counts=connection.prepare("SELECT * FROM counts").all();
}catch{
connection.prepare("CREATE TABLE counts ( command VARCHAR NOT NULL, count integer NOT NULL )").run();
counts=[];
}
if(!counts){
for(constcommandofcollections.commands.keys()){
connection.prepare("INSERT INTO counts (command, count) VALUES (?, ?)").run(command,0);
}
}else{
constexists=[];
for(constcommandofcollections.commands.keys()){
constcount=connection.prepare("SELECT * FROM counts WHERE command = ?").get(command);
if(!count){
connection.prepare("INSERT INTO counts (command, count) VALUES (?, ?)").run(command,0);
}
exists.push(command);
}
for(const{command}ofcounts){
if(!exists.includes(command)){
connection.prepare("DELETE FROM counts WHERE command = ?").run(command);
}
}
}
};
exports.stop=async()=>{
connection.close();
};
exports.fixGuild=async(guild)=>{
letguildDB;
try{
guildDB=connection.prepare("SELECT * FROM guilds WHERE guild_id = ?").get(guild.id);
}catch{
connection.prepare("CREATE TABLE guilds ( guild_id VARCHAR(30) NOT NULL, tags text NOT NULL, prefix VARCHAR(15) NOT NULL, disabled text NOT NULL, tags_disabled integer NOT NULL DEFAULT 0 CHECK(tags_disabled IN (0,1)) )").run();
}
if(!guildDB){
logger.log(`Registering guild database entry for guild ${guild.id}...`);
returnawaitthis.addGuild(guild);
}
};
exports.addCount=async(command)=>{
connection.prepare("UPDATE counts SET count = count + 1 WHERE command = ?").run(command);
};
exports.getCounts=async()=>{
constcounts=connection.prepare("SELECT * FROM counts").all();
connection.prepare("UPDATE guilds SET disabled = ? WHERE guild_id = ?").run(JSON.stringify([...JSON.parse(guildDB.disabled),channel.id]),channel.guild.id);