Merge pull request #5 from nxbat/db-rewrite
Settings and small Database.ts cleanup.
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
||||
* text=auto eol=lf
|
||||
* text=auto eol=lf
|
||||
|
||||
@@ -22,6 +22,8 @@ export default {
|
||||
.setRequired(false)
|
||||
),
|
||||
handler: async function (client: Client, interaction: ChatInputCommandInteraction) {
|
||||
if (!interaction.guildId) return;
|
||||
|
||||
if (!interaction.channel || !interaction.channel.isSendable())
|
||||
return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Missing permissions to send to channel.' });
|
||||
|
||||
@@ -37,9 +39,7 @@ export default {
|
||||
.addComponents(button);
|
||||
|
||||
await interaction.channel.send({ components: [row], content });
|
||||
|
||||
await Database.setPrivateHelpChannel(interaction.guildId!, interaction.channelId);
|
||||
|
||||
await Database.updateGuildSettings(interaction.guildId, 'private_help_channel_id', interaction.channelId);
|
||||
interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Sent.' });
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
+57
-105
@@ -123,195 +123,147 @@ export default {
|
||||
.setDescription('Set the github release channel.')
|
||||
.setRequired(false)
|
||||
),
|
||||
|
||||
handler: async function (client: Client, interaction: ChatInputCommandInteraction) {
|
||||
if (!interaction.guildId) return; // This shouldn't occur, but TypeScript doesn't know that.
|
||||
await interaction.deferReply({ flags: [MessageFlags.Ephemeral] });
|
||||
|
||||
let response = '';
|
||||
|
||||
const response: string[] = [];
|
||||
const settings = await Database.getGuildSettings(interaction.guildId!);
|
||||
|
||||
if (!settings) {
|
||||
await Database.putGuild(interaction.guildId!);
|
||||
}
|
||||
if (!settings) await Database.putGuild(interaction.guildId);
|
||||
|
||||
const generalChannel = interaction.options.getChannel('general-channel');
|
||||
|
||||
if (generalChannel) {
|
||||
await Database.setGuildGeneralChatId(interaction.guildId!, generalChannel.id);
|
||||
|
||||
response += `General channel set to ${generalChannel}.\n`;
|
||||
await Database.updateGuildSettings(interaction.guildId, 'general_chat_id', generalChannel.id);
|
||||
response.push(`**general_chat_id** has been set to: ${generalChannel}.`);
|
||||
}
|
||||
|
||||
const ticketsChannel = interaction.options.getChannel('tickets-channel');
|
||||
|
||||
if (ticketsChannel) {
|
||||
await Database.setGuildTicketsLogsChannelId(interaction.guildId!, ticketsChannel.id);
|
||||
|
||||
response += `Tickets logs channel set to ${ticketsChannel}.\n`;
|
||||
await Database.updateGuildSettings(interaction.guildId, 'tickets_channel_id', ticketsChannel.id);
|
||||
response.push(`**tickets_channel_id** has been set to: ${ticketsChannel}.`);
|
||||
}
|
||||
|
||||
const appealsChannel = interaction.options.getChannel('appeals-channel');
|
||||
|
||||
if (appealsChannel) {
|
||||
await Database.setGuildAppealsLogsChannelId(interaction.guildId!, appealsChannel.id);
|
||||
await Database.updateGuildSettings(interaction.guildId, 'appeals_channel_id', appealsChannel.id);
|
||||
|
||||
response += `Appeals logs channel set to ${appealsChannel}.\n`;
|
||||
response.push(`**appeals_channel_id** has been set to ${appealsChannel}.`);
|
||||
}
|
||||
|
||||
const eventLogsChannel = interaction.options.getChannel('event-logs-channel');
|
||||
|
||||
if (eventLogsChannel) {
|
||||
await Database.setGuildEventsLogsChannelId(interaction.guildId!, eventLogsChannel.id);
|
||||
|
||||
response += `Event logs channel set to ${eventLogsChannel}.\n`;
|
||||
await Database.updateGuildSettings(interaction.guildId, 'event_logs_channel_id', eventLogsChannel.id);
|
||||
response.push(`**event_logs_channel_id** has been set to: ${eventLogsChannel}.`);
|
||||
}
|
||||
|
||||
const discordLogsChannel = interaction.options.getChannel('discord-logs-channel');
|
||||
|
||||
if (discordLogsChannel) {
|
||||
await Database.setGuildDiscordLogsChannelId(interaction.guildId!, discordLogsChannel.id);
|
||||
|
||||
response += `Discord logs channel set to ${discordLogsChannel}.\n`;
|
||||
await Database.updateGuildSettings(interaction.guildId, 'discord_logs_channel_id', discordLogsChannel.id);
|
||||
response.push(`**discord_logs_channel_id** has been set to: ${discordLogsChannel}.`);
|
||||
}
|
||||
|
||||
const auditLogsChannel = interaction.options.getChannel('audit-logs-channel');
|
||||
|
||||
if (auditLogsChannel) {
|
||||
await Database.setGuildAuditLogsChannelId(interaction.guildId!, auditLogsChannel.id);
|
||||
|
||||
response += `Audit logs channel set to ${auditLogsChannel}.\n`;
|
||||
await Database.updateGuildSettings(interaction.guildId, 'audit_logs_channel_id', auditLogsChannel.id);
|
||||
response.push(`**audit_logs_channel_id** has been set to: ${auditLogsChannel}.`);
|
||||
}
|
||||
|
||||
const voiceLogsChannel = interaction.options.getChannel('voice-logs-channel');
|
||||
|
||||
if (voiceLogsChannel) {
|
||||
await Database.setGuildVoiceLogsChannelId(interaction.guildId!, voiceLogsChannel.id);
|
||||
|
||||
response += `Voice logs channel set to ${voiceLogsChannel}.\n`;
|
||||
await Database.updateGuildSettings(interaction.guildId, 'voice_logs_channel_id', voiceLogsChannel.id);
|
||||
response.push(`**voice_logs_channel_id** has been set to: ${voiceLogsChannel}.`);
|
||||
}
|
||||
|
||||
const newMemberLogsChannel = interaction.options.getChannel('new-member-channel');
|
||||
|
||||
if (newMemberLogsChannel) {
|
||||
await Database.setGuildNewMemberLogsChannel(interaction.guildId!, newMemberLogsChannel.id);
|
||||
|
||||
response += `New member logs channel set to ${newMemberLogsChannel}.\n`;
|
||||
await Database.updateGuildSettings(interaction.guildId, 'new_member_channel_id', newMemberLogsChannel.id);
|
||||
response.push(`**new_member_channel_id** has been set to: ${newMemberLogsChannel}.`);
|
||||
}
|
||||
|
||||
const moderatorChannel = interaction.options.getChannel('moderator-channel');
|
||||
|
||||
if (moderatorChannel) {
|
||||
await Database.setGuildModeratorChannel(interaction.guildId!, moderatorChannel.id);
|
||||
|
||||
response += `Moderator channel set to ${moderatorChannel}.\n`;
|
||||
await Database.updateGuildSettings(interaction.guildId, 'moderator_channel_id', moderatorChannel.id);
|
||||
response.push(`**moderator_channel_id** has been set to": ${moderatorChannel}.`);
|
||||
}
|
||||
|
||||
const adminRole = interaction.options.getRole('admin-role');
|
||||
|
||||
if (adminRole) {
|
||||
await Database.setGuildAdminRole(interaction.guildId!, adminRole.id);
|
||||
|
||||
response += `Admin role set to ${adminRole}.\n`;
|
||||
await Database.updateGuildSettings(interaction.guildId, 'admin_role_id', adminRole.id);
|
||||
response.push(`**admin_role_id** has been set to: ${adminRole}.`);
|
||||
}
|
||||
|
||||
const privateHelperRole = interaction.options.getRole('private-helper-role');
|
||||
|
||||
if (privateHelperRole) {
|
||||
await Database.setGuildPrivateHelperRole(interaction.guildId!, privateHelperRole.id);
|
||||
|
||||
response += `Private helper role set to ${privateHelperRole}.\n`;
|
||||
await Database.updateGuildSettings(interaction.guildId, 'private_help_role_id', privateHelperRole.id);
|
||||
response.push(`**private_help_role_id** has been set to: ${privateHelperRole}.`);
|
||||
}
|
||||
|
||||
const devWatchRole = interaction.options.getRole('devwatch-role');
|
||||
|
||||
if (devWatchRole) {
|
||||
await Database.setGuildDevWatchRole(interaction.guildId!, devWatchRole.id);
|
||||
|
||||
response += `DevWatch role set to ${devWatchRole}.\n`;
|
||||
await Database.updateGuildSettings(interaction.guildId, 'devwatch_role_id', devWatchRole.id);
|
||||
response.push(`**private_help_role_id** has been set to ${devWatchRole}.`);
|
||||
}
|
||||
|
||||
const addCategory = interaction.options.getChannel('add-staff-category');
|
||||
if (addCategory) {
|
||||
if (addCategory.type == ChannelType.GuildCategory) {
|
||||
await Database.putGuildArraySetting('staff_categories', interaction.guildId!, addCategory.id);
|
||||
|
||||
response += `Added ${addCategory.toString()} as a staff category.\n`;
|
||||
} else {
|
||||
response += `Error adding staff category: ${addCategory.toString()} isn't a category.`;
|
||||
}
|
||||
await Database.putGuildArraySetting('staff_categories', interaction.guildId, addCategory.id);
|
||||
response.push(`Added ${addCategory.toString()} as a staff category.`);
|
||||
} else response.push(`Error adding staff category: ${addCategory.toString()} isn't a category.`);
|
||||
}
|
||||
|
||||
const removeCategory = interaction.options.getChannel('remove-staff-category');
|
||||
if (removeCategory) {
|
||||
if (removeCategory.type == ChannelType.GuildCategory) {
|
||||
if (await Database.removeGuildArraySetting('staff_categories', interaction.guildId!, removeCategory.id)) {
|
||||
response += `Removed ${removeCategory.toString()} as a staff category\n`;
|
||||
} else {
|
||||
response += `Error removing staff category: ${removeCategory.toString()} isn't a staff category.`;
|
||||
}
|
||||
} else {
|
||||
response += `Error removing staff category: ${removeCategory.toString()} isn't a category.`;
|
||||
}
|
||||
if (removeCategory.type == ChannelType.GuildCategory)
|
||||
if (await Database.removeGuildArraySetting('staff_categories', interaction.guildId, removeCategory.id))
|
||||
response.push(`Removed ${removeCategory.toString()} as a staff category`);
|
||||
else response.push(`Error removing staff category: ${removeCategory.toString()} isn't a staff category.`);
|
||||
else response.push(`Error removing staff category: ${removeCategory.toString()} isn't a category.`);
|
||||
}
|
||||
|
||||
const addSafeChannel = interaction.options.getChannel('add-safe-channel');
|
||||
if (addSafeChannel) {
|
||||
if (addSafeChannel.type == ChannelType.GuildText) {
|
||||
await Database.putGuildArraySetting('safe_channels', interaction.guildId!, addSafeChannel.id);
|
||||
|
||||
response += `Added ${addSafeChannel.toString()} as a SFW cannel.\n`;
|
||||
} else {
|
||||
response += `Error adding SFW channel: ${addSafeChannel.toString()} isn't a text channel.`;
|
||||
}
|
||||
await Database.putGuildArraySetting('safe_channels', interaction.guildId, addSafeChannel.id);
|
||||
response.push(`Added ${addSafeChannel.toString()} as a SFW cannel.`);
|
||||
} else response.push(`Error adding SFW channel: ${addSafeChannel.toString()} isn't a text channel.`);
|
||||
}
|
||||
|
||||
const removeSafeChannel = interaction.options.getChannel('remove-safe-channel');
|
||||
if (removeSafeChannel) {
|
||||
if (removeSafeChannel.type == ChannelType.GuildText) {
|
||||
if (await Database.removeGuildArraySetting('safe_channels', interaction.guildId!, removeSafeChannel.id)) {
|
||||
response += `Removed ${removeSafeChannel.toString()} as a safe channel\n`;
|
||||
} else {
|
||||
response += `Error removing safe channel: ${removeSafeChannel.toString()} isn't a safe channel.`;
|
||||
}
|
||||
} else {
|
||||
response += `Error removing safe channel: ${removeSafeChannel.toString()} isn't a text channel.`;
|
||||
}
|
||||
if (removeSafeChannel.type == ChannelType.GuildText)
|
||||
if (await Database.removeGuildArraySetting('safe_channels', interaction.guildId, removeSafeChannel.id))
|
||||
response.push(`Removed ${removeSafeChannel.toString()} as a safe channel`);
|
||||
else response.push(`Error removing safe channel: ${removeSafeChannel.toString()} isn't a safe channel.`);
|
||||
else response.push(`Error removing safe channel: ${removeSafeChannel.toString()} isn't a text channel.`);
|
||||
}
|
||||
|
||||
const addLinkSkipChannel = interaction.options.getChannel('add-link-skip-channel');
|
||||
if (addLinkSkipChannel) {
|
||||
if (addLinkSkipChannel.type == ChannelType.GuildText) {
|
||||
await Database.putGuildArraySetting('link_skip_channels', interaction.guildId!, addLinkSkipChannel.id);
|
||||
|
||||
response += `Added ${addLinkSkipChannel.toString()} as a link skip channel.\n`;
|
||||
} else {
|
||||
response += `Error adding link skip channel: ${addLinkSkipChannel.toString()} isn't a text channel.`;
|
||||
}
|
||||
await Database.putGuildArraySetting('link_skip_channels', interaction.guildId, addLinkSkipChannel.id);
|
||||
response.push(`Added ${addLinkSkipChannel.toString()} as a link skip channel.`);
|
||||
} else response.push(`Error adding link skip channel: ${addLinkSkipChannel.toString()} isn't a text channel.`);
|
||||
}
|
||||
|
||||
const removeLinkSkipChannel = interaction.options.getChannel('remove-link-skip-channel');
|
||||
if (removeLinkSkipChannel) {
|
||||
if (removeLinkSkipChannel.type == ChannelType.GuildText) {
|
||||
if (await Database.removeGuildArraySetting('link_skip_channels', interaction.guildId!, removeLinkSkipChannel.id)) {
|
||||
response += `Removed ${removeLinkSkipChannel.toString()} as a staff category\n`;
|
||||
} else {
|
||||
response += `Error removing link skip channel: ${removeLinkSkipChannel.toString()} isn't a link skip channel.`;
|
||||
}
|
||||
} else {
|
||||
response += `Error removing link skip channel: ${removeLinkSkipChannel.toString()} isn't a text channel.`;
|
||||
}
|
||||
if (removeLinkSkipChannel.type == ChannelType.GuildText)
|
||||
if (await Database.removeGuildArraySetting('link_skip_channels', interaction.guildId, removeLinkSkipChannel.id))
|
||||
response.push(`Removed ${removeLinkSkipChannel.toString()} as a staff category`);
|
||||
else response.push(`Error removing link skip channel: ${removeLinkSkipChannel.toString()} isn't a link skip channel.`);
|
||||
else response.push(`Error removing link skip channel: ${removeLinkSkipChannel.toString()} isn't a text channel.`);
|
||||
}
|
||||
|
||||
const githubReleaseChannel = interaction.options.getChannel('github-release-channel');
|
||||
|
||||
if (githubReleaseChannel) {
|
||||
await Database.setGuildGithubReleaseChannel(interaction.guildId!, githubReleaseChannel.id);
|
||||
|
||||
response += `Github releases channel set to ${githubReleaseChannel}.\n`;
|
||||
await Database.updateGuildSettings(interaction.guildId, 'github_release_channel', githubReleaseChannel.id);
|
||||
response.push(`**github_release_channel** has been set to ${githubReleaseChannel}.`);
|
||||
}
|
||||
|
||||
if (response.length == 0) return interaction.editReply({ content: 'No settings provided.' });
|
||||
|
||||
interaction.editReply({ content: response });
|
||||
if (response.length == 0) return interaction.editReply({ content: 'No settings have been modified.' });
|
||||
interaction.editReply({ content: response.join('\n') });
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
+114
-166
@@ -2,112 +2,112 @@ import path from 'path';
|
||||
import { open, Database as SqliteDatabase } from 'sqlite';
|
||||
import sqlite3 from 'sqlite3';
|
||||
import { Message } from '../events';
|
||||
import { AppealMessage, Ban, GithubUserMapping, GuildArraySetting, GuildSettings, KnowledgebaseItem, LoggedMessage, Note, PrivateHelpTicket, TicketMessage, TicketPhrase } from '../types';
|
||||
import { AppealMessage, Ban, GithubUserMapping, GuildArraySetting, GuildSetting, GuildSettings, KnowledgebaseItem, LoggedMessage, Note, PrivateHelpTicket, TicketMessage, TicketPhrase } from '../types';
|
||||
import { serializeMessage, wait } from '../utils';
|
||||
|
||||
const DB_SCHEMA = `
|
||||
CREATE TABLE IF NOT EXISTS discord_names (
|
||||
id INTEGER PRIMARY KEY,
|
||||
user_id INTEGER NOT NULL,
|
||||
discord_id TEXT NOT NULL,
|
||||
discord_username TEXT NOT NULL,
|
||||
added_on datetime NOT NULL DEFAULT (datetime('now', 'localtime'))
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS discord_names (
|
||||
id INTEGER PRIMARY KEY,
|
||||
user_id INTEGER NOT NULL,
|
||||
discord_id TEXT NOT NULL,
|
||||
discord_username TEXT NOT NULL,
|
||||
added_on datetime NOT NULL DEFAULT (datetime('now', 'localtime'))
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS settings (
|
||||
guild_id TEXT PRIMARY KEY,
|
||||
general_chat_id TEXT,
|
||||
new_member_channel_id TEXT,
|
||||
tickets_channel_id TEXT,
|
||||
event_logs_channel_id TEXT,
|
||||
discord_logs_channel_id TEXT,
|
||||
audit_logs_channel_id TEXT,
|
||||
voice_logs_channel_id TEXT,
|
||||
admin_role_id TEXT,
|
||||
private_help_role_id TEXT,
|
||||
devwatch_role_id TEXT,
|
||||
staff_categories TEXT,
|
||||
safe_channels TEXT,
|
||||
link_skip_channels TEXT,
|
||||
github_release_channel TEXT,
|
||||
moderator_channel_id TEXT,
|
||||
private_help_channel_id TEXT
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS settings (
|
||||
guild_id TEXT PRIMARY KEY,
|
||||
general_chat_id TEXT,
|
||||
new_member_channel_id TEXT,
|
||||
tickets_channel_id TEXT,
|
||||
event_logs_channel_id TEXT,
|
||||
discord_logs_channel_id TEXT,
|
||||
audit_logs_channel_id TEXT,
|
||||
voice_logs_channel_id TEXT,
|
||||
admin_role_id TEXT,
|
||||
private_help_role_id TEXT,
|
||||
devwatch_role_id TEXT,
|
||||
staff_categories TEXT,
|
||||
safe_channels TEXT,
|
||||
link_skip_channels TEXT,
|
||||
github_release_channel TEXT,
|
||||
moderator_channel_id TEXT,
|
||||
private_help_channel_id TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS messages (
|
||||
id TEXT PRIMARY KEY ON CONFLICT REPLACE,
|
||||
author_id TEXT NOT NULL,
|
||||
author_name TEXT NOT NULL,
|
||||
channel_id TEXT NOT NULL,
|
||||
attachments TEXT NOT NULL,
|
||||
stickers TEXT NOT NULL,
|
||||
content TEXT NOT NULL
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS messages (
|
||||
id TEXT PRIMARY KEY ON CONFLICT REPLACE,
|
||||
author_id TEXT NOT NULL,
|
||||
author_name TEXT NOT NULL,
|
||||
channel_id TEXT NOT NULL,
|
||||
attachments TEXT NOT NULL,
|
||||
stickers TEXT NOT NULL,
|
||||
content TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS index_authors ON messages (author_id);
|
||||
CREATE INDEX IF NOT EXISTS index_authors ON messages (author_id);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS index_channels ON messages (channel_id);
|
||||
CREATE INDEX IF NOT EXISTS index_channels ON messages (channel_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS tickets (
|
||||
id INTEGER PRIMARY KEY,
|
||||
message_id TEXT NOT NULL
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS tickets (
|
||||
id INTEGER PRIMARY KEY,
|
||||
message_id TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ticket_phrases (
|
||||
id INTEGER PRIMARY KEY,
|
||||
user_id TEXT NOT NULL,
|
||||
phrase TEXT NOT NULL
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS ticket_phrases (
|
||||
id INTEGER PRIMARY KEY,
|
||||
user_id TEXT NOT NULL,
|
||||
phrase TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS notes (
|
||||
id INTEGER PRIMARY KEY,
|
||||
user_id TEXT,
|
||||
reason TEXT,
|
||||
mod_id TEXT,
|
||||
timestamp datetime NOT NULL DEFAULT (datetime('now', 'localtime'))
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS notes (
|
||||
id INTEGER PRIMARY KEY,
|
||||
user_id TEXT,
|
||||
reason TEXT,
|
||||
mod_id TEXT,
|
||||
timestamp datetime NOT NULL DEFAULT (datetime('now', 'localtime'))
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS index_user_ids ON notes (user_id);
|
||||
CREATE INDEX IF NOT EXISTS index_user_ids ON notes (user_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS note_edits (
|
||||
id INTEGER PRIMARY KEY,
|
||||
note_id INTEGER,
|
||||
mod_id TEXT,
|
||||
previous_reason TEXT,
|
||||
timestamp datetime NOT NULL DEFAULT (datetime('now', 'localtime')),
|
||||
FOREIGN KEY(note_id) REFERENCES notes(id)
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS note_edits (
|
||||
id INTEGER PRIMARY KEY,
|
||||
note_id INTEGER,
|
||||
mod_id TEXT,
|
||||
previous_reason TEXT,
|
||||
timestamp datetime NOT NULL DEFAULT (datetime('now', 'localtime')),
|
||||
FOREIGN KEY(note_id) REFERENCES notes(id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS bans (
|
||||
id INTEGER PRIMARY KEY,
|
||||
user_id TEXT,
|
||||
expires INTEGER,
|
||||
expires_at datetime,
|
||||
full_ban INTEGER
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS bans (
|
||||
id INTEGER PRIMARY KEY,
|
||||
user_id TEXT,
|
||||
expires INTEGER,
|
||||
expires_at datetime,
|
||||
full_ban INTEGER
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS github_user_mapping (
|
||||
id INTEGER PRIMARY KEY,
|
||||
discord_id TEXT,
|
||||
github_username TEXT
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS github_user_mapping (
|
||||
id INTEGER PRIMARY KEY,
|
||||
discord_id TEXT,
|
||||
github_username TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS knowledgebase (
|
||||
id INTEGER PRIMARY KEY,
|
||||
guild_id TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
content TEXT NOT NULL
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS knowledgebase (
|
||||
id INTEGER PRIMARY KEY,
|
||||
guild_id TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
content TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS private_help_tickets (
|
||||
id INTEGER PRIMARY KEY,
|
||||
thread_id TEXT NOT NULL,
|
||||
user_id TEXT NOT NULL,
|
||||
status INTEGER NOT NULL,
|
||||
timestamp datetime NOT NULL DEFAULT (datetime('now', 'localtime'))
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS private_help_tickets (
|
||||
id INTEGER PRIMARY KEY,
|
||||
thread_id TEXT NOT NULL,
|
||||
user_id TEXT NOT NULL,
|
||||
status INTEGER NOT NULL,
|
||||
timestamp datetime NOT NULL DEFAULT (datetime('now', 'localtime'))
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS index_timestamp ON private_help_tickets (timestamp);
|
||||
CREATE INDEX IF NOT EXISTS index_timestamp ON private_help_tickets (timestamp);
|
||||
`;
|
||||
|
||||
export const enum PrivateHelpTicketStatus {
|
||||
@@ -148,7 +148,7 @@ export class Database {
|
||||
console.log('Database migrations ran');
|
||||
}
|
||||
|
||||
// -- START WHOIS --
|
||||
//#region WHOIS
|
||||
|
||||
static async getE621Ids(discordId: string): Promise<number[]> {
|
||||
const ids = await Database.db.all<{ user_id: number }[]>('SELECT DISTINCT user_id FROM discord_names WHERE discord_id = ?', discordId);
|
||||
@@ -185,72 +185,20 @@ export class Database {
|
||||
await Database.db.run('DELETE from discord_names WHERE user_id = ? AND discord_id = ?', id, discordId);
|
||||
}
|
||||
|
||||
// -- END WHOIS --
|
||||
//#endregion
|
||||
|
||||
// -- START SETTINGS --
|
||||
//#region Guild Settings
|
||||
|
||||
static async getGuildSettings(guildId: string): Promise<GuildSettings | undefined> {
|
||||
return await Database.db.get<GuildSettings>('SELECT * FROM settings WHERE guild_id = ?', guildId);
|
||||
static async getGuildSettings(guildId: string): Promise<GuildSettings> {
|
||||
return await Database.db.get<GuildSettings>('SELECT * FROM settings WHERE guild_id = ?', guildId) as GuildSettings;
|
||||
}
|
||||
|
||||
static async putGuild(guildId: string) {
|
||||
await Database.db.run('INSERT INTO settings(guild_id) VALUES (?)', guildId);
|
||||
}
|
||||
|
||||
static async setGuildGeneralChatId(guildId: string, id: string) {
|
||||
await Database.db.run('UPDATE settings SET general_chat_id = ? WHERE guild_id = ?', id, guildId);
|
||||
}
|
||||
|
||||
static async setGuildTicketsLogsChannelId(guildId: string, id: string) {
|
||||
await Database.db.run('UPDATE settings SET tickets_channel_id = ? WHERE guild_id = ?', id, guildId);
|
||||
}
|
||||
|
||||
static async setGuildAppealsLogsChannelId(guildId: string, id: string) {
|
||||
await Database.db.run('UPDATE settings SET appeals_channel_id = ? WHERE guild_id = ?', id, guildId);
|
||||
}
|
||||
|
||||
static async setGuildEventsLogsChannelId(guildId: string, id: string) {
|
||||
await Database.db.run('UPDATE settings SET event_logs_channel_id = ? WHERE guild_id = ?', id, guildId);
|
||||
}
|
||||
|
||||
static async setGuildDiscordLogsChannelId(guildId: string, id: string) {
|
||||
await Database.db.run('UPDATE settings SET discord_logs_channel_id = ? WHERE guild_id = ?', id, guildId);
|
||||
}
|
||||
|
||||
static async setGuildAuditLogsChannelId(guildId: string, id: string) {
|
||||
await Database.db.run('UPDATE settings SET audit_logs_channel_id = ? WHERE guild_id = ?', id, guildId);
|
||||
}
|
||||
|
||||
static async setGuildVoiceLogsChannelId(guildId: string, id: string) {
|
||||
await Database.db.run('UPDATE settings SET voice_logs_channel_id = ? WHERE guild_id = ?', id, guildId);
|
||||
}
|
||||
|
||||
static async setGuildNewMemberLogsChannel(guildId: string, id: string) {
|
||||
await Database.db.run('UPDATE settings SET new_member_channel_id = ? WHERE guild_id = ?', id, guildId);
|
||||
}
|
||||
|
||||
static async setGuildModeratorChannel(guildId: string, id: string) {
|
||||
await Database.db.run('UPDATE settings SET moderator_channel_id = ? WHERE guild_id = ?', id, guildId);
|
||||
}
|
||||
|
||||
static async setGuildAdminRole(guildId: string, id: string) {
|
||||
await Database.db.run('UPDATE settings SET admin_role_id = ? WHERE guild_id = ?', id, guildId);
|
||||
}
|
||||
|
||||
static async setGuildPrivateHelperRole(guildId: string, id: string) {
|
||||
await Database.db.run('UPDATE settings SET private_help_role_id = ? WHERE guild_id = ?', id, guildId);
|
||||
}
|
||||
|
||||
static async setGuildDevWatchRole(guildId: string, id: string) {
|
||||
await Database.db.run('UPDATE settings SET devwatch_role_id = ? WHERE guild_id = ?', id, guildId);
|
||||
}
|
||||
|
||||
static async setGuildGithubReleaseChannel(guildId: string, id: string) {
|
||||
await Database.db.run('UPDATE settings SET github_release_channel = ? WHERE guild_id = ?', id, guildId);
|
||||
}
|
||||
|
||||
static async setPrivateHelpChannel(guildId: string, id: string) {
|
||||
await Database.db.run('UPDATE settings SET private_help_channel_id = ? WHERE guild_id = ?', id, guildId);
|
||||
static async updateGuildSettings(guildId: string, key: GuildSetting, value: string) {
|
||||
await Database.db.run(`UPDATE settings SET ${key} = ? WHERE guild_id = ?`, value, guildId);
|
||||
}
|
||||
|
||||
// Since "setting" has guaranteed values and is never set by the user, this shouldn't cause any security issues.
|
||||
@@ -288,9 +236,9 @@ export class Database {
|
||||
return true;
|
||||
}
|
||||
|
||||
// -- END SETTINGS --
|
||||
//#endregion
|
||||
|
||||
// START MESSAGE LOGS --
|
||||
//#region Message Logs
|
||||
|
||||
static async putMessage(message: Message): Promise<boolean> {
|
||||
try {
|
||||
@@ -324,9 +272,9 @@ export class Database {
|
||||
}
|
||||
}
|
||||
|
||||
// -- END MESSAGE LOGS --
|
||||
//#endregion
|
||||
|
||||
// -- START TICKETS --
|
||||
//#region Tickets
|
||||
|
||||
static async putTicket(ticketId: number, messageId: string) {
|
||||
await Database.db.run('INSERT INTO tickets(id, message_id) VALUES (?, ?)', ticketId, messageId);
|
||||
@@ -369,9 +317,9 @@ export class Database {
|
||||
});
|
||||
}
|
||||
|
||||
// -- END TICKETS --
|
||||
//#endregion
|
||||
|
||||
// -- START APPEALS --
|
||||
//#region Appeals
|
||||
|
||||
static async putAppeal(appealId: number, messageId: string) {
|
||||
await Database.db.run('INSERT INTO appeals(id, message_id) VALUES (?, ?)', appealId, messageId);
|
||||
@@ -386,9 +334,9 @@ export class Database {
|
||||
return appeal?.message_id;
|
||||
}
|
||||
|
||||
// -- END APPEALS --
|
||||
//#endregion
|
||||
|
||||
// -- START NOTES --
|
||||
//#region Notes
|
||||
|
||||
static async putNote(userId: string, reason: string, modId: string) {
|
||||
await Database.db.run('INSERT INTO notes(user_id, reason, mod_id) VALUES (?, ?, ?)', userId, reason, modId);
|
||||
@@ -409,9 +357,9 @@ export class Database {
|
||||
return await Database.db.all<Note[]>('SELECT * from notes WHERE user_id = ?', userId);
|
||||
}
|
||||
|
||||
// -- END NOTES --
|
||||
//#endregion
|
||||
|
||||
// -- START BANS --
|
||||
//#region Bans
|
||||
|
||||
static async putBan(userId: string, expiresAt: Date | null, fullBan = false) {
|
||||
await Database.db.run('INSERT INTO bans(user_id, expires, expires_at, full_ban) VALUES (?, ?, ?, ?)', userId, expiresAt != null ? 1 : 0, expiresAt, fullBan);
|
||||
@@ -433,9 +381,9 @@ export class Database {
|
||||
await Database.db.run('DELETE from bans WHERE user_id = ?', userId);
|
||||
}
|
||||
|
||||
// -- END BANS --
|
||||
//#endregion
|
||||
|
||||
// -- START GITHUB USER MAPPING --
|
||||
//# GitHub User Mapping
|
||||
|
||||
// github_user_mapping
|
||||
static async putGithubUserMapping(discordId: string, githubUsername: string) {
|
||||
@@ -462,9 +410,9 @@ export class Database {
|
||||
await Database.db.run('DELETE from github_user_mapping WHERE discord_id = ?', discordId);
|
||||
}
|
||||
|
||||
// -- END GITHUB USER MAPPING --
|
||||
//#endregion
|
||||
|
||||
// -- START KNOWLEDGEBASE --
|
||||
//# Knowledgebase
|
||||
|
||||
static async addToKnowledgebase(guildId: string, name: string, content: string) {
|
||||
if (content.length > 2000) return;
|
||||
@@ -494,9 +442,9 @@ export class Database {
|
||||
return await Database.db.all<KnowledgebaseItem[]>('SELECT * from knowledgebase WHERE guild_id = ?', guildId);
|
||||
}
|
||||
|
||||
// -- END KNOWLEDGEBASE --
|
||||
//#endregion
|
||||
|
||||
// -- START PRIVATE HELP TICKETS --
|
||||
//#region Private Help Tickets
|
||||
|
||||
static async createPrivateHelpTicket(userId: string, threadId: string) {
|
||||
await Database.db.run('INSERT INTO private_help_tickets(user_id, thread_id, status) VALUES (?, ?, ?)', userId, threadId, PrivateHelpTicketStatus.OPEN);
|
||||
@@ -514,5 +462,5 @@ export class Database {
|
||||
return await Database.db.all<PrivateHelpTicket[]>('SELECT * from private_help_tickets WHERE status = ?', PrivateHelpTicketStatus.OPEN);
|
||||
}
|
||||
|
||||
// -- END PRIVATE HELP TICKETS
|
||||
}
|
||||
//#endregion
|
||||
}
|
||||
|
||||
Vendored
+2
-1
@@ -29,6 +29,7 @@ export type GuildSettings = {
|
||||
appeals_channel_id?: string
|
||||
}
|
||||
|
||||
type GuildSetting = Exclude<keyof GuildSettings, 'guild_id'>
|
||||
export type GuildArraySetting = 'staff_categories' | 'safe_channels' | 'link_skip_channels';
|
||||
|
||||
export type TicketMessage = {
|
||||
@@ -82,4 +83,4 @@ export type PrivateHelpTicket = {
|
||||
thread_id: string
|
||||
status: PrivateHelpTicketStatus
|
||||
timestamp: string
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { APIEmbed, Client } from 'discord.js';
|
||||
|
||||
type EmbedSeverity =
|
||||
| 'default'
|
||||
| 'info'
|
||||
| 'warning'
|
||||
| 'error'
|
||||
| 'success'
|
||||
|
||||
export function CreateDefaultEmbed(context: Client): APIEmbed {
|
||||
if (!context.user) return {};
|
||||
|
||||
return {
|
||||
footer: {
|
||||
icon_url: context.user.avatarURL()!,
|
||||
text: context.user.username
|
||||
},
|
||||
|
||||
timestamp: new Date().toISOString()
|
||||
}
|
||||
}
|
||||
|
||||
export function SetSeverity(severity: EmbedSeverity): APIEmbed {
|
||||
switch (severity) {
|
||||
case 'default': return { color: 0x014995 }
|
||||
case 'info': return { color: 0x5865F2 }
|
||||
case 'warning': return { color: 0xFEE75C }
|
||||
case 'error': return { color: 0xED4245 }
|
||||
case 'success': return { color: 0x57F287 }
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ export * from './channel-utils';
|
||||
export * from './commands';
|
||||
export * from './debug-utils';
|
||||
export * from './discord-user-utils';
|
||||
export * from './embed-utils';
|
||||
export * from './e621-utils';
|
||||
export * from './event-log-utils';
|
||||
export * from './file-utils';
|
||||
|
||||
Reference in New Issue
Block a user