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)
|
.setRequired(false)
|
||||||
),
|
),
|
||||||
handler: async function (client: Client, interaction: ChatInputCommandInteraction) {
|
handler: async function (client: Client, interaction: ChatInputCommandInteraction) {
|
||||||
|
if (!interaction.guildId) return;
|
||||||
|
|
||||||
if (!interaction.channel || !interaction.channel.isSendable())
|
if (!interaction.channel || !interaction.channel.isSendable())
|
||||||
return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Missing permissions to send to channel.' });
|
return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Missing permissions to send to channel.' });
|
||||||
|
|
||||||
@@ -37,9 +39,7 @@ export default {
|
|||||||
.addComponents(button);
|
.addComponents(button);
|
||||||
|
|
||||||
await interaction.channel.send({ components: [row], content });
|
await interaction.channel.send({ components: [row], content });
|
||||||
|
await Database.updateGuildSettings(interaction.guildId, 'private_help_channel_id', interaction.channelId);
|
||||||
await Database.setPrivateHelpChannel(interaction.guildId!, interaction.channelId);
|
|
||||||
|
|
||||||
interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Sent.' });
|
interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Sent.' });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+57
-105
@@ -123,195 +123,147 @@ export default {
|
|||||||
.setDescription('Set the github release channel.')
|
.setDescription('Set the github release channel.')
|
||||||
.setRequired(false)
|
.setRequired(false)
|
||||||
),
|
),
|
||||||
|
|
||||||
handler: async function (client: Client, interaction: ChatInputCommandInteraction) {
|
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] });
|
await interaction.deferReply({ flags: [MessageFlags.Ephemeral] });
|
||||||
|
|
||||||
let response = '';
|
const response: string[] = [];
|
||||||
|
|
||||||
const settings = await Database.getGuildSettings(interaction.guildId!);
|
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');
|
const generalChannel = interaction.options.getChannel('general-channel');
|
||||||
|
|
||||||
if (generalChannel) {
|
if (generalChannel) {
|
||||||
await Database.setGuildGeneralChatId(interaction.guildId!, generalChannel.id);
|
await Database.updateGuildSettings(interaction.guildId, 'general_chat_id', generalChannel.id);
|
||||||
|
response.push(`**general_chat_id** has been set to: ${generalChannel}.`);
|
||||||
response += `General channel set to ${generalChannel}.\n`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const ticketsChannel = interaction.options.getChannel('tickets-channel');
|
const ticketsChannel = interaction.options.getChannel('tickets-channel');
|
||||||
|
|
||||||
if (ticketsChannel) {
|
if (ticketsChannel) {
|
||||||
await Database.setGuildTicketsLogsChannelId(interaction.guildId!, ticketsChannel.id);
|
await Database.updateGuildSettings(interaction.guildId, 'tickets_channel_id', ticketsChannel.id);
|
||||||
|
response.push(`**tickets_channel_id** has been set to: ${ticketsChannel}.`);
|
||||||
response += `Tickets logs channel set to ${ticketsChannel}.\n`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const appealsChannel = interaction.options.getChannel('appeals-channel');
|
const appealsChannel = interaction.options.getChannel('appeals-channel');
|
||||||
|
|
||||||
if (appealsChannel) {
|
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');
|
const eventLogsChannel = interaction.options.getChannel('event-logs-channel');
|
||||||
|
|
||||||
if (eventLogsChannel) {
|
if (eventLogsChannel) {
|
||||||
await Database.setGuildEventsLogsChannelId(interaction.guildId!, eventLogsChannel.id);
|
await Database.updateGuildSettings(interaction.guildId, 'event_logs_channel_id', eventLogsChannel.id);
|
||||||
|
response.push(`**event_logs_channel_id** has been set to: ${eventLogsChannel}.`);
|
||||||
response += `Event logs channel set to ${eventLogsChannel}.\n`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const discordLogsChannel = interaction.options.getChannel('discord-logs-channel');
|
const discordLogsChannel = interaction.options.getChannel('discord-logs-channel');
|
||||||
|
|
||||||
if (discordLogsChannel) {
|
if (discordLogsChannel) {
|
||||||
await Database.setGuildDiscordLogsChannelId(interaction.guildId!, discordLogsChannel.id);
|
await Database.updateGuildSettings(interaction.guildId, 'discord_logs_channel_id', discordLogsChannel.id);
|
||||||
|
response.push(`**discord_logs_channel_id** has been set to: ${discordLogsChannel}.`);
|
||||||
response += `Discord logs channel set to ${discordLogsChannel}.\n`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const auditLogsChannel = interaction.options.getChannel('audit-logs-channel');
|
const auditLogsChannel = interaction.options.getChannel('audit-logs-channel');
|
||||||
|
|
||||||
if (auditLogsChannel) {
|
if (auditLogsChannel) {
|
||||||
await Database.setGuildAuditLogsChannelId(interaction.guildId!, auditLogsChannel.id);
|
await Database.updateGuildSettings(interaction.guildId, 'audit_logs_channel_id', auditLogsChannel.id);
|
||||||
|
response.push(`**audit_logs_channel_id** has been set to: ${auditLogsChannel}.`);
|
||||||
response += `Audit logs channel set to ${auditLogsChannel}.\n`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const voiceLogsChannel = interaction.options.getChannel('voice-logs-channel');
|
const voiceLogsChannel = interaction.options.getChannel('voice-logs-channel');
|
||||||
|
|
||||||
if (voiceLogsChannel) {
|
if (voiceLogsChannel) {
|
||||||
await Database.setGuildVoiceLogsChannelId(interaction.guildId!, voiceLogsChannel.id);
|
await Database.updateGuildSettings(interaction.guildId, 'voice_logs_channel_id', voiceLogsChannel.id);
|
||||||
|
response.push(`**voice_logs_channel_id** has been set to: ${voiceLogsChannel}.`);
|
||||||
response += `Voice logs channel set to ${voiceLogsChannel}.\n`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const newMemberLogsChannel = interaction.options.getChannel('new-member-channel');
|
const newMemberLogsChannel = interaction.options.getChannel('new-member-channel');
|
||||||
|
|
||||||
if (newMemberLogsChannel) {
|
if (newMemberLogsChannel) {
|
||||||
await Database.setGuildNewMemberLogsChannel(interaction.guildId!, newMemberLogsChannel.id);
|
await Database.updateGuildSettings(interaction.guildId, 'new_member_channel_id', newMemberLogsChannel.id);
|
||||||
|
response.push(`**new_member_channel_id** has been set to: ${newMemberLogsChannel}.`);
|
||||||
response += `New member logs channel set to ${newMemberLogsChannel}.\n`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const moderatorChannel = interaction.options.getChannel('moderator-channel');
|
const moderatorChannel = interaction.options.getChannel('moderator-channel');
|
||||||
|
|
||||||
if (moderatorChannel) {
|
if (moderatorChannel) {
|
||||||
await Database.setGuildModeratorChannel(interaction.guildId!, moderatorChannel.id);
|
await Database.updateGuildSettings(interaction.guildId, 'moderator_channel_id', moderatorChannel.id);
|
||||||
|
response.push(`**moderator_channel_id** has been set to": ${moderatorChannel}.`);
|
||||||
response += `Moderator channel set to ${moderatorChannel}.\n`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const adminRole = interaction.options.getRole('admin-role');
|
const adminRole = interaction.options.getRole('admin-role');
|
||||||
|
|
||||||
if (adminRole) {
|
if (adminRole) {
|
||||||
await Database.setGuildAdminRole(interaction.guildId!, adminRole.id);
|
await Database.updateGuildSettings(interaction.guildId, 'admin_role_id', adminRole.id);
|
||||||
|
response.push(`**admin_role_id** has been set to: ${adminRole}.`);
|
||||||
response += `Admin role set to ${adminRole}.\n`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const privateHelperRole = interaction.options.getRole('private-helper-role');
|
const privateHelperRole = interaction.options.getRole('private-helper-role');
|
||||||
|
|
||||||
if (privateHelperRole) {
|
if (privateHelperRole) {
|
||||||
await Database.setGuildPrivateHelperRole(interaction.guildId!, privateHelperRole.id);
|
await Database.updateGuildSettings(interaction.guildId, 'private_help_role_id', privateHelperRole.id);
|
||||||
|
response.push(`**private_help_role_id** has been set to: ${privateHelperRole}.`);
|
||||||
response += `Private helper role set to ${privateHelperRole}.\n`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const devWatchRole = interaction.options.getRole('devwatch-role');
|
const devWatchRole = interaction.options.getRole('devwatch-role');
|
||||||
|
|
||||||
if (devWatchRole) {
|
if (devWatchRole) {
|
||||||
await Database.setGuildDevWatchRole(interaction.guildId!, devWatchRole.id);
|
await Database.updateGuildSettings(interaction.guildId, 'devwatch_role_id', devWatchRole.id);
|
||||||
|
response.push(`**private_help_role_id** has been set to ${devWatchRole}.`);
|
||||||
response += `DevWatch role set to ${devWatchRole}.\n`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const addCategory = interaction.options.getChannel('add-staff-category');
|
const addCategory = interaction.options.getChannel('add-staff-category');
|
||||||
if (addCategory) {
|
if (addCategory) {
|
||||||
if (addCategory.type == ChannelType.GuildCategory) {
|
if (addCategory.type == ChannelType.GuildCategory) {
|
||||||
await Database.putGuildArraySetting('staff_categories', interaction.guildId!, addCategory.id);
|
await Database.putGuildArraySetting('staff_categories', interaction.guildId, addCategory.id);
|
||||||
|
response.push(`Added ${addCategory.toString()} as a staff category.`);
|
||||||
response += `Added ${addCategory.toString()} as a staff category.\n`;
|
} else response.push(`Error adding staff category: ${addCategory.toString()} isn't a category.`);
|
||||||
} else {
|
|
||||||
response += `Error adding staff category: ${addCategory.toString()} isn't a category.`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const removeCategory = interaction.options.getChannel('remove-staff-category');
|
const removeCategory = interaction.options.getChannel('remove-staff-category');
|
||||||
if (removeCategory) {
|
if (removeCategory) {
|
||||||
if (removeCategory.type == ChannelType.GuildCategory) {
|
if (removeCategory.type == ChannelType.GuildCategory)
|
||||||
if (await Database.removeGuildArraySetting('staff_categories', interaction.guildId!, removeCategory.id)) {
|
if (await Database.removeGuildArraySetting('staff_categories', interaction.guildId, removeCategory.id))
|
||||||
response += `Removed ${removeCategory.toString()} as a staff category\n`;
|
response.push(`Removed ${removeCategory.toString()} as a staff category`);
|
||||||
} else {
|
else response.push(`Error removing staff category: ${removeCategory.toString()} isn't a staff category.`);
|
||||||
response += `Error removing staff category: ${removeCategory.toString()} isn't a staff category.`;
|
else response.push(`Error removing staff category: ${removeCategory.toString()} isn't a category.`);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
response += `Error removing staff category: ${removeCategory.toString()} isn't a category.`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const addSafeChannel = interaction.options.getChannel('add-safe-channel');
|
const addSafeChannel = interaction.options.getChannel('add-safe-channel');
|
||||||
if (addSafeChannel) {
|
if (addSafeChannel) {
|
||||||
if (addSafeChannel.type == ChannelType.GuildText) {
|
if (addSafeChannel.type == ChannelType.GuildText) {
|
||||||
await Database.putGuildArraySetting('safe_channels', interaction.guildId!, addSafeChannel.id);
|
await Database.putGuildArraySetting('safe_channels', interaction.guildId, addSafeChannel.id);
|
||||||
|
response.push(`Added ${addSafeChannel.toString()} as a SFW cannel.`);
|
||||||
response += `Added ${addSafeChannel.toString()} as a SFW cannel.\n`;
|
} else response.push(`Error adding SFW channel: ${addSafeChannel.toString()} isn't a text channel.`);
|
||||||
} else {
|
|
||||||
response += `Error adding SFW channel: ${addSafeChannel.toString()} isn't a text channel.`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const removeSafeChannel = interaction.options.getChannel('remove-safe-channel');
|
const removeSafeChannel = interaction.options.getChannel('remove-safe-channel');
|
||||||
if (removeSafeChannel) {
|
if (removeSafeChannel) {
|
||||||
if (removeSafeChannel.type == ChannelType.GuildText) {
|
if (removeSafeChannel.type == ChannelType.GuildText)
|
||||||
if (await Database.removeGuildArraySetting('safe_channels', interaction.guildId!, removeSafeChannel.id)) {
|
if (await Database.removeGuildArraySetting('safe_channels', interaction.guildId, removeSafeChannel.id))
|
||||||
response += `Removed ${removeSafeChannel.toString()} as a safe channel\n`;
|
response.push(`Removed ${removeSafeChannel.toString()} as a safe channel`);
|
||||||
} else {
|
else response.push(`Error removing safe channel: ${removeSafeChannel.toString()} isn't a safe channel.`);
|
||||||
response += `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.`);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
response += `Error removing safe channel: ${removeSafeChannel.toString()} isn't a text channel.`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const addLinkSkipChannel = interaction.options.getChannel('add-link-skip-channel');
|
const addLinkSkipChannel = interaction.options.getChannel('add-link-skip-channel');
|
||||||
if (addLinkSkipChannel) {
|
if (addLinkSkipChannel) {
|
||||||
if (addLinkSkipChannel.type == ChannelType.GuildText) {
|
if (addLinkSkipChannel.type == ChannelType.GuildText) {
|
||||||
await Database.putGuildArraySetting('link_skip_channels', interaction.guildId!, addLinkSkipChannel.id);
|
await Database.putGuildArraySetting('link_skip_channels', interaction.guildId, addLinkSkipChannel.id);
|
||||||
|
response.push(`Added ${addLinkSkipChannel.toString()} as a link skip channel.`);
|
||||||
response += `Added ${addLinkSkipChannel.toString()} as a link skip channel.\n`;
|
} else response.push(`Error adding link skip channel: ${addLinkSkipChannel.toString()} isn't a text channel.`);
|
||||||
} else {
|
|
||||||
response += `Error adding link skip channel: ${addLinkSkipChannel.toString()} isn't a text channel.`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const removeLinkSkipChannel = interaction.options.getChannel('remove-link-skip-channel');
|
const removeLinkSkipChannel = interaction.options.getChannel('remove-link-skip-channel');
|
||||||
if (removeLinkSkipChannel) {
|
if (removeLinkSkipChannel) {
|
||||||
if (removeLinkSkipChannel.type == ChannelType.GuildText) {
|
if (removeLinkSkipChannel.type == ChannelType.GuildText)
|
||||||
if (await Database.removeGuildArraySetting('link_skip_channels', interaction.guildId!, removeLinkSkipChannel.id)) {
|
if (await Database.removeGuildArraySetting('link_skip_channels', interaction.guildId, removeLinkSkipChannel.id))
|
||||||
response += `Removed ${removeLinkSkipChannel.toString()} as a staff category\n`;
|
response.push(`Removed ${removeLinkSkipChannel.toString()} as a staff category`);
|
||||||
} else {
|
else response.push(`Error removing link skip channel: ${removeLinkSkipChannel.toString()} isn't a link skip channel.`);
|
||||||
response += `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.`);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
response += `Error removing link skip channel: ${removeLinkSkipChannel.toString()} isn't a text channel.`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const githubReleaseChannel = interaction.options.getChannel('github-release-channel');
|
const githubReleaseChannel = interaction.options.getChannel('github-release-channel');
|
||||||
|
|
||||||
if (githubReleaseChannel) {
|
if (githubReleaseChannel) {
|
||||||
await Database.setGuildGithubReleaseChannel(interaction.guildId!, githubReleaseChannel.id);
|
await Database.updateGuildSettings(interaction.guildId, 'github_release_channel', githubReleaseChannel.id);
|
||||||
|
response.push(`**github_release_channel** has been set to ${githubReleaseChannel}.`);
|
||||||
response += `Github releases channel set to ${githubReleaseChannel}.\n`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.length == 0) return interaction.editReply({ content: 'No settings provided.' });
|
if (response.length == 0) return interaction.editReply({ content: 'No settings have been modified.' });
|
||||||
|
interaction.editReply({ content: response.join('\n') });
|
||||||
interaction.editReply({ content: response });
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+114
-166
@@ -2,112 +2,112 @@ import path from 'path';
|
|||||||
import { open, Database as SqliteDatabase } from 'sqlite';
|
import { open, Database as SqliteDatabase } from 'sqlite';
|
||||||
import sqlite3 from 'sqlite3';
|
import sqlite3 from 'sqlite3';
|
||||||
import { Message } from '../events';
|
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';
|
import { serializeMessage, wait } from '../utils';
|
||||||
|
|
||||||
const DB_SCHEMA = `
|
const DB_SCHEMA = `
|
||||||
CREATE TABLE IF NOT EXISTS discord_names (
|
CREATE TABLE IF NOT EXISTS discord_names (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
user_id INTEGER NOT NULL,
|
user_id INTEGER NOT NULL,
|
||||||
discord_id TEXT NOT NULL,
|
discord_id TEXT NOT NULL,
|
||||||
discord_username TEXT NOT NULL,
|
discord_username TEXT NOT NULL,
|
||||||
added_on datetime NOT NULL DEFAULT (datetime('now', 'localtime'))
|
added_on datetime NOT NULL DEFAULT (datetime('now', 'localtime'))
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS settings (
|
CREATE TABLE IF NOT EXISTS settings (
|
||||||
guild_id TEXT PRIMARY KEY,
|
guild_id TEXT PRIMARY KEY,
|
||||||
general_chat_id TEXT,
|
general_chat_id TEXT,
|
||||||
new_member_channel_id TEXT,
|
new_member_channel_id TEXT,
|
||||||
tickets_channel_id TEXT,
|
tickets_channel_id TEXT,
|
||||||
event_logs_channel_id TEXT,
|
event_logs_channel_id TEXT,
|
||||||
discord_logs_channel_id TEXT,
|
discord_logs_channel_id TEXT,
|
||||||
audit_logs_channel_id TEXT,
|
audit_logs_channel_id TEXT,
|
||||||
voice_logs_channel_id TEXT,
|
voice_logs_channel_id TEXT,
|
||||||
admin_role_id TEXT,
|
admin_role_id TEXT,
|
||||||
private_help_role_id TEXT,
|
private_help_role_id TEXT,
|
||||||
devwatch_role_id TEXT,
|
devwatch_role_id TEXT,
|
||||||
staff_categories TEXT,
|
staff_categories TEXT,
|
||||||
safe_channels TEXT,
|
safe_channels TEXT,
|
||||||
link_skip_channels TEXT,
|
link_skip_channels TEXT,
|
||||||
github_release_channel TEXT,
|
github_release_channel TEXT,
|
||||||
moderator_channel_id TEXT,
|
moderator_channel_id TEXT,
|
||||||
private_help_channel_id TEXT
|
private_help_channel_id TEXT
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS messages (
|
CREATE TABLE IF NOT EXISTS messages (
|
||||||
id TEXT PRIMARY KEY ON CONFLICT REPLACE,
|
id TEXT PRIMARY KEY ON CONFLICT REPLACE,
|
||||||
author_id TEXT NOT NULL,
|
author_id TEXT NOT NULL,
|
||||||
author_name TEXT NOT NULL,
|
author_name TEXT NOT NULL,
|
||||||
channel_id TEXT NOT NULL,
|
channel_id TEXT NOT NULL,
|
||||||
attachments TEXT NOT NULL,
|
attachments TEXT NOT NULL,
|
||||||
stickers TEXT NOT NULL,
|
stickers TEXT NOT NULL,
|
||||||
content 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 (
|
CREATE TABLE IF NOT EXISTS tickets (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
message_id TEXT NOT NULL
|
message_id TEXT NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS ticket_phrases (
|
CREATE TABLE IF NOT EXISTS ticket_phrases (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
user_id TEXT NOT NULL,
|
user_id TEXT NOT NULL,
|
||||||
phrase TEXT NOT NULL
|
phrase TEXT NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS notes (
|
CREATE TABLE IF NOT EXISTS notes (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
user_id TEXT,
|
user_id TEXT,
|
||||||
reason TEXT,
|
reason TEXT,
|
||||||
mod_id TEXT,
|
mod_id TEXT,
|
||||||
timestamp datetime NOT NULL DEFAULT (datetime('now', 'localtime'))
|
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 (
|
CREATE TABLE IF NOT EXISTS note_edits (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
note_id INTEGER,
|
note_id INTEGER,
|
||||||
mod_id TEXT,
|
mod_id TEXT,
|
||||||
previous_reason TEXT,
|
previous_reason TEXT,
|
||||||
timestamp datetime NOT NULL DEFAULT (datetime('now', 'localtime')),
|
timestamp datetime NOT NULL DEFAULT (datetime('now', 'localtime')),
|
||||||
FOREIGN KEY(note_id) REFERENCES notes(id)
|
FOREIGN KEY(note_id) REFERENCES notes(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS bans (
|
CREATE TABLE IF NOT EXISTS bans (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
user_id TEXT,
|
user_id TEXT,
|
||||||
expires INTEGER,
|
expires INTEGER,
|
||||||
expires_at datetime,
|
expires_at datetime,
|
||||||
full_ban INTEGER
|
full_ban INTEGER
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS github_user_mapping (
|
CREATE TABLE IF NOT EXISTS github_user_mapping (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
discord_id TEXT,
|
discord_id TEXT,
|
||||||
github_username TEXT
|
github_username TEXT
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS knowledgebase (
|
CREATE TABLE IF NOT EXISTS knowledgebase (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
guild_id TEXT NOT NULL,
|
guild_id TEXT NOT NULL,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
content TEXT NOT NULL
|
content TEXT NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS private_help_tickets (
|
CREATE TABLE IF NOT EXISTS private_help_tickets (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
thread_id TEXT NOT NULL,
|
thread_id TEXT NOT NULL,
|
||||||
user_id TEXT NOT NULL,
|
user_id TEXT NOT NULL,
|
||||||
status INTEGER NOT NULL,
|
status INTEGER NOT NULL,
|
||||||
timestamp datetime NOT NULL DEFAULT (datetime('now', 'localtime'))
|
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 {
|
export const enum PrivateHelpTicketStatus {
|
||||||
@@ -148,7 +148,7 @@ export class Database {
|
|||||||
console.log('Database migrations ran');
|
console.log('Database migrations ran');
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- START WHOIS --
|
//#region WHOIS
|
||||||
|
|
||||||
static async getE621Ids(discordId: string): Promise<number[]> {
|
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);
|
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);
|
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> {
|
static async getGuildSettings(guildId: string): Promise<GuildSettings> {
|
||||||
return await Database.db.get<GuildSettings>('SELECT * FROM settings WHERE guild_id = ?', guildId);
|
return await Database.db.get<GuildSettings>('SELECT * FROM settings WHERE guild_id = ?', guildId) as GuildSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async putGuild(guildId: string) {
|
static async putGuild(guildId: string) {
|
||||||
await Database.db.run('INSERT INTO settings(guild_id) VALUES (?)', guildId);
|
await Database.db.run('INSERT INTO settings(guild_id) VALUES (?)', guildId);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async setGuildGeneralChatId(guildId: string, id: string) {
|
static async updateGuildSettings(guildId: string, key: GuildSetting, value: string) {
|
||||||
await Database.db.run('UPDATE settings SET general_chat_id = ? WHERE guild_id = ?', id, guildId);
|
await Database.db.run(`UPDATE settings SET ${key} = ? WHERE guild_id = ?`, value, 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since "setting" has guaranteed values and is never set by the user, this shouldn't cause any security issues.
|
// 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- END SETTINGS --
|
//#endregion
|
||||||
|
|
||||||
// START MESSAGE LOGS --
|
//#region Message Logs
|
||||||
|
|
||||||
static async putMessage(message: Message): Promise<boolean> {
|
static async putMessage(message: Message): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
@@ -324,9 +272,9 @@ export class Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- END MESSAGE LOGS --
|
//#endregion
|
||||||
|
|
||||||
// -- START TICKETS --
|
//#region Tickets
|
||||||
|
|
||||||
static async putTicket(ticketId: number, messageId: string) {
|
static async putTicket(ticketId: number, messageId: string) {
|
||||||
await Database.db.run('INSERT INTO tickets(id, message_id) VALUES (?, ?)', ticketId, messageId);
|
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) {
|
static async putAppeal(appealId: number, messageId: string) {
|
||||||
await Database.db.run('INSERT INTO appeals(id, message_id) VALUES (?, ?)', appealId, messageId);
|
await Database.db.run('INSERT INTO appeals(id, message_id) VALUES (?, ?)', appealId, messageId);
|
||||||
@@ -386,9 +334,9 @@ export class Database {
|
|||||||
return appeal?.message_id;
|
return appeal?.message_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- END APPEALS --
|
//#endregion
|
||||||
|
|
||||||
// -- START NOTES --
|
//#region Notes
|
||||||
|
|
||||||
static async putNote(userId: string, reason: string, modId: string) {
|
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);
|
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);
|
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) {
|
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);
|
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);
|
await Database.db.run('DELETE from bans WHERE user_id = ?', userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- END BANS --
|
//#endregion
|
||||||
|
|
||||||
// -- START GITHUB USER MAPPING --
|
//# GitHub User Mapping
|
||||||
|
|
||||||
// github_user_mapping
|
// github_user_mapping
|
||||||
static async putGithubUserMapping(discordId: string, githubUsername: string) {
|
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);
|
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) {
|
static async addToKnowledgebase(guildId: string, name: string, content: string) {
|
||||||
if (content.length > 2000) return;
|
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);
|
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) {
|
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);
|
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);
|
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
|
appeals_channel_id?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GuildSetting = Exclude<keyof GuildSettings, 'guild_id'>
|
||||||
export type GuildArraySetting = 'staff_categories' | 'safe_channels' | 'link_skip_channels';
|
export type GuildArraySetting = 'staff_categories' | 'safe_channels' | 'link_skip_channels';
|
||||||
|
|
||||||
export type TicketMessage = {
|
export type TicketMessage = {
|
||||||
@@ -82,4 +83,4 @@ export type PrivateHelpTicket = {
|
|||||||
thread_id: string
|
thread_id: string
|
||||||
status: PrivateHelpTicketStatus
|
status: PrivateHelpTicketStatus
|
||||||
timestamp: string
|
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 './commands';
|
||||||
export * from './debug-utils';
|
export * from './debug-utils';
|
||||||
export * from './discord-user-utils';
|
export * from './discord-user-utils';
|
||||||
|
export * from './embed-utils';
|
||||||
export * from './e621-utils';
|
export * from './e621-utils';
|
||||||
export * from './event-log-utils';
|
export * from './event-log-utils';
|
||||||
export * from './file-utils';
|
export * from './file-utils';
|
||||||
|
|||||||
Reference in New Issue
Block a user