logger.info(`Migrating SQLite database at ${process.env.DB}, which is currently at version ${version}...`);
while(version<latestVersion){
version++;
logger.info(`Running version ${version} update script...`);
connection.exec(updates[version]);
}
}elseif(version>latestVersion){
thrownewError(`SQLite database is at version ${version}, but this version of the bot only supports up to version ${latestVersion}.`);
}else{
return;
}
connection.pragma(`user_version = ${latestVersion}`);// prepared statements don't seem to work here
}catch(e){
logger.error(`SQLite migration failed: ${e}`);
connection.exec("ROLLBACK");
logger.error("Unable to start the bot, quitting now.");
return1;
}
connection.exec("COMMIT");
}
exportasyncfunctionaddCount(command){
connection.prepare("UPDATE counts SET count = count + 1 WHERE command = ?").run(command);
}
exportasyncfunctiongetCounts(){
constcounts=connection.prepare("SELECT * FROM counts").all();
constcountObject={};
for(const{command,count}ofcounts){
countObject[command]=count;
}
returncountObject;
}
exportasyncfunctiondisableCommand(guild,command){
constguildDB=awaitthis.getGuild(guild);
connection.prepare("UPDATE guilds SET disabled_commands = ? WHERE guild_id = ?").run(JSON.stringify((guildDB.disabledCommands?[...JSON.parse(guildDB.disabledCommands),command]:[command]).filter((v)=>!!v)),guild);
connection.prepare("UPDATE guilds SET disabled_commands = ? WHERE guild_id = ?").run(JSON.stringify(newDisabled),guild);
disabledCmdCache.set(guild,newDisabled);
}
exportasyncfunctiondisableChannel(channel){
constguildDB=awaitthis.getGuild(channel.guildID);
connection.prepare("UPDATE guilds SET disabled = ? WHERE guild_id = ?").run(JSON.stringify([...JSON.parse(guildDB.disabled),channel.id]),channel.guildID);