diff options
Diffstat (limited to 'src/lib/extensions')
-rw-r--r-- | src/lib/extensions/discord-akairo/BushClient.ts | 2 | ||||
-rw-r--r-- | src/lib/extensions/discord-akairo/BushClientUtil.ts | 43 | ||||
-rw-r--r-- | src/lib/extensions/discord.js/BushGuildMember.ts | 24 |
3 files changed, 55 insertions, 14 deletions
diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts index cb6a1de..3b14200 100644 --- a/src/lib/extensions/discord-akairo/BushClient.ts +++ b/src/lib/extensions/discord-akairo/BushClient.ts @@ -25,6 +25,7 @@ import { Guild as GuildModel } from '../../models/Guild'; import { Level } from '../../models/Level'; import { ModLog } from '../../models/ModLog'; import { Mute } from '../../models/Mute'; +import { PunishmentRole } from '../../models/PunishmentRole'; import { StickyRole } from '../../models/StickyRole'; import { AllowedMentions } from '../../utils/AllowedMentions'; import { BushCache } from '../../utils/BushCache'; @@ -260,6 +261,7 @@ export class BushClient extends AkairoClient { Mute.initModel(this.db); Level.initModel(this.db); StickyRole.initModel(this.db); + PunishmentRole.initModel(this.db); await this.db.sync({ alter: true }); // Sync all tables to fix everything if updated await this.console.success('Startup', `Successfully connected to <<database>>.`, false); } catch (e) { diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts index b3c9953..6538ebf 100644 --- a/src/lib/extensions/discord-akairo/BushClientUtil.ts +++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts @@ -43,7 +43,7 @@ import { } from 'discord.js'; import got from 'got'; import humanizeDuration from 'humanize-duration'; -import Op from 'sequelize/types/lib/operators'; +import { Op } from 'sequelize'; import { promisify } from 'util'; interface hastebinRes { @@ -99,6 +99,11 @@ interface punishmentModels { role: PunishmentRole; } +interface MojangProfile { + username: string; + uuid: string; +} + export class BushClientUtil extends ClientUtil { /** The client of this ClientUtil */ public declare readonly client: BushClient; @@ -302,6 +307,7 @@ export class BushClientUtil extends ClientUtil { text: string | null = null, deleteOnExit?: boolean ): Promise<void> { + const paginateEmojis = this.paginateEmojis; if (deleteOnExit === undefined) deleteOnExit = true; if (embeds.length === 1) { @@ -374,7 +380,6 @@ export class BushClientUtil extends ClientUtil { ?.update({ content: text, embeds: [embeds[curPage]], components: [getPaginationRow()] }) .catch(() => undefined); } - const paginateEmojis = this.paginateEmojis; function getPaginationRow(disableAll = false): MessageActionRow { return new MessageActionRow().addComponents( new MessageButton({ @@ -408,6 +413,7 @@ export class BushClientUtil extends ClientUtil { /** Sends a message with a button for the user to delete it. */ public async sendWithDeleteButton(message: BushMessage | BushSlashMessage, options: MessageOptions): Promise<void> { + const paginateEmojis = this.paginateEmojis; updateOptions(); const msg = await message.util.reply(options as MessageOptions & { split?: false }); const filter = (interaction: ButtonInteraction) => interaction.customId == 'paginate__stop' && interaction.message == msg; @@ -429,7 +435,6 @@ export class BushClientUtil extends ClientUtil { await msg.edit(options as MessageEditOptions).catch(() => undefined); }); - const paginateEmojis = this.paginateEmojis; function updateOptions(edit?: boolean, disable?: boolean) { if (edit == undefined) edit = false; if (disable == undefined) disable = false; @@ -644,7 +649,7 @@ export class BushClientUtil extends ClientUtil { if (!getCaseNumber) return { log: saveResult, caseNum: null }; - const caseNum = (await ModLog.findAll({ where: { type: options.type, user: options.user, guild: options.guild } }))?.length; + const caseNum = (await ModLog.findAll({ where: { type: options.type, user: user, guild: guild } }))?.length; return { log: saveResult, caseNum }; } @@ -703,6 +708,7 @@ export class BushClientUtil extends ClientUtil { public async findExpiredEntries<K extends keyof punishmentModels>(type: K): Promise<punishmentModels[K][]> { const dbModel = this.findPunishmentModel(type); + console.log(dbModel); //@ts-ignore: stfu idc return await dbModel.findAll({ where: { @@ -733,4 +739,33 @@ export class BushClientUtil extends ClientUtil { public humanizeDuration(duration: number): string { return humanizeDuration(duration, { language: 'en', maxDecimalPoints: 2 }); } + + public async findUUID(player: string): Promise<string> { + try { + const raw = await got.get(`https://api.ashcon.app/mojang/v2/user/${player}`); + let profile: MojangProfile; + if (raw.statusCode == 200) { + profile = JSON.parse(raw.body); + } else { + throw 'invalid player'; + } + + if (raw.statusCode == 200 && profile && profile.uuid) { + return profile.uuid.replace(/-/g, ''); + } else { + throw `Could not fetch the uuid for ${player}.`; + } + } catch (e) { + throw 'An error has occurred.'; + } + } + + public hexToRgb(hex: string): string { + const arrBuff = new ArrayBuffer(4); + const vw = new DataView(arrBuff); + vw.setUint32(0, parseInt(hex, 16), false); + const arrByte = new Uint8Array(arrBuff); + + return arrByte[1] + ', ' + arrByte[2] + ', ' + arrByte[3]; + } } diff --git a/src/lib/extensions/discord.js/BushGuildMember.ts b/src/lib/extensions/discord.js/BushGuildMember.ts index 4bb1c2c..fb85d7f 100644 --- a/src/lib/extensions/discord.js/BushGuildMember.ts +++ b/src/lib/extensions/discord.js/BushGuildMember.ts @@ -80,32 +80,36 @@ export class BushGuildMember extends GuildMember { } public async warn(options: BushPunishmentOptions): Promise<{ result: WarnResponse; caseNum: number }> { + const moderator = this.client.users.cache.get(this.client.users.resolveId(options.moderator || this.client.user)); // add modlog entry - const { log, caseNum } = await this.client.util + const result = await this.client.util .createModLogEntry( { type: ModLogType.WARN, user: this, - moderator: options.moderator || this.client.user.id, + moderator: moderator.id, reason: options.reason, guild: this.guild }, true ) - .catch(() => null); - if (!log) return { result: 'error creating modlog entry', caseNum: null }; + .catch((e) => { + this.client.console.error('warn', e, true, 1); + return { log: null, caseNum: null }; + }); + if (!result || !result.log) return { result: 'error creating modlog entry', caseNum: null }; // dm user - const ending = this.guild.getSetting('punishmentEnding'); + const ending = await this.guild.getSetting('punishmentEnding'); const dmSuccess = await this.send({ content: `You have been warned in **${this.guild}** for **${options.reason || 'No reason provided'}**.${ ending ? `\n\n${ending}` : '' }` }).catch(() => null); - if (!dmSuccess) return { result: 'failed to dm', caseNum }; + if (!dmSuccess) return { result: 'failed to dm', caseNum: result.caseNum }; - return { result: 'success', caseNum }; + return { result: 'success', caseNum: result.caseNum }; } public async addRole(options: AddRoleOptions): Promise<AddRoleResponse> { @@ -232,7 +236,7 @@ export class BushGuildMember extends GuildMember { if (!punishmentEntrySuccess) return 'error creating mute entry'; // dm user - const ending = this.guild.getSetting('punishmentEnding'); + const ending = await this.guild.getSetting('punishmentEnding'); const dmSuccess = await this.send({ content: `You have been muted ${ options.duration ? 'for ' + this.client.util.humanizeDuration(options.duration) : 'permanently' @@ -300,7 +304,7 @@ export class BushGuildMember extends GuildMember { const moderator = this.client.users.cache.get(this.client.users.resolveId(options.moderator || this.client.user)); // dm user - const ending = this.guild.getSetting('punishmentEnding'); + const ending = await this.guild.getSetting('punishmentEnding'); const dmSuccess = await this.send({ content: `You have been kicked from **${this.guild}** for **${options.reason || 'No reason provided'}**.${ ending ? `\n\n${ending}` : '' @@ -333,7 +337,7 @@ export class BushGuildMember extends GuildMember { const moderator = this.client.users.cache.get(this.client.users.resolveId(options.moderator || this.client.user)); // dm user - const ending = this.guild.getSetting('punishmentEnding'); + const ending = await this.guild.getSetting('punishmentEnding'); const dmSuccess = await this.send({ content: `You have been banned ${ options.duration ? 'for ' + this.client.util.humanizeDuration(options.duration) : 'permanently' |