feat: base settings command
This commit is contained in:
parent
ba012a5b2b
commit
bd995747fa
9 changed files with 155 additions and 14 deletions
|
@ -47,7 +47,10 @@
|
|||
<option name="HTML_DO_NOT_INDENT_CHILDREN_OF" value="" />
|
||||
</HTMLCodeStyleSettings>
|
||||
<JSCodeStyleSettings version="0">
|
||||
<option name="SPACE_WITHIN_ARRAY_INITIALIZER_BRACKETS" value="true" />
|
||||
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
||||
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
|
||||
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
||||
</JSCodeStyleSettings>
|
||||
<Markdown>
|
||||
<option name="MAX_LINES_AROUND_HEADER" value="0" />
|
||||
|
@ -65,9 +68,12 @@
|
|||
<option name="IDENTIFIER_CASE" value="1" />
|
||||
</SqlCodeStyleSettings>
|
||||
<TypeScriptCodeStyleSettings version="0">
|
||||
<option name="SPACE_WITHIN_ARRAY_INITIALIZER_BRACKETS" value="true" />
|
||||
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
||||
<option name="USE_PUBLIC_MODIFIER" value="true" />
|
||||
<option name="PREFER_AS_TYPE_CAST" value="true" />
|
||||
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
|
||||
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
||||
<option name="IMPORT_SORT_MODULE_NAME" value="true" />
|
||||
</TypeScriptCodeStyleSettings>
|
||||
<codeStyleSettings language="CSS">
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||
</state>
|
||||
</component>
|
|
@ -15,12 +15,17 @@
|
|||
* along with ArgonBot. If not, see <https: //www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import type ArgonClient from '@lib/ArgonClient';
|
||||
import type Command from '@structures/command';
|
||||
exports.shorthands = undefined;
|
||||
|
||||
declare module 'discord.js' {
|
||||
export interface Client {
|
||||
constructor: typeof ArgonClient;
|
||||
readonly commands: Collection<string, Command>;
|
||||
}
|
||||
}
|
||||
exports.up = (pgm) => {
|
||||
pgm.createTable('settings', {
|
||||
id: {
|
||||
type: 'varchar(20)',
|
||||
},
|
||||
locale: {
|
||||
type: 'varchar(10)',
|
||||
default: 'en-US',
|
||||
notNull: true,
|
||||
},
|
||||
});
|
||||
};
|
102
src/commands/admin/settings.ts
Normal file
102
src/commands/admin/settings.ts
Normal file
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* This file is part of ArgonBot
|
||||
*
|
||||
* ArgonBot is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ArgonBot is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ArgonBot. If not, see <https: //www.gnu.org/licenses/>.
|
||||
*/
|
||||
import Command from '@structures/command';
|
||||
import { ECommandRunIn, IGuildSettings } from '@utils/types';
|
||||
import { query } from '@utils/utils';
|
||||
import type { Client, Message } from 'discord.js';
|
||||
import i18next from 'i18next';
|
||||
import SQL from 'sql-template-strings';
|
||||
|
||||
export default class extends Command {
|
||||
public constructor(client: Client, file: string) {
|
||||
super(client, file, {
|
||||
shortDescription: i18next.t('commands:settings.shortDescription'),
|
||||
extendedDescription: i18next.t('commands:settings.extendedDescription'),
|
||||
usage: 'set locale en-US',
|
||||
runIn: ECommandRunIn.Server,
|
||||
args: [
|
||||
{
|
||||
name: 'action',
|
||||
acceptedValues: [ 'set', 'get', 'reset' ],
|
||||
description: i18next.t('commands:settings.actionArg'),
|
||||
},
|
||||
{
|
||||
name: 'setting',
|
||||
description: i18next.t('commands:settings.settingArg'),
|
||||
},
|
||||
{
|
||||
name: 'value',
|
||||
description: i18next.t('commands:settings.valueArg'),
|
||||
optional: true,
|
||||
goToEnd: true,
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
public async run(message: Message, action: string, setting: string, value: string): Promise<void> {
|
||||
switch(action) {
|
||||
case 'set':
|
||||
await this.setSetting(message, setting, value);
|
||||
break;
|
||||
case 'get':
|
||||
break;
|
||||
case 'reset':
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private async setSetting(message: Message, setting: string, value: string): Promise<void> {
|
||||
let findGuild = await query<IGuildSettings>(SQL`SELECT *
|
||||
FROM bot.public.settings
|
||||
WHERE id = ${message.guild?.id}`);
|
||||
|
||||
if(findGuild && findGuild.rowCount === 0) {
|
||||
await query(SQL`INSERT INTO bot.public.settings (id)
|
||||
VALUES (${message.guild?.id})`);
|
||||
findGuild = await query<IGuildSettings>(SQL`SELECT *
|
||||
FROM bot.public.settings
|
||||
WHERE id = ${message.guild?.id}`);
|
||||
}
|
||||
|
||||
switch(setting) {
|
||||
case 'locale':
|
||||
case 'language':
|
||||
if(findGuild) {
|
||||
const guildSettings = findGuild.rows[0]!;
|
||||
if(guildSettings.locale === value)
|
||||
await message.reply(i18next.t('commands:settings.localeAlreadySet', { locale: guildSettings.locale }));
|
||||
else {
|
||||
await query(SQL`UPDATE bot.public.settings
|
||||
SET locale=${value}
|
||||
WHERE id = ${message.guild?.id}`);
|
||||
|
||||
await message.channel.send(i18next.t('commands:settings.localeSuccessfullySet', { locale: value }));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'get':
|
||||
break;
|
||||
case 'reset':
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,13 +15,12 @@
|
|||
* along with ArgonBot. If not, see <https: //www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'module-alias/register';
|
||||
import '@utils/augments';
|
||||
|
||||
import ArgonClient from '@lib/ArgonClient';
|
||||
import { Defaults } from '@utils/defaults';
|
||||
import { debug, error, fatal, info, verbose } from '@utils/logger';
|
||||
import { ECommandRunIn, ELoggingScope } from '@utils/types';
|
||||
import { connectToDB, query, walkDir } from '@utils/utils';
|
||||
import { connectToDB, walkDir } from '@utils/utils';
|
||||
import chalk from 'chalk';
|
||||
import config from 'config';
|
||||
import { Collection } from 'discord.js';
|
||||
|
@ -36,7 +35,6 @@ import FSBackend from 'i18next-fs-backend';
|
|||
import { Validator } from 'jsonschema';
|
||||
import { DateTime } from 'luxon';
|
||||
import process from 'process';
|
||||
import { SQL } from 'sql-template-strings';
|
||||
|
||||
const commandCooldowns: Collection<string, Collection<string, number>> = new Collection();
|
||||
let isBotReady = false;
|
||||
|
|
16
src/lib/extensions/ArgonGuild.ts
Normal file
16
src/lib/extensions/ArgonGuild.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* This file is part of ArgonBot
|
||||
*
|
||||
* ArgonBot is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ArgonBot is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ArgonBot. If not, see <https: //www.gnu.org/licenses/>.
|
||||
*/
|
|
@ -49,4 +49,9 @@ export interface ICommandOptions {
|
|||
}[];
|
||||
}
|
||||
|
||||
export interface IGuildSettings {
|
||||
id: string,
|
||||
locale: string;
|
||||
}
|
||||
|
||||
// Type Aliases
|
||||
|
|
|
@ -76,7 +76,7 @@ export const connectToDB = async (connectionData: pg.PoolConfig): Promise<void>
|
|||
});
|
||||
};
|
||||
|
||||
export const query = async (query: SQLStatement): Promise<QueryResult | void>=> {
|
||||
export const query = async <t>(query: SQLStatement): Promise<QueryResult<t> | void> => {
|
||||
if(!pool) return error('Attempted to query to the Database when a connection has not been made yet... Discarding' +
|
||||
' request.', ELoggingScope.Query);
|
||||
else {
|
||||
|
@ -87,7 +87,7 @@ export const query = async (query: SQLStatement): Promise<QueryResult | void>=>
|
|||
await client.query('BEGIN');
|
||||
|
||||
info(query.text, ELoggingScope.Query);
|
||||
const result = await client.query(query);
|
||||
const result = await client.query<t>(query);
|
||||
|
||||
info('COMMIT', ELoggingScope.Query);
|
||||
await client.query('COMMIT');
|
||||
|
|
|
@ -21,6 +21,15 @@
|
|||
"commandDescription": "Name: `{ $name }`\nCategory: `{ $category }`\nDescription: `{ $description }`\nUsage: `{ $usage }`",
|
||||
"categoryPlaceholder": "Choose a category!"
|
||||
},
|
||||
"settings": {
|
||||
"shortDescription": "Changes the current server settings",
|
||||
"extendedDescription": "Changes the current server settings for better server customization",
|
||||
"actionArg": "What action you want to take",
|
||||
"settingArg": "What setting you want to view/set\nOr optionally, you can put 'help' if you are unsure what to do with that action",
|
||||
"valueArg": "The value you want to set (This is ignored if you are only getting/resetting a setting).",
|
||||
"localeAlreadySet": "The language of the bot in this server is already set to { $locale }!",
|
||||
"localeSuccessfullySet": "The language of the bot has been successfully set to { $locale }!"
|
||||
},
|
||||
"errors": {
|
||||
"ownerOnly": "Only the bot owner can run this command!",
|
||||
"dmsOnly": "You can only run this command in DMs!",
|
||||
|
|
Reference in a new issue