aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-07-02 19:33:29 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-07-02 19:33:29 -0400
commit34f0d1d3ff3e2a90193c9a4d4de29d8335160d6a (patch)
treef5a069b332b649f510aac741ae2484e853efc6a2 /src/lib
parent6c3ab0e2e4239a2122d1d8ce8ed7bc9673fdde6a (diff)
downloadtanzanite-34f0d1d3ff3e2a90193c9a4d4de29d8335160d6a.tar.gz
tanzanite-34f0d1d3ff3e2a90193c9a4d4de29d8335160d6a.tar.bz2
tanzanite-34f0d1d3ff3e2a90193c9a4d4de29d8335160d6a.zip
started restructuring moderation commands,
note: nothing currently works :flushed:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/extensions/discord-akairo/BushClient.ts17
-rw-r--r--src/lib/extensions/discord-akairo/BushClientUtil.ts83
-rw-r--r--src/lib/extensions/discord.js/BushGuild.ts2
-rw-r--r--src/lib/extensions/discord.js/BushGuildMember.ts60
-rw-r--r--src/lib/extensions/discord.js/BushGuildMemberManager.ts11
-rw-r--r--src/lib/extensions/discord.js/BushMessageManager.ts3
-rw-r--r--src/lib/extensions/discord.js/BushThreadMemberManager.ts9
-rw-r--r--src/lib/extensions/global.d.ts9
-rw-r--r--src/lib/models/ModLog.ts19
9 files changed, 175 insertions, 38 deletions
diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts
index 724f01a..6911573 100644
--- a/src/lib/extensions/discord-akairo/BushClient.ts
+++ b/src/lib/extensions/discord-akairo/BushClient.ts
@@ -9,13 +9,13 @@ import {
MessagePayload,
ReplyMessageOptions,
Snowflake,
- Structures,
- UserResolvable
+ Structures
} from 'discord.js';
import * as path from 'path';
import { exit } from 'process';
import readline from 'readline';
import { Sequelize } from 'sequelize';
+import { contentWithDurationTypeCaster } from '../../../arguments/contentWithDuration';
import { durationTypeCaster } from '../../../arguments/duration';
import * as config from '../../../config/options';
import UpdateCacheTask from '../../../tasks/updateCache';
@@ -54,6 +54,9 @@ export type BotConfig = typeof config;
export type BushReplyMessageType = string | MessagePayload | ReplyMessageOptions;
export type BushEditMessageType = string | MessageEditOptions | MessagePayload;
export type BushSendMessageType = string | MessagePayload | MessageOptions;
+export type BushThreadMemberResolvable = BushThreadMember | BushUserResolvable;
+export type BushUserResolvable = BushUser | Snowflake | BushMessage | BushGuildMember | BushThreadMember;
+export type BushGuildMemberResolvable = BushGuildMember | BushUserResolvable;
const rl = readline.createInterface({
input: process.stdin,
@@ -168,7 +171,7 @@ export class BushClient extends AkairoClient {
dialect: 'postgres',
host: this.config.db.host,
port: this.config.db.port,
- logging: this.config.logging.db ? (a) => this.logger.debug(a) : false
+ logging: this.config.logging.db ? (sql) => this.logger.debug(sql) : false
});
this.logger = new BushLogger(this);
}
@@ -198,7 +201,8 @@ export class BushClient extends AkairoClient {
gateway: this.ws
});
this.commandHandler.resolver.addTypes({
- duration: durationTypeCaster
+ duration: durationTypeCaster,
+ contentWithDuration: contentWithDurationTypeCaster
});
// loads all the handlers
const loaders = {
@@ -240,7 +244,6 @@ export class BushClient extends AkairoClient {
/** Starts the bot */
public async start(): Promise<void> {
- //@ts-ignore: stfu bitch
global.client = this;
try {
@@ -260,10 +263,10 @@ export class BushClient extends AkairoClient {
}
}
- public isOwner(user: UserResolvable): boolean {
+ public isOwner(user: BushUserResolvable): boolean {
return this.config.owners.includes(this.users.resolveID(user));
}
- public isSuperUser(user: UserResolvable): boolean {
+ public isSuperUser(user: BushUserResolvable): boolean {
const userID = this.users.resolveID(user);
return !!BushCache?.global?.superUsers?.includes(userID) || this.config.owners.includes(userID);
}
diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts
index 1f8c0f9..9289598 100644
--- a/src/lib/extensions/discord-akairo/BushClientUtil.ts
+++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts
@@ -25,10 +25,13 @@ import {
} from 'discord.js';
import got from 'got';
import { promisify } from 'util';
-import { Global } from '../../models';
+import { Global, Guild, ModLog, ModLogType } from '../../models';
import { BushCache } from '../../utils/BushCache';
+import { BushConstants } from '../../utils/BushConstants';
+import { BushGuildResolvable } from '../discord.js/BushCommandInteraction';
+import { BushGuildMember } from '../discord.js/BushGuildMember';
import { BushMessage } from '../discord.js/BushMessage';
-import { BushClient } from './BushClient';
+import { BushClient, BushGuildMemberResolvable } from './BushClient';
interface hastebinRes {
key: string;
@@ -281,6 +284,10 @@ export class BushClientUtil extends ClientUtil {
): Promise<void> {
if (deleteOnExit === undefined) deleteOnExit = true;
+ if (embeds.length === 1) {
+ return this.sendWithDeleteButton(message, { embeds: embeds });
+ }
+
embeds.forEach((_e, i) => {
embeds[i] = embeds[i].setFooter(`Page ${i + 1}/${embeds.length}`);
});
@@ -523,14 +530,68 @@ export class BushClientUtil extends ClientUtil {
return newArray;
}
- // public createModLogEntry(
- // user: User | Snowflake,
- // guild: Guild | Snowflake,
- // reason?: string,
- // type?: ModLogType,
- // duration?: number,
- // moderator: User | Snowflake
- // ): ModLog {
+ public parseDuration(content: string): { duration: number; contentWithoutTime: string } {
+ if (!content) return { duration: 0, contentWithoutTime: null };
+
+ let duration = 0,
+ contentWithoutTime = content;
- // }
+ const regexString = Object.entries(BushConstants.TimeUnits)
+ .map(([name, { label }]) => String.raw`(?:(?<${name}>-?(?:\d+)?\.?\d+) *${label})?`)
+ .join('\\s*');
+ const match = new RegExp(`^${regexString}$`, 'im').exec(content);
+ if (!match) return null;
+
+ for (const key in match.groups) {
+ contentWithoutTime = contentWithoutTime.replace(match.groups[key], '');
+ const value = Number(match.groups[key] || 0);
+ duration += value * BushConstants.TimeUnits[key].value;
+ }
+
+ return { duration, contentWithoutTime };
+ }
+
+ /**
+ * Checks if a moderator can perform a moderation action on another user.
+ * @param moderator - The person trying to perform the action.
+ * @param victim - The person getting punished.
+ */
+ public moderatorCanModerateUser(moderator: BushGuildMember, victim: BushGuildMember): boolean {
+ throw 'not implemented';
+ if (moderator.guild.id !== victim.guild.id) throw 'wtf';
+ if (moderator.guild.ownerID === moderator.id) return true;
+ }
+
+ public async createModLogEntry(options: {
+ type: ModLogType;
+ user: BushGuildMemberResolvable;
+ moderator: BushGuildMemberResolvable;
+ reason: string;
+ duration: number;
+ guild: BushGuildResolvable;
+ }): Promise<void> {
+ const user = this.client.users.resolveID(options.user);
+ const moderator = this.client.users.resolveID(options.moderator);
+ const guild = this.client.guilds.resolveID(options.guild);
+
+ // If guild does not exist create it so the modlog can reference a guild.
+ await Guild.findOrCreate({
+ where: {
+ id: guild
+ },
+ defaults: {
+ id: guild
+ }
+ });
+
+ const modLogEntry = ModLog.build({
+ type: options.type,
+ user,
+ moderator,
+ reason: options.reason,
+ duration: options.duration,
+ guild
+ });
+ await modLogEntry.save();
+ }
}
diff --git a/src/lib/extensions/discord.js/BushGuild.ts b/src/lib/extensions/discord.js/BushGuild.ts
index 95e07f9..ea34aec 100644
--- a/src/lib/extensions/discord.js/BushGuild.ts
+++ b/src/lib/extensions/discord.js/BushGuild.ts
@@ -4,6 +4,8 @@ import { BushClient } from '../discord-akairo/BushClient';
export class BushGuild extends Guild {
public declare readonly client: BushClient;
+ // I cba to do this
+ //// public declare members: GuildMemberManager;
public constructor(client: BushClient, data: unknown) {
super(client, data);
}
diff --git a/src/lib/extensions/discord.js/BushGuildMember.ts b/src/lib/extensions/discord.js/BushGuildMember.ts
index 6bcb9b8..59dc777 100644
--- a/src/lib/extensions/discord.js/BushGuildMember.ts
+++ b/src/lib/extensions/discord.js/BushGuildMember.ts
@@ -1,13 +1,69 @@
+/* eslint-disable @typescript-eslint/no-unused-vars */
import { GuildMember } from 'discord.js';
-import { BushClient } from '../discord-akairo/BushClient';
+import { BushClient, BushUserResolvable } from '../discord-akairo/BushClient';
import { BushGuild } from './BushGuild';
import { BushUser } from './BushUser';
+interface BushPunishmentOptions {
+ reason?: string;
+ moderator: BushUserResolvable;
+ createModLogEntry?: boolean;
+}
+
+interface BushTimedPunishmentOptions extends BushPunishmentOptions {
+ duration?: number;
+}
+
+type PunishmentResponse = 'success';
+
+type WarnResponse = PunishmentResponse;
+
+type MuteResponse = PunishmentResponse | 'no mute role';
+
+type UnmuteResponse = PunishmentResponse;
+
+type KickResponse = PunishmentResponse;
+
+interface BushBanOptions extends BushTimedPunishmentOptions {
+ deleteDays?: number;
+ duration?: number;
+}
+
+type BanResponse = PunishmentResponse;
+
export class BushGuildMember extends GuildMember {
public declare readonly client: BushClient;
public declare guild: BushGuild;
- public declare BushUser: BushUser;
+ public declare user: BushUser;
public constructor(client: BushClient, data: unknown, guild: BushGuild) {
super(client, data, guild);
}
+
+ public async warn(options: BushPunishmentOptions): Promise<WarnResponse> {
+ throw 'not implemented';
+ }
+
+ public async mute(options: BushTimedPunishmentOptions): Promise<MuteResponse> {
+ throw 'not implemented';
+ }
+
+ public async unmute(options: BushPunishmentOptions): Promise<UnmuteResponse> {
+ throw 'not implemented';
+ }
+
+ public async bushKick(options: BushPunishmentOptions): Promise<KickResponse> {
+ throw 'not implemented';
+ }
+
+ public async bushBan(options?: BushBanOptions): Promise<BanResponse> {
+ throw 'not implemented';
+ }
+
+ public isOwner(): boolean {
+ return this.client.isOwner(this);
+ }
+
+ public isSuperUser(): boolean {
+ return this.client.isSuperUser(this);
+ }
}
diff --git a/src/lib/extensions/discord.js/BushGuildMemberManager.ts b/src/lib/extensions/discord.js/BushGuildMemberManager.ts
new file mode 100644
index 0000000..dbc2da5
--- /dev/null
+++ b/src/lib/extensions/discord.js/BushGuildMemberManager.ts
@@ -0,0 +1,11 @@
+// /* eslint-disable @typescript-eslint/no-explicit-any */
+// import { GuildMemberManager } from 'discord.js';
+// import { BushGuild } from './BushGuild';
+
+// export class BushGuildMemberManager extends GuildMemberManager {
+// public guild: BushGuild;
+
+// public constructor(guild: BushGuild, iterable?: Iterable<any>) {
+// super(guild, iterable);
+// }
+// }
diff --git a/src/lib/extensions/discord.js/BushMessageManager.ts b/src/lib/extensions/discord.js/BushMessageManager.ts
index efc6369..181808a 100644
--- a/src/lib/extensions/discord.js/BushMessageManager.ts
+++ b/src/lib/extensions/discord.js/BushMessageManager.ts
@@ -4,11 +4,12 @@ import { BushClient } from '../discord-akairo/BushClient';
import { BushDMChannel } from './BushDMChannel';
import { BushMessage } from './BushMessage';
import { BushTextChannel } from './BushTextChannel';
+import { BushThreadChannel } from './BushThreadChannel';
export class BushMessageManager extends MessageManager {
public declare readonly client: BushClient;
public declare cache: Collection<Snowflake, BushMessage>;
- public constructor(channel: BushTextChannel | BushDMChannel, iterable?: Iterable<any>) {
+ public constructor(channel: BushTextChannel | BushDMChannel | BushThreadChannel, iterable?: Iterable<any>) {
super(channel, iterable);
}
}
diff --git a/src/lib/extensions/discord.js/BushThreadMemberManager.ts b/src/lib/extensions/discord.js/BushThreadMemberManager.ts
index e375322..0c44f71 100644
--- a/src/lib/extensions/discord.js/BushThreadMemberManager.ts
+++ b/src/lib/extensions/discord.js/BushThreadMemberManager.ts
@@ -1,15 +1,8 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-empty-interface */
-import { Snowflake, ThreadMemberManager, UserResolvable } from 'discord.js';
+import { ThreadMemberManager } from 'discord.js';
import { BushClient } from '../discord-akairo/BushClient';
-import { BushGuildMember } from './BushGuildMember';
-import { BushMessage } from './BushMessage';
import { BushThreadChannel } from './BushThreadChannel';
-import { BushThreadMember } from './BushThreadMember';
-import { BushUser } from './BushUser';
-
-export type BushThreadMemberResolvable = BushThreadMember | UserResolvable;
-export type BushUserResolvable = BushUser | Snowflake | BushMessage | BushGuildMember | BushThreadMember;
export interface BushThreadMemberManager extends ThreadMemberManager {}
diff --git a/src/lib/extensions/global.d.ts b/src/lib/extensions/global.d.ts
new file mode 100644
index 0000000..6b5d129
--- /dev/null
+++ b/src/lib/extensions/global.d.ts
@@ -0,0 +1,9 @@
+import { BushClient } from './discord-akairo/BushClient';
+declare global {
+ declare namespace NodeJS {
+ export interface Global {
+ client: BushClient;
+ }
+ }
+ const client: BushClient;
+}
diff --git a/src/lib/models/ModLog.ts b/src/lib/models/ModLog.ts
index 94c464d..1d850d9 100644
--- a/src/lib/models/ModLog.ts
+++ b/src/lib/models/ModLog.ts
@@ -1,3 +1,4 @@
+import { Snowflake } from 'discord.js';
import { DataTypes, Sequelize } from 'sequelize';
import { v4 as uuidv4 } from 'uuid';
import { BaseModel } from './BaseModel';
@@ -16,31 +17,31 @@ export enum ModLogType {
export interface ModLogModel {
id: string;
type: ModLogType;
- user: string;
- moderator: string;
+ user: Snowflake;
+ moderator: Snowflake;
reason: string;
duration: number;
- guild: string;
+ guild: Snowflake;
}
export interface ModLogModelCreationAttributes {
id?: string;
type: ModLogType;
- user: string;
- moderator: string;
+ user: Snowflake;
+ moderator: Snowflake;
reason?: string;
duration?: number;
- guild: string;
+ guild: Snowflake;
}
export class ModLog extends BaseModel<ModLogModel, ModLogModelCreationAttributes> implements ModLogModel {
id: string;
type: ModLogType;
- user: string;
- moderator: string;
- guild: string;
+ user: Snowflake;
+ moderator: Snowflake;
reason: string | null;
duration: number | null;
+ guild: Snowflake;
static initModel(sequelize: Sequelize): void {
ModLog.init(