"CREATE TABLE IF NOT EXISTS settings ( id smallint PRIMARY KEY, version integer NOT NULL, CHECK(id = 1) );\nALTER TABLE guilds ADD COLUMN accessed timestamp;",
"ALTER TABLE guilds DROP COLUMN accessed",
"ALTER TABLE settings ADD COLUMN IF NOT EXISTS broadcast text"
];
exportasyncfunctionsetup(){
constexistingCommands=(awaitsql`SELECT command FROM counts`).map(x=>x.command);
awaitsql`INSERT INTO tags ${sql({guild_id:guild.id,name,content:content.content,author:content.author}, "guild_id", "name", "content", "author")}`;
}
exportasyncfunctioneditTag(name,content,guild){
awaitsql`UPDATE tags SET content = ${content.content}, author = ${content.author} WHERE guild_id = ${guild.id} AND name = ${name}`;
}
exportasyncfunctionremoveTag(name,guild){
awaitsql`DELETE FROM tags WHERE guild_id = ${guild.id} AND name = ${name}`;
}
exportasyncfunctionsetBroadcast(msg){
awaitsql`UPDATE settings SET broadcast = ${msg} WHERE id = 1`;
}
exportasyncfunctiongetBroadcast(){
constresult=awaitsql`SELECT broadcast FROM settings WHERE id = 1`;
returnresult[0].broadcast;
}
exportasyncfunctiondisableCommand(guild,command){
constguildDB=awaitthis.getGuild(guild);
awaitsql`UPDATE guilds SET disabled_commands = ${(guildDB.disabled_commands?[...guildDB.disabled_commands,command]:[command]).filter((v)=>!!v)} WHERE guild_id = ${guild}`;
awaitsql`UPDATE guilds SET disabled_commands = ${newDisabled} WHERE guild_id = ${channel.guildID}`;
disabledCache.set(channel.guildID,newDisabled);
}
exportasyncfunctiongetCounts(){
constcounts=awaitsql`SELECT * FROM counts`;
constcountObject={};
for(const{command,count}ofcounts){
countObject[command]=count;
}
returncountObject;
}
exportasyncfunctionaddCount(command){
awaitsql`INSERT INTO counts ${sql({command,count:1}, "command", "count")} ON CONFLICT (command) DO UPDATE SET count = counts.count + 1 WHERE counts.command = ${command}`;