MCPcopy Create free account
hub / github.com/esmBot/esmBot / getGuild

Method getGuild

src/database/sqlite.ts:247–297  ·  view source on GitHub ↗
(query: string)

Source from the content-addressed store, hash-verified

245 }
246
247 async getGuild(query: string): Promise<DBGuild> {
248 // SQLite does not support arrays, so instead we convert them from strings
249 let guild:
250 | ({
251 disabled: string;
252 disabled_commands: string;
253 tag_roles: string;
254 } & Omit<DBGuild, "disabled" | "disabled_commands" | "tag_roles">)
255 | undefined;
256 try {
257 this.connection.exec("BEGIN TRANSACTION");
258 guild = this.connection.prepare("SELECT * FROM guilds WHERE guild_id = ?").get(query) as {
259 disabled: string;
260 disabled_commands: string;
261 tag_roles: string;
262 } & Omit<DBGuild, "disabled" | "disabled_commands" | "tag_roles">;
263 if (!guild) {
264 const guild_id = query;
265 const prefix = process.env.PREFIX ?? "&";
266 guild = {
267 guild_id,
268 prefix,
269 disabled: "[]",
270 disabled_commands: "[]",
271 tag_roles: "[]",
272 };
273 this.connection
274 .prepare(
275 "INSERT INTO guilds (guild_id, prefix, disabled, disabled_commands, tag_roles) VALUES (:guild_id, :prefix, :disabled, :disabled_commands, :tag_roles)",
276 )
277 .run(guild);
278 }
279 this.connection.exec("COMMIT");
280 } catch {
281 this.connection.exec("ROLLBACK");
282 }
283 if (guild) {
284 guild.disabled = JSON.parse(guild.disabled);
285 guild.disabled_commands = JSON.parse(guild.disabled_commands);
286 guild.tag_roles = JSON.parse(guild.tag_roles);
287 }
288 return (
289 (guild as DBGuild | undefined) ?? {
290 guild_id: query,
291 prefix: process.env.PREFIX ?? "&",
292 disabled: [],
293 disabled_commands: [],
294 tag_roles: [],
295 }
296 );
297 }
298}

Callers 15

disableCommandMethod · 0.95
enableCommandMethod · 0.95
disableChannelMethod · 0.95
enableChannelMethod · 0.95
addTagRoleMethod · 0.95
removeTagRoleMethod · 0.95
runMethod · 0.45
runMethod · 0.45
runMethod · 0.45
runMethod · 0.45
runMethod · 0.45
runMethod · 0.45

Calls 1

runMethod · 0.45

Tested by

no test coverage detected