Skip to content

Commit 571a503

Browse files
committed
Fix some bugs
1 parent 4b4f109 commit 571a503

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

src/bot.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Message, Client, User, GuildMember } from 'discord.js';
2-
import { prefixes, trustedRoleId } from './env';
2+
import { botAdmins, prefixes, trustedRoleId } from './env';
33

44
export interface CommandRegistration {
55
aliases: string[];
@@ -21,13 +21,21 @@ export class Bot {
2121
const content = msg.content
2222
.substring(triggerWithPrefix.length + 1)
2323
.trim();
24-
this.getByTrigger(
24+
25+
const command = this.getByTrigger(
2526
triggerWithPrefix.substring(matchingPrefix.length),
26-
)
27-
?.listener(msg, content)
28-
.catch(err => {
29-
this.client.emit('error', err);
30-
});
27+
);
28+
29+
if (
30+
!command ||
31+
(this.adminCommands.includes(command) &&
32+
!this.isAdmin(msg.author))
33+
) {
34+
return;
35+
}
36+
command.listener(msg, content).catch(err => {
37+
this.client.emit('error', err);
38+
});
3139
}
3240
});
3341
}
@@ -49,6 +57,10 @@ export class Bot {
4957
return member?.permissions.has('ManageMessages') ?? false;
5058
}
5159

60+
isAdmin(user: User) {
61+
return botAdmins.includes(user.id);
62+
}
63+
5264
getTrustedMemberError(msg: Message) {
5365
if (!msg.guild || !msg.member || !msg.channel.isTextBased()) {
5466
return ":warning: you can't use that command here.";

src/modules/etc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const emojiRegex = /<:\w+?:(\d+?)>|(\p{Emoji_Presentation})/gu;
1818
const defaultPollEmojis = ['✅', '❌', '🤷'];
1919

2020
export function etcModule(bot: Bot) {
21-
bot.registerAdminCommand({
21+
bot.registerCommand({
2222
aliases: ['ping'],
2323
description: 'See if the bot is alive',
2424
async listener(msg) {

src/modules/playground.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export async function playgroundModule(bot: Bot) {
3131
const editedLongLink = new LimitedSizeMap<string, Message>(1000);
3232

3333
bot.registerCommand({
34-
aliases: ['pg', 'playg', 'playground'],
34+
aliases: ['playground', 'pg', 'playg'],
3535
description: 'Shorten a TypeScript playground link',
3636
async listener(msg, content) {
3737
console.log('Playground', msg.content);
@@ -46,7 +46,6 @@ export async function playgroundModule(bot: Bot) {
4646
":warning: couldn't find a codeblock!",
4747
);
4848
}
49-
console.log('Code is', code);
5049
const embed = new EmbedBuilder()
5150
.setURL(PLAYGROUND_BASE + compressToEncodedURIComponent(code))
5251
.setTitle('View in Playground')

0 commit comments

Comments
 (0)