diff --git a/commands/setprefix.ts b/commands/setprefix.ts new file mode 100644 index 0000000..08d034b --- /dev/null +++ b/commands/setprefix.ts @@ -0,0 +1,34 @@ +import { Message, Client } from 'discord.js'; +import sqlite3 from 'sqlite3'; +require('dotenv').config(); + +module.exports = { + aliases: [], + description: 'Change le préfixe du bot.', + emote: '⏱️', + utilisation: '', + + async execute(message: Message, args: string[], client: Client) { + const dbName = process.env.DB_NAME || 'db.db'; + let db = new sqlite3.Database(dbName, sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, (err: any) => { + if (err) { + console.error(err.message); + } + }); + + const prefix = args[0] || '!!'; + db.run('UPDATE config SET value = ? WHERE name = "prefix"', [prefix], (err: any) => { + if (err) { + console.error(err.message); + } + }); + + db.close((err) => { + if (err) { + console.error(err.message); + } + }); + + message.edit(`Le préfixe a été changé pour \`${prefix}\``); + } +}; \ No newline at end of file diff --git a/events/ready.ts b/events/ready.ts index aa2a7c4..90357c7 100644 --- a/events/ready.ts +++ b/events/ready.ts @@ -55,9 +55,6 @@ module.exports = { rows.forEach((row: any) => { if (row.name === 'autovoc') { voc = row.value || 'None'; - if (voc !== 'None') { - joinVC(client, voc); - } } }); }); diff --git a/fonctions/addBaseInDB.ts b/fonctions/addBaseInDB.ts index 429caea..1b758f7 100644 --- a/fonctions/addBaseInDB.ts +++ b/fonctions/addBaseInDB.ts @@ -9,18 +9,24 @@ module.exports = function addBaseInDB(client: any) { } }); - const prefix = process.env.DEFAULT_PREFIX || '!!'; - db.run('INSERT OR IGNORE INTO config(name, value) VALUES(?, ?)', ['prefix', prefix], (err) => { - if (err) { - console.error(err.message); - } - }); + db.serialize(() => { + db.run('BEGIN TRANSACTION'); - const voc = 'None'; - db.run('INSERT OR IGNORE INTO config(name, value) VALUES(?, ?)', ['autovoc', voc], (err) => { - if (err) { - console.error(err.message); - } + const prefix = process.env.DEFAULT_PREFIX || '!!'; + db.run('INSERT OR IGNORE INTO config(name, value) VALUES(?, ?)', ['prefix', prefix], (err) => { + if (err) { + console.error(err.message); + } + }); + + const voc = 'None'; + db.run('INSERT OR IGNORE INTO config(name, value) VALUES(?, ?)', ['autovoc', voc], (err) => { + if (err) { + console.error(err.message); + } + }); + + db.run('COMMIT'); }); db.close((err) => {