mirror of
https://github.com/toast-ts/Daggerbot-TS.git
synced 2024-11-17 04:10:59 -05:00
Improvements
This commit is contained in:
parent
2d412c0994
commit
54145161ec
@ -6,7 +6,7 @@ import Formatters from '../helpers/Formatters.js';
|
||||
import GitHub from '../helpers/GitHub.js';
|
||||
import TClient from '../client.js';
|
||||
import util from 'node:util';
|
||||
import fs from 'node:fs';
|
||||
import fs, { writeFileSync } from 'node:fs';
|
||||
export default class Developer {
|
||||
static run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>) {
|
||||
if (!client.config.whitelist.includes(interaction.user.id)) return MessageTool.youNeedRole(interaction, 'bottech');
|
||||
@ -102,6 +102,7 @@ export default class Developer {
|
||||
if (name) currentActivities[0].name = name;
|
||||
if (url) currentActivities[0].url = url;
|
||||
client.user.setPresence(client.config.botPresence);
|
||||
writeFileSync(process.argv[2] ?? 'src/config.json', JSON.stringify(client.config, null, 2));
|
||||
interaction.reply(MessageTool.concatMessage(
|
||||
'Presence updated:',
|
||||
`Status: **${client.config.botPresence.status}**`,
|
||||
@ -157,7 +158,7 @@ export default class Developer {
|
||||
.setRequired(false)))
|
||||
.addSubcommand(x=>x
|
||||
.setName('restart')
|
||||
.setDescription('Restart the bot for technical reasons'))
|
||||
.setDescription('Restart the bot for manual changes/technical difficulties'))
|
||||
.addSubcommand(x=>x
|
||||
.setName('update')
|
||||
.setDescription('Pull from repository and restart')
|
||||
|
@ -47,13 +47,6 @@ export default class ProhibitedWords {
|
||||
]
|
||||
});
|
||||
}
|
||||
},
|
||||
import: async()=>{
|
||||
const file = interaction.options.getAttachment('file', true);
|
||||
if (!file.contentType.match(/application\/json/)) return interaction.reply({ephemeral: true, content: 'This file is not a JSON file!'});
|
||||
const success = await client.prohibitedWords.importWords(file.url);
|
||||
if (success) interaction.reply({ephemeral: true, content: `Successfully imported the list from \`${file.name}\` into the database`});
|
||||
else interaction.reply({ephemeral: true, content: `Failed to import the list from \`${file.name}\` into the database`});
|
||||
}
|
||||
} as any)[interaction.options.getSubcommand()]();
|
||||
}
|
||||
@ -80,11 +73,4 @@ export default class ProhibitedWords {
|
||||
.setName('word')
|
||||
.setDescription('Remove the specific word from automod\'s prohibitedWords database')
|
||||
.setRequired(true)))
|
||||
.addSubcommand(x=>x
|
||||
.setName('import')
|
||||
.setDescription('Import a JSON file of words into the database')
|
||||
.addAttachmentOption(x=>x
|
||||
.setName('file')
|
||||
.setDescription('The JSON file to import')
|
||||
.setRequired(true)))
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
import DatabaseServer from '../components/DatabaseServer.js';
|
||||
import {Model, DataTypes} from 'sequelize';
|
||||
import {get} from 'node:https';
|
||||
|
||||
class prohibitedWords extends Model {
|
||||
declare public word: string;
|
||||
@ -27,25 +26,6 @@ export class ProhibitedWordsSvc {
|
||||
this.model.sync();
|
||||
}
|
||||
findWord = async(word:string)=>await this.model.findByPk(word);
|
||||
async importWords(file:string) {
|
||||
const jsonData = await new Promise<string>((resolve, reject)=>{
|
||||
get(file, res=>{
|
||||
let data = '';
|
||||
res.on('data', chunk=>data += chunk);
|
||||
res.on('end', ()=>resolve(data));
|
||||
res.on('error', reject);
|
||||
})
|
||||
});
|
||||
|
||||
const data = JSON.parse(jsonData);
|
||||
const dataMapping = data.map((x:string)=>({word: x}));
|
||||
try {
|
||||
await this.model.bulkCreate(dataMapping, {ignoreDuplicates: true});
|
||||
return true;
|
||||
} catch(err) {
|
||||
throw new Error(`Failed to insert words into Postgres database: ${err.message}`)
|
||||
}
|
||||
}
|
||||
getAllWords = async()=>await this.model.findAll();
|
||||
insertWord = async(word:string)=>await this.model.create({word: word});
|
||||
removeWord = async(word:string)=>await this.model.destroy({where: {word: word}})
|
||||
|
Loading…
Reference in New Issue
Block a user