aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/extensions/discord-akairo/BushClientUtil.ts30
-rw-r--r--src/lib/extensions/discord-akairo/BushCommand.ts5
-rw-r--r--src/lib/extensions/discord.js/BushGuild.ts2
-rw-r--r--src/lib/models/Global.ts15
-rw-r--r--src/lib/models/Guild.ts48
-rw-r--r--src/lib/models/Level.ts19
-rw-r--r--src/lib/utils/BushConstants.ts6
7 files changed, 101 insertions, 24 deletions
diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts
index 6538ebf..6a08c54 100644
--- a/src/lib/extensions/discord-akairo/BushClientUtil.ts
+++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts
@@ -45,6 +45,9 @@ import got from 'got';
import humanizeDuration from 'humanize-duration';
import { Op } from 'sequelize';
import { promisify } from 'util';
+import { BushNewsChannel } from '../discord.js/BushNewsChannel';
+import { BushTextChannel } from '../discord.js/BushTextChannel';
+import { BushUserResolvable } from './BushClient';
interface hastebinRes {
key: string;
@@ -322,7 +325,7 @@ export class BushClientUtil extends ClientUtil {
let curPage = 0;
if (typeof embeds !== 'object') throw 'embeds must be an object';
const msg: Message = await message.util.reply({
- content: text,
+ content: text || null,
embeds: [embeds[curPage]],
components: [getPaginationRow()]
});
@@ -527,16 +530,22 @@ export class BushClientUtil extends ClientUtil {
const environment = this.client.config.dev ? 'development' : 'production';
const row = await Global.findByPk(environment);
const oldValue: any[] = row[key];
+ const newValue = this.addOrRemoveFromArray(action, oldValue, value);
+ row[key] = newValue;
+ this.client.cache.global[key] = newValue;
+ return await row.save().catch((e) => this.client.logger.error('insertOrRemoveFromGlobal', e?.stack || e));
+ }
+
+ public addOrRemoveFromArray(action: 'add' | 'remove', array: any[], value: any): any[] {
let newValue: any[];
+ if (!array) return null;
if (action === 'add') {
- if (!oldValue.includes(action)) oldValue.push(value);
- newValue = oldValue;
+ if (!array.includes(action)) array.push(value);
+ newValue = array;
} else {
- newValue = oldValue.filter((ae) => ae !== value);
+ newValue = array.filter((ae) => ae !== value);
}
- row[key] = newValue;
- this.client.cache.global[key] = newValue;
- return await row.save().catch((e) => this.client.logger.error('insertOrRemoveFromGlobal', e?.stack || e));
+ return newValue;
}
/**
@@ -587,11 +596,13 @@ export class BushClientUtil extends ClientUtil {
moderator: BushGuildMember,
victim: BushGuildMember,
type: 'mute' | 'unmute' | 'warn' | 'kick' | 'ban' | 'unban' | 'add a punishment role to' | 'remove a punishment role from',
- checkModerator = true
+ checkModerator = true,
+ force = false
): true | string {
if (moderator.guild.id !== victim.guild.id) {
throw 'moderator and victim not in same guild';
}
+ if (force) return true;
const isOwner = moderator.guild.ownerId === moderator.id;
if (moderator.id === victim.id) {
return `${this.client.util.emojis.error} You cannot ${type} yourself.`;
@@ -708,7 +719,6 @@ 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: {
@@ -768,4 +778,6 @@ export class BushClientUtil extends ClientUtil {
return arrByte[1] + ', ' + arrByte[2] + ', ' + arrByte[3];
}
+
+ public async lockdownChannel(options: { channel: BushTextChannel | BushNewsChannel; moderator: BushUserResolvable }) {}
}
diff --git a/src/lib/extensions/discord-akairo/BushCommand.ts b/src/lib/extensions/discord-akairo/BushCommand.ts
index 90c68df..6cf981b 100644
--- a/src/lib/extensions/discord-akairo/BushCommand.ts
+++ b/src/lib/extensions/discord-akairo/BushCommand.ts
@@ -86,6 +86,7 @@ export interface BushCommandOptions extends CommandOptions {
};
args?: BushArgumentOptions[] | ArgumentGenerator;
category: string;
+ completelyHide?: boolean;
}
export class BushCommand extends Command {
@@ -104,12 +105,16 @@ export class BushCommand extends Command {
/** Whether the command is hidden from the help command. */
public hidden: boolean;
+ /** Completely hide this command from the help command. */
+ public completelyHide: boolean;
+
public constructor(id: string, options?: BushCommandOptions) {
super(id, options);
this.options = options;
this.hidden = options.hidden || false;
this.restrictedChannels = options.restrictedChannels;
this.restrictedGuilds = options.restrictedGuilds;
+ this.completelyHide = options.completelyHide;
}
public exec(message: BushMessage, args: any): any;
diff --git a/src/lib/extensions/discord.js/BushGuild.ts b/src/lib/extensions/discord.js/BushGuild.ts
index 6eca44d..f695f8b 100644
--- a/src/lib/extensions/discord.js/BushGuild.ts
+++ b/src/lib/extensions/discord.js/BushGuild.ts
@@ -12,7 +12,7 @@ export class BushGuild extends Guild {
}
public async getSetting<K extends keyof GuildModel>(setting: K): Promise<GuildModel[K]> {
- return ((await GuildDB.findByPk(this.id)) ?? GuildDB.build({ id: this.id })).get(setting);
+ return ((await GuildDB.findByPk(this.id)) ?? GuildDB.build({ id: this.id }))[setting];
}
public async setSetting<K extends keyof GuildModel>(setting: K, value: GuildDB[K]): Promise<GuildDB> {
diff --git a/src/lib/models/Global.ts b/src/lib/models/Global.ts
index ba77302..8664365 100644
--- a/src/lib/models/Global.ts
+++ b/src/lib/models/Global.ts
@@ -60,7 +60,8 @@ export class Global extends BaseModel<GlobalModel, GlobalModelCreationAttributes
set: function (val: Snowflake[]) {
return this.setDataValue('superUsers', JSON.stringify(val) as unknown as Snowflake[]);
},
- allowNull: true
+ allowNull: false,
+ defaultValue: '[]'
},
disabledCommands: {
type: DataTypes.STRING,
@@ -70,7 +71,8 @@ export class Global extends BaseModel<GlobalModel, GlobalModelCreationAttributes
set: function (val: Snowflake[]) {
return this.setDataValue('disabledCommands', JSON.stringify(val) as unknown as string[]);
},
- allowNull: true
+ allowNull: false,
+ defaultValue: '[]'
},
blacklistedUsers: {
type: DataTypes.STRING,
@@ -80,7 +82,8 @@ export class Global extends BaseModel<GlobalModel, GlobalModelCreationAttributes
set: function (val: Snowflake[]) {
return this.setDataValue('blacklistedUsers', JSON.stringify(val) as unknown as Snowflake[]);
},
- allowNull: true
+ allowNull: false,
+ defaultValue: '[]'
},
blacklistedGuilds: {
type: DataTypes.STRING,
@@ -90,7 +93,8 @@ export class Global extends BaseModel<GlobalModel, GlobalModelCreationAttributes
set: function (val: Snowflake[]) {
return this.setDataValue('blacklistedGuilds', JSON.stringify(val) as unknown as Snowflake[]);
},
- allowNull: true
+ allowNull: false,
+ defaultValue: '[]'
},
blacklistedChannels: {
type: DataTypes.STRING,
@@ -100,7 +104,8 @@ export class Global extends BaseModel<GlobalModel, GlobalModelCreationAttributes
set: function (val: Snowflake[]) {
return this.setDataValue('blacklistedChannels', JSON.stringify(val) as unknown as Snowflake[]);
},
- allowNull: true
+ allowNull: false,
+ defaultValue: '[]'
}
},
{ sequelize: sequelize }
diff --git a/src/lib/models/Guild.ts b/src/lib/models/Guild.ts
index 43fcd64..30072b3 100644
--- a/src/lib/models/Guild.ts
+++ b/src/lib/models/Guild.ts
@@ -8,9 +8,12 @@ export interface GuildModel {
prefix: string;
autoPublishChannels: Snowflake[];
blacklistedChannels: Snowflake[];
+ blacklistedUsers: Snowflake[];
welcomeChannel: Snowflake;
muteRole: Snowflake;
punishmentEnding: string;
+ disabledCommands: string[];
+ lockdownChannels: Snowflake[];
}
export interface GuildModelCreationAttributes {
@@ -18,9 +21,12 @@ export interface GuildModelCreationAttributes {
prefix?: string;
autoPublishChannels?: Snowflake[];
blacklistedChannels?: Snowflake[];
+ blacklistedUsers?: Snowflake[];
welcomeChannel?: Snowflake;
muteRole?: Snowflake;
punishmentEnding?: string;
+ disabledCommands?: string[];
+ lockdownChannels?: Snowflake[];
}
export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> implements GuildModel {
@@ -28,9 +34,12 @@ export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> i
prefix!: string;
autoPublishChannels: Snowflake[];
blacklistedChannels: Snowflake[];
+ blacklistedUsers: Snowflake[];
welcomeChannel: Snowflake;
muteRole: Snowflake;
punishmentEnding: string;
+ disabledCommands: string[];
+ lockdownChannels: Snowflake[];
static initModel(sequelize: Sequelize, client: BushClient): void {
Guild.init(
@@ -52,7 +61,8 @@ export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> i
set: function (val: Snowflake[]) {
return this.setDataValue('autoPublishChannels', JSON.stringify(val) as unknown as Snowflake[]);
},
- allowNull: true
+ allowNull: false,
+ defaultValue: '[]'
},
blacklistedChannels: {
type: DataTypes.STRING,
@@ -62,7 +72,19 @@ export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> i
set: function (val: Snowflake[]) {
return this.setDataValue('blacklistedChannels', JSON.stringify(val) as unknown as Snowflake[]);
},
- allowNull: true
+ allowNull: false,
+ defaultValue: '[]'
+ },
+ blacklistedUsers: {
+ type: DataTypes.STRING,
+ get: function () {
+ return JSON.parse(this.getDataValue('blacklistedUsers') as unknown as string);
+ },
+ set: function (val: Snowflake[]) {
+ return this.setDataValue('blacklistedUsers', JSON.stringify(val) as unknown as Snowflake[]);
+ },
+ allowNull: false,
+ defaultValue: '[]'
},
welcomeChannel: {
type: DataTypes.STRING,
@@ -75,6 +97,28 @@ export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> i
punishmentEnding: {
type: DataTypes.TEXT,
allowNull: true
+ },
+ disabledCommands: {
+ type: DataTypes.STRING,
+ get: function () {
+ return JSON.parse(this.getDataValue('disabledCommands') as unknown as string);
+ },
+ set: function (val: string[]) {
+ return this.setDataValue('disabledCommands', JSON.stringify(val) as unknown as string[]);
+ },
+ allowNull: false,
+ defaultValue: '[]'
+ },
+ lockdownChannels: {
+ type: DataTypes.STRING,
+ get: function () {
+ return JSON.parse(this.getDataValue('lockdownChannels') as unknown as string);
+ },
+ set: function (val: Snowflake[]) {
+ return this.setDataValue('lockdownChannels', JSON.stringify(val) as unknown as Snowflake[]);
+ },
+ allowNull: false,
+ defaultValue: '[]'
}
},
{ sequelize: sequelize }
diff --git a/src/lib/models/Level.ts b/src/lib/models/Level.ts
index b834992..755b1c6 100644
--- a/src/lib/models/Level.ts
+++ b/src/lib/models/Level.ts
@@ -3,12 +3,14 @@ import { DataTypes, Sequelize } from 'sequelize';
import { BaseModel } from './BaseModel';
export interface LevelModel {
- id: Snowflake;
+ user: Snowflake;
+ guild: Snowflake;
xp: number;
}
export interface LevelModelCreationAttributes {
- id: Snowflake;
+ user: Snowflake;
+ guild: Snowflake;
xp?: number;
}
@@ -16,7 +18,11 @@ export class Level extends BaseModel<LevelModel, LevelModelCreationAttributes> {
/**
* The user's id.
*/
- public id: Snowflake;
+ public user: Snowflake;
+ /**
+ * The guild where the user is gaining xp.
+ */
+ public guild: Snowflake;
/**
* The user's xp.
*/
@@ -28,9 +34,12 @@ export class Level extends BaseModel<LevelModel, LevelModelCreationAttributes> {
static initModel(sequelize: Sequelize): void {
Level.init(
{
- id: {
+ user: {
+ type: DataTypes.STRING,
+ allowNull: false
+ },
+ guild: {
type: DataTypes.STRING,
- primaryKey: true,
allowNull: false
},
xp: {
diff --git a/src/lib/utils/BushConstants.ts b/src/lib/utils/BushConstants.ts
index 747c6d6..3ca2e8c 100644
--- a/src/lib/utils/BushConstants.ts
+++ b/src/lib/utils/BushConstants.ts
@@ -351,9 +351,11 @@ export class BushConstants {
DISABLED_GUILD: 'disabledGuild',
DISABLED_GLOBAL: 'disabledGlobal',
ROLE_BLACKLIST: 'roleBlacklist',
- USER_BLACKLIST: 'userBlacklist',
+ USER_GUILD_BLACKLIST: 'userGuildBlacklist',
+ USER_GLOBAL_BLACKLIST: 'userGlobalBlacklist',
RESTRICTED_GUILD: 'restrictedGuild',
- CHANNEL_BLACKLIST: 'channelBlacklist',
+ CHANNEL_GUILD_BLACKLIST: 'channelGuildBlacklist',
+ CHANNEL_GLOBAL_BLACKLIST: 'channelGlobalBlacklist',
RESTRICTED_CHANNEL: 'restrictedChannel'
};