aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/extensions/discord-akairo/BushClient.ts2
-rw-r--r--src/lib/extensions/discord-akairo/BushClientUtil.ts43
-rw-r--r--src/lib/extensions/discord.js/BushGuildMember.ts24
-rw-r--r--src/lib/models/Guild.ts8
-rw-r--r--src/lib/utils/BushConstants.ts3
5 files changed, 59 insertions, 21 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'
diff --git a/src/lib/models/Guild.ts b/src/lib/models/Guild.ts
index f6aa1a4..43fcd64 100644
--- a/src/lib/models/Guild.ts
+++ b/src/lib/models/Guild.ts
@@ -6,17 +6,13 @@ import { BaseModel } from './BaseModel';
export interface GuildModel {
id: string;
prefix: string;
- autoPublishChannels: string[];
+ autoPublishChannels: Snowflake[];
blacklistedChannels: Snowflake[];
welcomeChannel: Snowflake;
muteRole: Snowflake;
punishmentEnding: string;
}
-// export type GuildModelCreationAttributes = Optional<
-// GuildModel,
-// 'prefix' | 'autoPublishChannels' | 'blacklistedChannels' | 'welcomeChannel' | 'muteRole' | 'punishmentEnding'
-// >;
export interface GuildModelCreationAttributes {
id: string;
prefix?: string;
@@ -30,7 +26,7 @@ export interface GuildModelCreationAttributes {
export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> implements GuildModel {
id!: string;
prefix!: string;
- autoPublishChannels: string[];
+ autoPublishChannels: Snowflake[];
blacklistedChannels: Snowflake[];
welcomeChannel: Snowflake;
muteRole: Snowflake;
diff --git a/src/lib/utils/BushConstants.ts b/src/lib/utils/BushConstants.ts
index 7e6013d..747c6d6 100644
--- a/src/lib/utils/BushConstants.ts
+++ b/src/lib/utils/BushConstants.ts
@@ -152,7 +152,8 @@ export class BushConstants {
VOICE: '<:voice:853375566735212584>',
STAGE: '<:stage:853375583521210468>',
STORE: '<:store:853375601175691266>',
- CATEGORY: '<:category:853375615260819476>'
+ CATEGORY: '<:category:853375615260819476>',
+ THREAD: '<:thread:865033845753249813>'
},
userFlags: {