From 763fb7d98c3accbb21adf035a7cf0a83cb9533c9 Mon Sep 17 00:00:00 2001 From: TymanWasTaken <32660892+tymanwastaken@users.noreply.github.com> Date: Tue, 27 Apr 2021 21:06:22 -0600 Subject: legit just copy utilibot v2 code --- src/lib/extensions/BotGuild.ts | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/lib/extensions/BotGuild.ts (limited to 'src/lib/extensions/BotGuild.ts') diff --git a/src/lib/extensions/BotGuild.ts b/src/lib/extensions/BotGuild.ts new file mode 100644 index 0000000..22d7834 --- /dev/null +++ b/src/lib/extensions/BotGuild.ts @@ -0,0 +1,38 @@ +import { Guild, Structures } from 'discord.js'; +import { BotClient } from './BotClient'; +import { Guild as GuildModel } from '../types/Models'; + +export class GuildSettings { + private guild: BotGuild; + constructor(guild: BotGuild) { + this.guild = guild; + } + public async getPrefix(): Promise { + return await GuildModel.findByPk(this.guild.id).then( + (gm) => gm?.prefix || this.guild.client.config.prefix + ); + } + public async setPrefix(value: string): Promise { + let entry = await GuildModel.findByPk(this.guild.id); + if (!entry) { + entry = GuildModel.build({ + id: this.guild.id, + prefix: value + }); + } else { + entry.prefix = value; + } + await entry.save(); + } +} + +export class BotGuild extends Guild { + constructor(client: BotClient, data: Record) { + super(client, data); + } + static install(): void { + Structures.extend('Guild', () => BotGuild); + } + public settings = new GuildSettings(this); + public client: BotClient; +} -- cgit