Skip to content

Commit 5f1bb58

Browse files
committed
Send out expired reminders (for when the bot was down), count guild scheduled events, fix obscure bugs
- Fixed a bug with disabling commands for roles/channels/users - Fixed a bug where time would default to AM instead of PM in reminders - Fix emojis not working properly in image commands
1 parent 08f01a7 commit 5f1bb58

File tree

14 files changed

+905
-808
lines changed

14 files changed

+905
-808
lines changed

package-lock.json

Lines changed: 745 additions & 746 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api/raw.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,6 +1876,7 @@ export async function putInfoDiscord(
18761876
emojis: x.emojis,
18771877
events: x.events,
18781878
guilds: x.guilds,
1879+
guild_scheduled_events: x.guildScheduledEvents,
18791880
members: x.members,
18801881
member_count: x.memberCount,
18811882
messages: x.messages,
@@ -1927,6 +1928,7 @@ export async function putUser(
19271928
const body = {
19281929
avatar: options.avatar,
19291930
bot: options.bot,
1931+
blocked: options.blocked,
19301932
channel_id: options.channelId,
19311933
discriminator: options.discriminator,
19321934
locale: options.locale,

src/api/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ export namespace RestOptions {
309309
emojis?: number,
310310
events?: number,
311311
guilds?: number,
312+
guildScheduledEvents?: number,
312313
members?: number,
313314
memberCount?: number,
314315
messages?: number,
@@ -332,6 +333,7 @@ export namespace RestOptions {
332333
export interface PutUser {
333334
avatar: null | string,
334335
bot: boolean,
336+
blocked?: boolean,
335337
channelId?: null | string,
336338
discriminator: string,
337339
locale?: null | string,

src/commandclient.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Command, CommandClient } from 'detritus-client';
22

3+
import { CommandMetadata } from './commands/prefixed/basecommand';
4+
35
import { GuildAllowlistTypes, GuildBlocklistTypes, GuildDisableCommandsTypes } from './constants';
46
import GuildSettingsStore from './stores/guildsettings';
57
import UserStore from './stores/users';
@@ -30,10 +32,15 @@ export class NotSoCommandClient extends CommandClient {
3032
return true;
3133
}
3234

35+
const metadata = command.metadata as CommandMetadata;
36+
const commandId = metadata.id || command.name.split(' ').join('.');
37+
3338
const channel = context.channel;
3439
const parent = (channel) ? channel.parent : null;
3540
if (settings) {
36-
const disabledCommands = settings.disabledCommands.filter((disabled) => disabled.command === command.name);
41+
const disabledCommands = settings.disabledCommands.filter((disabled) => {
42+
return disabled.command === commandId;
43+
});
3744
if (disabledCommands.length) {
3845
const shouldIgnore = disabledCommands.some((disabled) => {
3946
switch (disabled.type) {

src/commands/interactions/basecommand.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,31 @@ export class BaseInteractionCommand<ParsedArgsFinished = Interaction.ParsedArgs>
256256
}
257257
}
258258
}
259+
260+
onValueError(context: Interaction.InteractionContext, args: ParsedArgsFinished, errors: Interaction.ParsedErrors) {
261+
const embed = new Embed();
262+
embed.setColor(EmbedColors.ERROR);
263+
embed.setTitle(`⚠ ${this.error} Argument Error`);
264+
265+
const store: {[key: string]: string} = {};
266+
267+
const description: Array<string> = ['Invalid Arguments' + '\n'];
268+
for (let key in errors) {
269+
const message = errors[key].message;
270+
if (message in store) {
271+
description.push(`**${key}**: Same error as **${store[message]}**`);
272+
} else {
273+
description.push(`**${key}**: ${message}`);
274+
}
275+
store[message] = key;
276+
}
277+
278+
embed.setDescription(description.join('\n'));
279+
return editOrReply(context, {
280+
embed,
281+
flags: MessageFlags.EPHEMERAL,
282+
});
283+
}
259284
}
260285

261286

src/commands/prefixed/moderation/commands.disable.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { createGuildDisabledCommand, editGuildSettings } from '../../../api';
66
import { GuildSettings } from '../../../api/structures/guildsettings';
77
import { CommandCategories, GuildDisableCommandsTypes } from '../../../constants';
88
import GuildSettingsStore from '../../../stores/guildsettings';
9-
import { Parameters } from '../../../utils';
9+
import { Parameters, editOrReply } from '../../../utils';
1010

1111
import { BaseCommand } from '../basecommand';
1212

@@ -90,15 +90,15 @@ export default class CommandsDisable extends BaseCommand {
9090
if (args.users && !args.users.length) {
9191
errors.push('users');
9292
}
93-
return context.editOrReply(`⚠ Unable to find the provided ${errors.join(', ')}.`);
93+
return editOrReply(context, `⚠ Unable to find the provided ${errors.join(', ')}.`);
9494
}
95-
return context.editOrReply('⚠ Unknown Command');
95+
return editOrReply(context, '⚠ Unknown Command');
9696
}
9797

9898
async run(context: Command.Context, args: CommandArgs) {
9999
const { command } = args;
100100
const commandId = (command.metadata && command.metadata.id) ? command.metadata.id : command.name.split(' ').join('.');
101-
const guildId = context.guildId as string;
101+
const guildId = context.guildId!;
102102

103103
const isServerWide = !args.channels && !args.roles && !args.users;
104104

@@ -135,7 +135,7 @@ export default class CommandsDisable extends BaseCommand {
135135
for (let payload of payloads) {
136136
const key = `${commandId}.${payload.item.id}.${payload.type}`;
137137
if (!settings.disabledCommands.has(key)) {
138-
await createGuildDisabledCommand(context, guildId, command.name, payload.item.id, payload.type);
138+
await createGuildDisabledCommand(context, guildId, commandId, payload.item.id, payload.type);
139139
}
140140
}
141141
settings = await GuildSettingsStore.fetch(context, guildId) as GuildSettings;

src/commands/prefixed/moderation/commands.enable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export default class CommandsEnable extends BaseCommand {
114114
async run(context: Command.Context, args: CommandArgs) {
115115
const { command } = args;
116116
const commandId = (command.metadata && command.metadata.id) ? command.metadata.id : command.name.split(' ').join('.');
117-
const guildId = context.guildId as string;
117+
const guildId = context.guildId!;
118118

119119
const isServerWide = !args.channels && !args.roles && !args.users;
120120

src/commands/prefixed/utils/shards.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export interface ClusterObjectInformation {
2828
emojis: number,
2929
events: number,
3030
guilds: number,
31+
guildScheduledEvents: number,
3132
members: number,
3233
memberCount: number,
3334
messages: number,
@@ -59,6 +60,7 @@ export async function getClusterInformation(context: Command.Context): Promise<A
5960
emojis: 0,
6061
events: 0,
6162
guilds: 0,
63+
guildScheduledEvents: 0,
6264
members: 0,
6365
memberCount: 0,
6466
messages: 0,
@@ -89,6 +91,7 @@ export async function getClusterInformation(context: Command.Context): Promise<A
8991
information.objects.emojis += shard.emojis.length;
9092
information.objects.events += shard.gateway.sequence;
9193
information.objects.guilds += shard.guilds.length;
94+
information.objects.guildScheduledEvents += shard.guildScheduledEvents.length;
9295
information.objects.members += shard.members.length;
9396
information.objects.memberCount += shard.guilds.reduce((x, guild) => x + guild.memberCount, 0);
9497
information.objects.messages += shard.messages.length;

src/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ import {
1111
} from 'detritus-client/lib/constants';
1212

1313

14-
1514
export const MAX_MEMBERS_SAFE = 1000;
1615

1716
export const MOMENT_FORMAT = 'y [years], w [weeks], d [days], h [hours], m [minutes], s [seconds]';
1817
export const SNOWFLAKE_EPOCH = 1564790400000;
1918
export const ZERO_WIDTH_SPACE = '\u200b';
2019

20+
export const ONE_DAY = 24 * 60 * 60 * 1000;
21+
2122

2223
export enum BooleanEmojis {
2324
NO = '❌',

src/interactioncommandclient.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,14 @@ export class NotSoInteractionClient extends InteractionCommandClient {
3535
return true;
3636
}
3737

38-
const metadata = (command.metadata.id) ? (command.metadata as InteractionCommandMetadata) : null;
38+
const metadata = command.metadata as InteractionCommandMetadata;
39+
const commandId = metadata.id || command.name.split(' ').join('.');
3940

4041
const channel = context.channel;
4142
const parent = (channel) ? channel.parent : null;
4243
if (settings) {
4344
const disabledCommands = settings.disabledCommands.filter((disabled) => {
44-
if (metadata) {
45-
return metadata.id === disabled.command;
46-
}
47-
return command.name === disabled.command;
45+
return disabled.command === commandId;
4846
});
4947
if (disabledCommands.length) {
5048
const shouldIgnore = disabledCommands.some((disabled) => {

0 commit comments

Comments
 (0)