aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-07-04 16:26:56 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-07-04 16:26:56 -0400
commit153a40fbcd314459f94d9a2b44d3466c930c4e35 (patch)
tree5c853355da693e68c393b38c0c66a1f84ef0ac89 /src/lib
parentcf564dbb6435886f97e2e9870363144386af368d (diff)
downloadtanzanite-153a40fbcd314459f94d9a2b44d3466c930c4e35.tar.gz
tanzanite-153a40fbcd314459f94d9a2b44d3466c930c4e35.tar.bz2
tanzanite-153a40fbcd314459f94d9a2b44d3466c930c4e35.zip
cleaned up
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/extensions/discord-akairo/BushArgumentOptions.ts59
-rw-r--r--src/lib/extensions/discord-akairo/BushClient.ts57
-rw-r--r--src/lib/extensions/discord-akairo/BushClientUtil.ts29
-rw-r--r--src/lib/extensions/discord-akairo/BushCommand.ts64
-rw-r--r--src/lib/extensions/discord-akairo/BushInhibitorHandler.ts (renamed from src/lib/extensions/discord-akairo/BushInhinitorHandler.ts)0
-rw-r--r--src/lib/extensions/discord-akairo/index.ts13
-rw-r--r--src/lib/extensions/discord.js/BushGuildMember.ts12
-rw-r--r--src/lib/extensions/discord.js/index.ts35
-rw-r--r--src/lib/extensions/index.ts3
-rw-r--r--src/lib/index.ts3
-rw-r--r--src/lib/utils/BushLogger.ts2
-rw-r--r--src/lib/utils/index.ts5
12 files changed, 168 insertions, 114 deletions
diff --git a/src/lib/extensions/discord-akairo/BushArgumentOptions.ts b/src/lib/extensions/discord-akairo/BushArgumentOptions.ts
deleted file mode 100644
index bbbc04b..0000000
--- a/src/lib/extensions/discord-akairo/BushArgumentOptions.ts
+++ /dev/null
@@ -1,59 +0,0 @@
-import { ArgumentOptions, ArgumentTypeCaster } from 'discord-akairo';
-
-type BushArgumentType =
- | 'string'
- | 'lowercase'
- | 'uppercase'
- | 'charCodes'
- | 'number'
- | 'integer'
- | 'bigint'
- | 'emojint'
- | 'url'
- | 'date'
- | 'color'
- | 'user'
- | 'users'
- | 'member'
- | 'members'
- | 'relevant'
- | 'relevants'
- | 'channel'
- | 'channels'
- | 'textChannel'
- | 'textChannels'
- | 'voiceChannel'
- | 'voiceChannels'
- | 'categoryChannel'
- | 'categoryChannels'
- | 'newsChannel'
- | 'newsChannels'
- | 'storeChannel'
- | 'storeChannels'
- | 'role'
- | 'roles'
- | 'emoji'
- | 'emojis'
- | 'guild'
- | 'guilds'
- | 'message'
- | 'guildMessage'
- | 'relevantMessage'
- | 'invite'
- | 'userMention'
- | 'memberMention'
- | 'channelMention'
- | 'roleMention'
- | 'emojiMention'
- | 'commandAlias'
- | 'command'
- | 'inhibitor'
- | 'listener'
- | 'duration'
- | (string | string[])[]
- | RegExp
- | string;
-
-export interface BushArgumentOptions extends ArgumentOptions {
- type?: BushArgumentType | ArgumentTypeCaster;
-}
diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts
index ed5c90a..b7441bf 100644
--- a/src/lib/extensions/discord-akairo/BushClient.ts
+++ b/src/lib/extensions/discord-akairo/BushClient.ts
@@ -15,6 +15,29 @@ import * as path from 'path';
import { exit } from 'process';
import readline from 'readline';
import { Sequelize } from 'sequelize';
+import { BushClientUtil, BushCommandHandler, BushInhibitorHandler, BushListenerHandler, BushTaskHandler } from '.';
+import {
+ BushButtonInteraction,
+ BushCategoryChannel,
+ BushCommandInteraction,
+ BushDMChannel,
+ BushGuild,
+ BushGuildEmoji,
+ BushGuildMember,
+ BushMessage,
+ BushMessageReaction,
+ BushNewsChannel,
+ BushPresence,
+ BushRole,
+ BushSelectMenuInteraction,
+ BushStoreChannel,
+ BushTextChannel,
+ BushThreadChannel,
+ BushThreadMember,
+ BushUser,
+ BushVoiceChannel,
+ BushVoiceState
+} from '../';
import { contentWithDurationTypeCaster } from '../../../arguments/contentWithDuration';
import { durationTypeCaster } from '../../../arguments/duration';
import * as config from '../../../config/options';
@@ -24,31 +47,6 @@ import AllowedMentions from '../../utils/AllowedMentions';
import { BushCache } from '../../utils/BushCache';
import { BushConstants } from '../../utils/BushConstants';
import { BushLogger } from '../../utils/BushLogger';
-import { BushButtonInteraction } from '../discord.js/BushButtonInteraction';
-import { BushCategoryChannel } from '../discord.js/BushCategoryChannel';
-import { BushCommandInteraction } from '../discord.js/BushCommandInteraction';
-import { BushDMChannel } from '../discord.js/BushDMChannel';
-import { BushGuild } from '../discord.js/BushGuild';
-import { BushGuildEmoji } from '../discord.js/BushGuildEmoji';
-import { BushGuildMember } from '../discord.js/BushGuildMember';
-import { BushMessage } from '../discord.js/BushMessage';
-import { BushMessageReaction } from '../discord.js/BushMessageReaction';
-import { BushNewsChannel } from '../discord.js/BushNewsChannel';
-import { BushPresence } from '../discord.js/BushPresence';
-import { BushRole } from '../discord.js/BushRole';
-import { BushSelectMenuInteraction } from '../discord.js/BushSelectMenuInteraction';
-import { BushStoreChannel } from '../discord.js/BushStoreChannel';
-import { BushTextChannel } from '../discord.js/BushTextChannel';
-import { BushThreadChannel } from '../discord.js/BushThreadChannel';
-import { BushThreadMember } from '../discord.js/BushThreadMember';
-import { BushUser } from '../discord.js/BushUser';
-import { BushVoiceChannel } from '../discord.js/BushVoiceChannel';
-import { BushVoiceState } from '../discord.js/BushVoiceState';
-import { BushClientUtil } from './BushClientUtil';
-import { BushCommandHandler } from './BushCommandHandler';
-import { BushInhibitorHandler } from './BushInhinitorHandler';
-import { BushListenerHandler } from './BushListenerHandler';
-import { BushTaskHandler } from './BushTaskHandler';
export type BotConfig = typeof config;
export type BushReplyMessageType = string | MessagePayload | ReplyMessageOptions;
@@ -57,6 +55,7 @@ export type BushSendMessageType = string | MessagePayload | MessageOptions;
export type BushThreadMemberResolvable = BushThreadMember | BushUserResolvable;
export type BushUserResolvable = BushUser | Snowflake | BushMessage | BushGuildMember | BushThreadMember;
export type BushGuildMemberResolvable = BushGuildMember | BushUserResolvable;
+export type BushRoleResolvable = BushRole | Snowflake;
const rl = readline.createInterface({
input: process.stdin,
@@ -216,11 +215,7 @@ export class BushClient extends AkairoClient {
loaders[loader].loadAll();
await this.logger.success('Startup', `Successfully loaded <<${loader}>>.`, false);
} catch (e) {
- await this.logger.error(
- 'Startup',
- `Unable to load loader <<${loader}>> with error:\n${typeof e === 'object' ? e?.stack : e}`,
- false
- );
+ await this.logger.error('Startup', `Unable to load loader <<${loader}>> with error:\n${e?.stack || e}`, false);
}
}
await this.dbPreInit();
@@ -258,7 +253,7 @@ export class BushClient extends AkairoClient {
await this._init();
await this.login(this.token);
} catch (e) {
- await this.console.error('Start', chalk.red(e.stack), false);
+ await this.console.error('Start', chalk.red(e?.stack || e), false);
exit(2);
}
}
diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts
index 5a22efc..126ed90 100644
--- a/src/lib/extensions/discord-akairo/BushClientUtil.ts
+++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts
@@ -153,7 +153,7 @@ export class BushClientUtil extends ClientUtil {
try {
const res: hastebinRes = await got.post(`${url}/documents`, { body: content }).json();
return `${url}/${res.key}`;
- } catch (e) {
+ } catch {
this.client.console.error('Haste', `Unable to upload haste to ${url}`);
}
}
@@ -512,7 +512,7 @@ export class BushClientUtil extends ClientUtil {
}
row[key] = newValue;
this.client.cache.global[key] = newValue;
- return await row.save().catch((e) => this.client.logger.error('insertOrRemoveFromGlobal', e));
+ return await row.save().catch((e) => this.client.logger.error('insertOrRemoveFromGlobal', e?.stack || e));
}
/**
@@ -543,25 +543,12 @@ export class BushClientUtil extends ClientUtil {
const regex = BushConstants.TimeUnits[unit].match;
const match = regex.exec(contentWithoutTime);
const value = Number(match?.groups?.[unit] || 0);
- // this.client.console.debug(unit + ': ' + value);
duration += value * BushConstants.TimeUnits[unit].value;
if (remove) contentWithoutTime = contentWithoutTime.replace(regex, '');
- // this.client.console.debug(contentWithoutTime);
}
- //^(?:(?<years>-?(?:\d+)?\.?\d+) *(?:years?|y))?\s*(?:(?<months>-?(?:\d+)?\.?\d+) *(?:months?|mon|mo?))?\s*(?:(?<weeks>-?(?:\d+)?\.?\d+) *(?:weeks?|w))?\s*(?:(?<days>-?(?:\d+)?\.?\d+) *(?:days?|d))?\s*(?:(?<hours>-?(?:\d+)?\.?\d+) *(?:hours?|hrs?|h))?\s*(?:(?<minutes>-?(?:\d+)?\\.?\\d+) *(?:minutes?|mins?))?\s*(?:(?<seconds>-?(?:\d+)?\\.?\d+) *(?:seconds?|secs?|s))?\s*(?:(?<milliseconds>-?(?:\d+)?\.?\d+) *(?:milliseconds?|msecs?|ms))?$
- // const regexString = Object.entries(BushConstants.TimeUnits)
- // .map(([name, { label }]) => String.raw`(?: (?<${name}>-?(?:\d+)?\.?\d+) *${label})`)
- // .join(' |');
- // const match = new RegExp(`^${regexString}$`, 'img').exec(' ' + content + ' ');
- // if (!match) return null;
- // console.
- // const contentWithoutTime = content.replace(new RegExp(`^${regexString}$`, 'img'), '');
- // for (const key in match.groups) {
- // const value = Number(match.groups[key] || 0);
- // duration += value * BushConstants.TimeUnits[key].value;
- // }
-
+ // remove the space added earlier
+ if (contentWithoutTime.startsWith(' ')) contentWithoutTime.replace(' ', '');
return { duration, contentWithoutTime };
}
@@ -616,8 +603,8 @@ export class BushClientUtil extends ClientUtil {
duration: duration,
guild
});
- return modLogEntry.save().catch((err) => {
- this.client.console.error('createModLogEntry', err);
+ return modLogEntry.save().catch((e) => {
+ this.client.console.error('createModLogEntry', e?.stack || e);
return null;
});
}
@@ -649,8 +636,8 @@ export class BushClientUtil extends ClientUtil {
const guild = this.client.guilds.resolveID(options.guild);
const entry = dbModel.build({ user, guild, expires, modlog: options.modlog });
- return await entry.save().catch((err) => {
- this.client.console.error('createPunishmentEntry', err);
+ return await entry.save().catch((e) => {
+ this.client.console.error('createPunishmentEntry', e?.stack || e);
return null;
});
}
diff --git a/src/lib/extensions/discord-akairo/BushCommand.ts b/src/lib/extensions/discord-akairo/BushCommand.ts
index 101c9d3..90c68df 100644
--- a/src/lib/extensions/discord-akairo/BushCommand.ts
+++ b/src/lib/extensions/discord-akairo/BushCommand.ts
@@ -1,13 +1,75 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/* eslint-disable @typescript-eslint/no-explicit-any */
-import { ArgumentGenerator, ArgumentOptions, ArgumentPromptOptions, Command, CommandOptions } from 'discord-akairo';
+import {
+ ArgumentGenerator,
+ ArgumentOptions,
+ ArgumentPromptOptions,
+ ArgumentTypeCaster,
+ Command,
+ CommandOptions
+} from 'discord-akairo';
import { Snowflake } from 'discord.js';
import { BushMessage } from '../discord.js/BushMessage';
import { BushClient } from './BushClient';
import { BushCommandHandler } from './BushCommandHandler';
import { BushSlashMessage } from './BushSlashMessage';
+type BushArgumentType =
+ | 'string'
+ | 'lowercase'
+ | 'uppercase'
+ | 'charCodes'
+ | 'number'
+ | 'integer'
+ | 'bigint'
+ | 'emojint'
+ | 'url'
+ | 'date'
+ | 'color'
+ | 'user'
+ | 'users'
+ | 'member'
+ | 'members'
+ | 'relevant'
+ | 'relevants'
+ | 'channel'
+ | 'channels'
+ | 'textChannel'
+ | 'textChannels'
+ | 'voiceChannel'
+ | 'voiceChannels'
+ | 'categoryChannel'
+ | 'categoryChannels'
+ | 'newsChannel'
+ | 'newsChannels'
+ | 'storeChannel'
+ | 'storeChannels'
+ | 'role'
+ | 'roles'
+ | 'emoji'
+ | 'emojis'
+ | 'guild'
+ | 'guilds'
+ | 'message'
+ | 'guildMessage'
+ | 'relevantMessage'
+ | 'invite'
+ | 'userMention'
+ | 'memberMention'
+ | 'channelMention'
+ | 'roleMention'
+ | 'emojiMention'
+ | 'commandAlias'
+ | 'command'
+ | 'inhibitor'
+ | 'listener'
+ | 'duration'
+ | (string | string[])[]
+ | RegExp
+ | string;
+
export interface BushArgumentOptions extends ArgumentOptions {
+ type?: BushArgumentType | ArgumentTypeCaster;
id: string;
description?: string;
prompt?: ArgumentPromptOptions;
diff --git a/src/lib/extensions/discord-akairo/BushInhinitorHandler.ts b/src/lib/extensions/discord-akairo/BushInhibitorHandler.ts
index 2a947da..2a947da 100644
--- a/src/lib/extensions/discord-akairo/BushInhinitorHandler.ts
+++ b/src/lib/extensions/discord-akairo/BushInhibitorHandler.ts
diff --git a/src/lib/extensions/discord-akairo/index.ts b/src/lib/extensions/discord-akairo/index.ts
new file mode 100644
index 0000000..fd92de2
--- /dev/null
+++ b/src/lib/extensions/discord-akairo/index.ts
@@ -0,0 +1,13 @@
+export * from './BushArgumentTypeCaster';
+export * from './BushClient';
+export * from './BushClientUtil';
+export * from './BushCommand';
+export * from './BushCommandHandler';
+export * from './BushCommandUtil';
+export * from './BushInhibitor';
+export * from './BushInhibitorHandler';
+export * from './BushListener';
+export * from './BushListenerHandler';
+export * from './BushSlashMessage';
+export * from './BushTask';
+export * from './BushTaskHandler';
diff --git a/src/lib/extensions/discord.js/BushGuildMember.ts b/src/lib/extensions/discord.js/BushGuildMember.ts
index 2fefcdd..7a63012 100644
--- a/src/lib/extensions/discord.js/BushGuildMember.ts
+++ b/src/lib/extensions/discord.js/BushGuildMember.ts
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
-import { GuildMember } from 'discord.js';
+import { GuildMember, RoleResolvable } from 'discord.js';
import { ModLogType } from '../../models';
import { BushClient, BushUserResolvable } from '../discord-akairo/BushClient';
import { BushGuild } from './BushGuild';
@@ -14,10 +14,16 @@ interface BushTimedPunishmentOptions extends BushPunishmentOptions {
duration?: number;
}
+interface BushPunishmentRoleOptions extends BushTimedPunishmentOptions {
+ role: RoleResolvable;
+}
+
type PunishmentResponse = 'success';
type WarnResponse = PunishmentResponse;
+type PunishmentRoleResponse = PunishmentResponse;
+
type MuteResponse =
| PunishmentResponse
| 'missing permissions'
@@ -52,6 +58,10 @@ export class BushGuildMember extends GuildMember {
throw 'not implemented';
}
+ public punishRole(options: BushPunishmentRoleOptions): Promise<PunishmentRoleResponse> {
+ throw 'not implemented';
+ }
+
public async mute(options: BushTimedPunishmentOptions): Promise<MuteResponse> {
//checks
if (!this.guild.me.permissions.has('MANAGE_ROLES')) return 'missing permissions';
diff --git a/src/lib/extensions/discord.js/index.ts b/src/lib/extensions/discord.js/index.ts
new file mode 100644
index 0000000..766500d
--- /dev/null
+++ b/src/lib/extensions/discord.js/index.ts
@@ -0,0 +1,35 @@
+export * from './BushActivity';
+export * from './BushApplicationCommand';
+export * from './BushApplicationCommandManager';
+export * from './BushApplicationCommandPermissionsManager';
+export * from './BushButtonInteraction';
+export * from './BushCategoryChannel';
+export * from './BushCommandInteraction';
+export * from './BushDMChannel';
+export * from './BushEmoji';
+export * from './BushGuild';
+export * from './BushGuildApplicationCommandManager';
+export * from './BushGuildChannel';
+export * from './BushGuildEmoji';
+export * from './BushGuildEmojiRoleManager';
+export * from './BushGuildMember';
+// export * from './BushGuildMemberManager';
+export * from './BushMessage';
+export * from './BushMessageManager';
+export * from './BushMessageReaction';
+export * from './BushNewsChannel';
+export * from './BushPresence';
+export * from './BushReactionEmoji';
+export * from './BushRole';
+export * from './BushSelectMenuInteraction';
+export * from './BushStageChannel';
+export * from './BushStageInstance';
+export * from './BushStoreChannel';
+export * from './BushTextChannel';
+export * from './BushThreadChannel';
+export * from './BushThreadManager';
+export * from './BushThreadMember';
+export * from './BushThreadMemberManager';
+export * from './BushUser';
+export * from './BushVoiceChannel';
+export * from './BushVoiceState';
diff --git a/src/lib/extensions/index.ts b/src/lib/extensions/index.ts
new file mode 100644
index 0000000..318adcc
--- /dev/null
+++ b/src/lib/extensions/index.ts
@@ -0,0 +1,3 @@
+export * from './discord-akairo/index';
+export * from './discord.js/index';
+export * from './global';
diff --git a/src/lib/index.ts b/src/lib/index.ts
new file mode 100644
index 0000000..6a1433c
--- /dev/null
+++ b/src/lib/index.ts
@@ -0,0 +1,3 @@
+export * from './extensions';
+export * from './models';
+export * from './utils';
diff --git a/src/lib/utils/BushLogger.ts b/src/lib/utils/BushLogger.ts
index 915d8f1..184b100 100644
--- a/src/lib/utils/BushLogger.ts
+++ b/src/lib/utils/BushLogger.ts
@@ -3,7 +3,7 @@
import chalk from 'chalk';
import { MessageEmbed } from 'discord.js';
import { inspect } from 'util';
-import { BushClient, BushSendMessageType } from '../extensions/discord-akairo/BushClient';
+import { BushClient, BushSendMessageType } from '..';
export class BushLogger {
private client: BushClient;
diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts
new file mode 100644
index 0000000..b0319e5
--- /dev/null
+++ b/src/lib/utils/index.ts
@@ -0,0 +1,5 @@
+export * from './AllowedMentions';
+export * from './BushCache';
+export * from './BushConstants';
+export * from './BushLogger';
+export * from './CanvasProgressBar';