aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTymanWasTaken <tyman@tyman.tech>2021-05-18 23:41:49 -0400
committerTymanWasTaken <tyman@tyman.tech>2021-05-18 23:41:49 -0400
commit267c2946fc80e75cf01f22d311dd07cfb853f74b (patch)
treedfd0bd200f405c5e2613a7b8c055e68af7d3edf2
parent3b02bab4f786b9beb5afa18606d3e1d8fea0003d (diff)
downloadtanzanite-267c2946fc80e75cf01f22d311dd07cfb853f74b.tar.gz
tanzanite-267c2946fc80e75cf01f22d311dd07cfb853f74b.tar.bz2
tanzanite-267c2946fc80e75cf01f22d311dd07cfb853f74b.zip
nevermind forgot about these (I'll do the rest later they are annoying to do
-rw-r--r--src/commands/moderation/ban.ts90
-rw-r--r--src/commands/moderation/kick.ts72
-rw-r--r--src/commands/moderation/role.ts109
-rw-r--r--yarn.lock86
4 files changed, 199 insertions, 158 deletions
diff --git a/src/commands/moderation/ban.ts b/src/commands/moderation/ban.ts
index 107de9d..556dd6b 100644
--- a/src/commands/moderation/ban.ts
+++ b/src/commands/moderation/ban.ts
@@ -5,8 +5,8 @@ import { Ban, Modlog, ModlogType } from '../../lib/models';
import moment from 'moment';
import { Message } from 'discord.js';
import { CommandInteraction } from 'discord.js';
-// import { SlashCommandOption } from '../../lib/extensions/Util';
-// import { ApplicationCommandOptionType } from 'discord-api-types';
+import { SlashCommandOption } from '../../lib/extensions/Util';
+import { ApplicationCommandOptionType } from 'discord-api-types';
const durationAliases: Record<string, string[]> = {
weeks: ['w', 'weeks', 'week', 'wk', 'wks'],
@@ -51,28 +51,28 @@ export default class PrefixCommand extends BotCommand {
'ban @Tyman being cool',
'ban @Tyman being cool --time 7days'
]
- }
- // slashCommandOptions: [
- // {
- // type: ApplicationCommandOptionType.USER,
- // name: 'user',
- // description: 'The user to ban',
- // required: true
- // },
- // {
- // type: ApplicationCommandOptionType.STRING,
- // name: 'reason',
- // description: 'The reason to show in modlogs and audit log',
- // required: false
- // },
- // {
- // type: ApplicationCommandOptionType.STRING,
- // name: 'time',
- // description:
- // 'The time the user should be banned for (default permanent)',
- // required: false
- // }
- // ]
+ },
+ slashCommandOptions: [
+ {
+ type: ApplicationCommandOptionType.USER,
+ name: 'user',
+ description: 'The user to ban',
+ required: true
+ },
+ {
+ type: ApplicationCommandOptionType.STRING,
+ name: 'reason',
+ description: 'The reason to show in modlogs and audit log',
+ required: false
+ },
+ {
+ type: ApplicationCommandOptionType.STRING,
+ name: 'time',
+ description:
+ 'The time the user should be banned for (default permanent)',
+ required: false
+ }
+ ]
});
}
async *genResponses(
@@ -199,25 +199,25 @@ export default class PrefixCommand extends BotCommand {
}
}
- // async execSlash(
- // message: CommandInteraction,
- // {
- // user,
- // reason,
- // time
- // }: {
- // user: SlashCommandOption<undefined>;
- // reason: SlashCommandOption<string>;
- // time: SlashCommandOption<string>;
- // }
- // ): Promise<void> {
- // for await (const response of this.genResponses(
- // message,
- // user.user,
- // reason?.value,
- // time?.value
- // )) {
- // await message.reply(response);
- // }
- // }
+ async execSlash(
+ message: CommandInteraction,
+ {
+ user,
+ reason,
+ time
+ }: {
+ user: SlashCommandOption<undefined>;
+ reason: SlashCommandOption<string>;
+ time: SlashCommandOption<string>;
+ }
+ ): Promise<void> {
+ for await (const response of this.genResponses(
+ message,
+ user.user,
+ reason?.value,
+ time?.value
+ )) {
+ await message.reply(response);
+ }
+ }
}
diff --git a/src/commands/moderation/kick.ts b/src/commands/moderation/kick.ts
index 7b04d5a..a16e4b0 100644
--- a/src/commands/moderation/kick.ts
+++ b/src/commands/moderation/kick.ts
@@ -1,8 +1,10 @@
import { BotCommand } from '../../lib/extensions/BotCommand';
import { Guild, Modlog, ModlogType } from '../../lib/models';
import { GuildMember, Message } from 'discord.js';
+import { ApplicationCommandOptionType } from 'discord-api-types';
+import { CommandInteraction } from 'discord.js';
-export default class PrefixCommand extends BotCommand {
+export default class KickCommand extends BotCommand {
constructor() {
super('kick', {
aliases: ['kick'],
@@ -25,13 +27,29 @@ export default class PrefixCommand extends BotCommand {
content: 'Kick a member and log it in modlogs',
usage: 'kick <member> <reason>',
examples: ['kick @Tyman being cool']
- }
+ },
+ slashCommandOptions: [
+ {
+ type: ApplicationCommandOptionType.USER,
+ name: 'user',
+ description: 'The user to kick',
+ required: true
+ },
+ {
+ type: ApplicationCommandOptionType.STRING,
+ name: 'reason',
+ description: 'The reason to show in modlogs and audit log',
+ required: false
+ }
+ ]
});
}
- async exec(
- message: Message,
- { user, reason }: { user: GuildMember; reason?: string }
- ): Promise<void> {
+
+ private async *genResponses(
+ message: Message | CommandInteraction,
+ user: GuildMember,
+ reason?: string
+ ): AsyncIterable<string> {
let modlogEnry: Modlog;
// Create guild entry so postgres doesn't get mad when I try and add a modlog entry
await Guild.findOrCreate({
@@ -46,16 +64,14 @@ export default class PrefixCommand extends BotCommand {
modlogEnry = Modlog.build({
user: user.id,
guild: message.guild.id,
- moderator: message.author.id,
+ moderator: message instanceof Message ? message.author.id : message.user.id,
type: ModlogType.KICK,
reason
});
await modlogEnry.save();
} catch (e) {
console.error(e);
- await message.util.send(
- 'Error saving to database. Please report this to a developer.'
- );
+ yield 'Error saving to database. Please report this to a developer.'
return;
}
try {
@@ -65,21 +81,45 @@ export default class PrefixCommand extends BotCommand {
}\``
);
} catch (e) {
- await message.channel.send('Error sending message to user');
+ yield 'Error sending message to user';
}
try {
await user.kick(
- `Kicked by ${message.author.tag} with ${
+ `Kicked by ${message instanceof Message ? message.author.tag : message.user.tag} with ${
reason ? `reason ${reason}` : 'no reason'
}`
);
} catch {
- await message.util.send('Error kicking :/');
+ yield 'Error kicking :/';
await modlogEnry.destroy();
return;
}
- await message.util.send(
- `Kicked <@!${user.id}> with reason \`${reason || 'No reason given'}\``
- );
+ yield `Kicked <@!${user.id}> with reason \`${reason || 'No reason given'}\``
+ }
+
+ async exec(
+ message: Message,
+ { user, reason }: { user: GuildMember; reason?: string }
+ ): Promise<void> {
+ for await (const response of this.genResponses(
+ message,
+ user,
+ reason
+ )) {
+ await message.util.send(response);
+ }
+ }
+
+ async execSlash(
+ message: CommandInteraction,
+ { user, reason }: { user: GuildMember; reason?: string }
+ ): Promise<void> {
+ for await (const response of this.genResponses(
+ message,
+ user,
+ reason
+ )) {
+ await message.reply(response);
+ }
}
}
diff --git a/src/commands/moderation/role.ts b/src/commands/moderation/role.ts
index e799698..daa575d 100644
--- a/src/commands/moderation/role.ts
+++ b/src/commands/moderation/role.ts
@@ -2,6 +2,7 @@
import { BotCommand } from '../../lib/extensions/BotCommand';
import AllowedMentions from '../../lib/utils/AllowedMentions';
import { Message, Role, GuildMember } from 'discord.js';
+import { ApplicationCommandOptionType } from 'discord-api-types';
export default class RoleCommand extends BotCommand {
private roleWhitelist: Record<string, string[]> = {
@@ -49,51 +50,49 @@ export default class RoleCommand extends BotCommand {
},
clientPermissions: ['MANAGE_ROLES', 'EMBED_LINKS', 'SEND_MESSAGES'],
channel: 'guild',
- typing: true
+ typing: true,
+ args: [
+ {
+ id: 'user',
+ type: 'member',
+ prompt: {
+ start: `What user do you want to add/remove the role on?`,
+ retry: `<:error:837123021016924261> Choose a valid user to add/remove the role on.`
+ }
+ },
+ {
+ id: 'role',
+ type: 'role',
+ match: 'restContent',
+ prompt: {
+ start: `What role do you want to add/remove?`,
+ retry: `<:error:837123021016924261> Choose a valid role to add/remove.`
+ }
+ }
+ ],
+ slashCommandOptions: [
+ {
+ type: ApplicationCommandOptionType.USER,
+ name: 'user',
+ description: 'The user to add/remove the role on',
+ required: true
+ },
+ {
+ type: ApplicationCommandOptionType.ROLE,
+ name: 'role',
+ description: 'The role to add/remove',
+ required: true
+ }
+ ]
});
}
- *args(): unknown {
- const action: 'add' | 'remove' = yield {
- id: 'action',
- type: [['add'], ['remove']],
- prompt: {
- start: 'Would you like to `add` or `remove` a role?',
- retry:
- '<:error:837123021016924261> Choose whether you would you like to `add` or `remove` a role.'
- }
- };
- let actionWord: string;
- if (action === 'add') actionWord = 'to';
- else if (action === 'remove') actionWord = 'from';
- else return;
- const user = yield {
- id: 'user',
- type: 'member',
- prompt: {
- start: `What user do you want to ${action} the role ${actionWord}?`,
- retry: `<:error:837123021016924261> Choose a valid user to ${action} the role ${actionWord}.`
- }
- };
- const role = yield {
- id: 'role',
- type: 'role',
- match: 'restContent',
- prompt: {
- start: `What role do you want to ${action}?`,
- retry: `<:error:837123021016924261> Choose a valid role to ${action}.`
- }
- };
- return { action, user, role };
- }
- // eslint-disable-next-line require-await
public async exec(
message: Message,
{
- action,
user,
role
- }: { action: 'add' | 'remove'; user: GuildMember; role: Role }
+ }: { user: GuildMember; role: Role }
): Promise<unknown> {
if (
!message.member.permissions.has('MANAGE_ROLES') &&
@@ -153,31 +152,33 @@ export default class RoleCommand extends BotCommand {
);
}
}
- // no checks if the user has MANAGE_ROLES
- if (action == 'remove') {
- const success = await user.roles.remove(role.id).catch(() => undefined);
- if (success)
- return message.util.reply(
- `<:checkmark:837109864101707807> Successfully removed <@&${role.id}> from <@${user.id}>!`,
- { allowedMentions: AllowedMentions.none() }
- );
- else
+ // No checks if the user has MANAGE_ROLES
+ if (user.roles.cache.has(role.id)) {
+ try {
+ await user.roles.remove(role.id);
+ } catch {
return message.util.reply(
`<:error:837123021016924261> Could not remove <@&${role.id}> from <@${user.id}>.`,
{ allowedMentions: AllowedMentions.none() }
);
- } else if (action == 'add') {
- const success = await user.roles.add(role.id).catch(() => undefined);
- if (success) {
- return message.util.reply(
- `<:checkmark:837109864101707807> Successfully added <@&${role.id}> to <@${user.id}>!`,
- { allowedMentions: AllowedMentions.none() }
- );
- } else
+ }
+ return message.util.reply(
+ `<:checkmark:837109864101707807> Successfully removed <@&${role.id}> from <@${user.id}>!`,
+ { allowedMentions: AllowedMentions.none() }
+ );
+ } else {
+ try {
+ await user.roles.add(role.id);
+ } catch {
return message.util.reply(
`<:error:837123021016924261> Could not add <@&${role.id}> to <@${user.id}>.`,
{ allowedMentions: AllowedMentions.none() }
);
+ }
+ return message.util.reply(
+ `<:checkmark:837109864101707807> Successfully added <@&${role.id}> to <@${user.id}>!`,
+ { allowedMentions: AllowedMentions.none() }
+ );
}
}
}
diff --git a/yarn.lock b/yarn.lock
index f85d384..2c90517 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -170,9 +170,9 @@
integrity sha512-8/bnjSZD86ZfpBsDlCIkNXIvm+h6wi9g7IqL+kmFkQ+Wvu3JrasgLElfiPgoo8V8vVfnEi0QVS12gbl94h9YsQ==
"@types/node@^14.14.22":
- version "14.14.45"
- resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.45.tgz#ec2dfb5566ff814d061aef7e141575aedba245cf"
- integrity sha512-DssMqTV9UnnoxDWu959sDLZzfvqCF0qDNRjaWeYSui9xkFe61kKo4l1TWNTQONpuXEm+gLMRvdlzvNHBamzmEw==
+ version "14.17.0"
+ resolved "https://registry.yarnpkg.com/@types/node/-/node-14.17.0.tgz#3ba770047723b3eeb8dc9fca02cce8a7fb6378da"
+ integrity sha512-w8VZUN/f7SSbvVReb9SWp6cJFevxb4/nkG65yLAya//98WgocKm5PLDAtSs5CtJJJM+kHmJjO/6mmYW4MHShZA==
"@types/qs@*":
version "6.9.6"
@@ -205,12 +205,12 @@
integrity sha512-eQ9qFW/fhfGJF8WKHGEHZEyVWfZxrT+6CLIJGBcZPfxUh/+BnEj+UCGYMlr9qZuX/2AltsvwrGqp0LhEW8D0zQ==
"@typescript-eslint/eslint-plugin@^4.14.1":
- version "4.23.0"
- resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.23.0.tgz#29d3c9c81f6200b1fd6d8454cfb007ba176cde80"
- integrity sha512-tGK1y3KIvdsQEEgq6xNn1DjiFJtl+wn8JJQiETtCbdQxw1vzjXyAaIkEmO2l6Nq24iy3uZBMFQjZ6ECf1QdgGw==
+ version "4.24.0"
+ resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.24.0.tgz#03801ffc25b2af9d08f3dc9bccfc0b7ce3780d0f"
+ integrity sha512-qbCgkPM7DWTsYQGjx9RTuQGswi+bEt0isqDBeo+CKV0953zqI0Tp7CZ7Fi9ipgFA6mcQqF4NOVNwS/f2r6xShw==
dependencies:
- "@typescript-eslint/experimental-utils" "4.23.0"
- "@typescript-eslint/scope-manager" "4.23.0"
+ "@typescript-eslint/experimental-utils" "4.24.0"
+ "@typescript-eslint/scope-manager" "4.24.0"
debug "^4.1.1"
functional-red-black-tree "^1.0.1"
lodash "^4.17.15"
@@ -218,60 +218,60 @@
semver "^7.3.2"
tsutils "^3.17.1"
-"@typescript-eslint/experimental-utils@4.23.0":
- version "4.23.0"
- resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.23.0.tgz#f2059434cd6e5672bfeab2fb03b7c0a20622266f"
- integrity sha512-WAFNiTDnQfrF3Z2fQ05nmCgPsO5o790vOhmWKXbbYQTO9erE1/YsFot5/LnOUizLzU2eeuz6+U/81KV5/hFTGA==
+"@typescript-eslint/experimental-utils@4.24.0":
+ version "4.24.0"
+ resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.24.0.tgz#c23ead9de44b99c3a5fd925c33a106b00165e172"
+ integrity sha512-IwTT2VNDKH1h8RZseMH4CcYBz6lTvRoOLDuuqNZZoThvfHEhOiZPQCow+5El3PtyxJ1iDr6UXZwYtE3yZQjhcw==
dependencies:
"@types/json-schema" "^7.0.3"
- "@typescript-eslint/scope-manager" "4.23.0"
- "@typescript-eslint/types" "4.23.0"
- "@typescript-eslint/typescript-estree" "4.23.0"
+ "@typescript-eslint/scope-manager" "4.24.0"
+ "@typescript-eslint/types" "4.24.0"
+ "@typescript-eslint/typescript-estree" "4.24.0"
eslint-scope "^5.0.0"
eslint-utils "^2.0.0"
"@typescript-eslint/parser@^4.14.1":
- version "4.23.0"
- resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.23.0.tgz#239315d38e42e852bef43a4b0b01bef78f78911c"
- integrity sha512-wsvjksHBMOqySy/Pi2Q6UuIuHYbgAMwLczRl4YanEPKW5KVxI9ZzDYh3B5DtcZPQTGRWFJrfcbJ6L01Leybwug==
+ version "4.24.0"
+ resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.24.0.tgz#2e5f1cc78ffefe43bfac7e5659309a92b09a51bd"
+ integrity sha512-dj1ZIh/4QKeECLb2f/QjRwMmDArcwc2WorWPRlB8UNTZlY1KpTVsbX7e3ZZdphfRw29aTFUSNuGB8w9X5sS97w==
dependencies:
- "@typescript-eslint/scope-manager" "4.23.0"
- "@typescript-eslint/types" "4.23.0"
- "@typescript-eslint/typescript-estree" "4.23.0"
+ "@typescript-eslint/scope-manager" "4.24.0"
+ "@typescript-eslint/types" "4.24.0"
+ "@typescript-eslint/typescript-estree" "4.24.0"
debug "^4.1.1"
-"@typescript-eslint/scope-manager@4.23.0":
- version "4.23.0"
- resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.23.0.tgz#8792ef7eacac122e2ec8fa2d30a59b8d9a1f1ce4"
- integrity sha512-ZZ21PCFxPhI3n0wuqEJK9omkw51wi2bmeKJvlRZPH5YFkcawKOuRMQMnI8mH6Vo0/DoHSeZJnHiIx84LmVQY+w==
+"@typescript-eslint/scope-manager@4.24.0":
+ version "4.24.0"
+ resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.24.0.tgz#38088216f0eaf235fa30ed8cabf6948ec734f359"
+ integrity sha512-9+WYJGDnuC9VtYLqBhcSuM7du75fyCS/ypC8c5g7Sdw7pGL4NDTbeH38eJPfzIydCHZDoOgjloxSAA3+4l/zsA==
dependencies:
- "@typescript-eslint/types" "4.23.0"
- "@typescript-eslint/visitor-keys" "4.23.0"
+ "@typescript-eslint/types" "4.24.0"
+ "@typescript-eslint/visitor-keys" "4.24.0"
-"@typescript-eslint/types@4.23.0":
- version "4.23.0"
- resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.23.0.tgz#da1654c8a5332f4d1645b2d9a1c64193cae3aa3b"
- integrity sha512-oqkNWyG2SLS7uTWLZf6Sr7Dm02gA5yxiz1RP87tvsmDsguVATdpVguHr4HoGOcFOpCvx9vtCSCyQUGfzq28YCw==
+"@typescript-eslint/types@4.24.0":
+ version "4.24.0"
+ resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.24.0.tgz#6d0cca2048cbda4e265e0c4db9c2a62aaad8228c"
+ integrity sha512-tkZUBgDQKdvfs8L47LaqxojKDE+mIUmOzdz7r+u+U54l3GDkTpEbQ1Jp3cNqqAU9vMUCBA1fitsIhm7yN0vx9Q==
-"@typescript-eslint/typescript-estree@4.23.0":
- version "4.23.0"
- resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.23.0.tgz#0753b292097523852428a6f5a1aa8ccc1aae6cd9"
- integrity sha512-5Sty6zPEVZF5fbvrZczfmLCOcby3sfrSPu30qKoY1U3mca5/jvU5cwsPb/CO6Q3ByRjixTMIVsDkqwIxCf/dMw==
+"@typescript-eslint/typescript-estree@4.24.0":
+ version "4.24.0"
+ resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.24.0.tgz#b49249679a98014d8b03e8d4b70864b950e3c90f"
+ integrity sha512-kBDitL/by/HK7g8CYLT7aKpAwlR8doshfWz8d71j97n5kUa5caHWvY0RvEUEanL/EqBJoANev8Xc/mQ6LLwXGA==
dependencies:
- "@typescript-eslint/types" "4.23.0"
- "@typescript-eslint/visitor-keys" "4.23.0"
+ "@typescript-eslint/types" "4.24.0"
+ "@typescript-eslint/visitor-keys" "4.24.0"
debug "^4.1.1"
globby "^11.0.1"
is-glob "^4.0.1"
semver "^7.3.2"
tsutils "^3.17.1"
-"@typescript-eslint/visitor-keys@4.23.0":
- version "4.23.0"
- resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.23.0.tgz#7215cc977bd3b4ef22467b9023594e32f9e4e455"
- integrity sha512-5PNe5cmX9pSifit0H+nPoQBXdbNzi5tOEec+3riK+ku4e3er37pKxMKDH5Ct5Y4fhWxcD4spnlYjxi9vXbSpwg==
+"@typescript-eslint/visitor-keys@4.24.0":
+ version "4.24.0"
+ resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.24.0.tgz#a8fafdc76cad4e04a681a945fbbac4e35e98e297"
+ integrity sha512-4ox1sjmGHIxjEDBnMCtWFFhErXtKA1Ec0sBpuz0fqf3P+g3JFGyTxxbF06byw0FRsPnnbq44cKivH7Ks1/0s6g==
dependencies:
- "@typescript-eslint/types" "4.23.0"
+ "@typescript-eslint/types" "4.24.0"
eslint-visitor-keys "^2.0.0"
abort-controller@^3.0.0:
@@ -600,7 +600,7 @@ dir-glob@^3.0.1:
discord-akairo@SkyBlockDev/discord-akairo:
version "8.2.2"
- resolved "https://codeload.github.com/SkyBlockDev/discord-akairo/tar.gz/f061db03014b1ef7ebdf118658c48fde482cd9a7"
+ resolved "https://codeload.github.com/SkyBlockDev/discord-akairo/tar.gz/185d82fc0b4cef326d155c7c3f3f7ffe340e521c"
discord-api-types@^0.18.1:
version "0.18.1"