aboutsummaryrefslogtreecommitdiff
path: root/src/commands/leveling
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-06-16 14:32:18 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-06-16 14:32:18 -0400
commit0e87bbd3940d89defcb04926587b35c8f4d1947f (patch)
treee50860d4dc25a11d4c3977b583284c4bcad1b077 /src/commands/leveling
parent661e4c9935aeb8760dafc7ced4bbec6cc356a033 (diff)
downloadtanzanite-0e87bbd3940d89defcb04926587b35c8f4d1947f.tar.gz
tanzanite-0e87bbd3940d89defcb04926587b35c8f4d1947f.tar.bz2
tanzanite-0e87bbd3940d89defcb04926587b35c8f4d1947f.zip
remove util classes, move config out of src
Diffstat (limited to 'src/commands/leveling')
-rw-r--r--src/commands/leveling/leaderboard.ts21
-rw-r--r--src/commands/leveling/level.ts11
-rw-r--r--src/commands/leveling/levelRoles.ts33
-rw-r--r--src/commands/leveling/setLevel.ts20
-rw-r--r--src/commands/leveling/setXp.ts24
5 files changed, 76 insertions, 33 deletions
diff --git a/src/commands/leveling/leaderboard.ts b/src/commands/leveling/leaderboard.ts
index 040ed4a..d81d88b 100644
--- a/src/commands/leveling/leaderboard.ts
+++ b/src/commands/leveling/leaderboard.ts
@@ -1,4 +1,15 @@
-import { BushCommand, ButtonPaginator, Level, type CommandMessage, type OptArgType, type SlashMessage } from '#lib';
+import {
+ BushCommand,
+ ButtonPaginator,
+ chunk,
+ clientSendAndPermCheck,
+ emojis,
+ Level,
+ prefix,
+ type CommandMessage,
+ type OptArgType,
+ type SlashMessage
+} from '#lib';
import assert from 'assert';
import { ApplicationCommandOptionType, EmbedBuilder, PermissionFlagsBits } from 'discord.js';
@@ -23,7 +34,7 @@ export default class LeaderboardCommand extends BushCommand {
],
slash: true,
channel: 'guild',
- clientPermissions: (m) => util.clientSendAndPermCheck(m),
+ clientPermissions: (m) => clientSendAndPermCheck(m),
userPermissions: []
});
}
@@ -33,9 +44,9 @@ export default class LeaderboardCommand extends BushCommand {
if (!(await message.guild.hasFeature('leveling')))
return await message.util.reply(
- `${util.emojis.error} This command can only be run in servers with the leveling feature enabled.${
+ `${emojis.error} This command can only be run in servers with the leveling feature enabled.${
message.member?.permissions.has(PermissionFlagsBits.ManageGuild)
- ? ` You can toggle features using the \`${util.prefix(message)}features\` command.`
+ ? ` You can toggle features using the \`${prefix(message)}features\` command.`
: ''
}`
);
@@ -44,7 +55,7 @@ export default class LeaderboardCommand extends BushCommand {
const mappedRanks = ranks.map(
(val, index) => `\`${index + 1}\` <@${val.user}> - Level ${val.level} (${val.xp.toLocaleString()} xp)`
);
- const chunked = util.chunk(mappedRanks, 25);
+ const chunked = chunk(mappedRanks, 25);
const embeds = chunked.map((c) =>
new EmbedBuilder().setTitle(`${message.guild.name}'s Leaderboard`).setDescription(c.join('\n'))
);
diff --git a/src/commands/leveling/level.ts b/src/commands/leveling/level.ts
index 34a839a..df3e5b2 100644
--- a/src/commands/leveling/level.ts
+++ b/src/commands/leveling/level.ts
@@ -2,7 +2,10 @@ import {
AllowedMentions,
BushCommand,
CanvasProgressBar,
+ clientSendAndPermCheck,
+ emojis,
Level,
+ prefix,
type CommandMessage,
type OptArgType,
type SlashMessage
@@ -39,7 +42,7 @@ export default class LevelCommand extends BushCommand {
],
slash: true,
channel: 'guild',
- clientPermissions: (m) => util.clientSendAndPermCheck(m),
+ clientPermissions: (m) => clientSendAndPermCheck(m),
userPermissions: []
});
}
@@ -49,9 +52,9 @@ export default class LevelCommand extends BushCommand {
if (!(await message.guild.hasFeature('leveling')))
return await message.util.reply(
- `${util.emojis.error} This command can only be run in servers with the leveling feature enabled.${
+ `${emojis.error} This command can only be run in servers with the leveling feature enabled.${
message.member?.permissions.has(PermissionFlagsBits.ManageGuild)
- ? ` You can toggle features using the \`${util.prefix(message)}features\` command.`
+ ? ` You can toggle features using the \`${prefix(message)}features\` command.`
: ''
}`
);
@@ -63,7 +66,7 @@ export default class LevelCommand extends BushCommand {
} catch (e) {
if (e instanceof Error && e.message === 'User does not have a level') {
return await message.util.reply({
- content: `${util.emojis.error} ${user} does not have a level.`,
+ content: `${emojis.error} ${user} does not have a level.`,
allowedMentions: AllowedMentions.none()
});
} else throw e;
diff --git a/src/commands/leveling/levelRoles.ts b/src/commands/leveling/levelRoles.ts
index afa4ab6..470cf58 100644
--- a/src/commands/leveling/levelRoles.ts
+++ b/src/commands/leveling/levelRoles.ts
@@ -1,4 +1,13 @@
-import { AllowedMentions, BushCommand, type ArgType, type CommandMessage, type OptArgType, type SlashMessage } from '#lib';
+import {
+ AllowedMentions,
+ BushCommand,
+ clientSendAndPermCheck,
+ emojis,
+ type ArgType,
+ type CommandMessage,
+ type OptArgType,
+ type SlashMessage
+} from '#lib';
import assert from 'assert';
import { ApplicationCommandOptionType, PermissionFlagsBits } from 'discord.js';
@@ -33,7 +42,7 @@ export default class LevelRolesCommand extends BushCommand {
],
slash: true,
channel: 'guild',
- clientPermissions: (m) => util.clientSendAndPermCheck(m, [PermissionFlagsBits.ManageRoles]),
+ clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.ManageRoles]),
userPermissions: [PermissionFlagsBits.ManageGuild, PermissionFlagsBits.ManageRoles]
});
}
@@ -46,20 +55,20 @@ export default class LevelRolesCommand extends BushCommand {
assert(message.member);
if (!(await message.guild.hasFeature('leveling'))) {
- return await reply(`${util.emojis.error} This command can only be run in servers with the leveling feature enabled.`);
+ return await reply(`${emojis.error} This command can only be run in servers with the leveling feature enabled.`);
}
- if (args.level < 1) return await reply(`${util.emojis.error} You cannot set a level role less than **1**.`);
+ if (args.level < 1) return await reply(`${emojis.error} You cannot set a level role less than **1**.`);
if (args.role) {
if (args.role.managed)
- return await reply(`${util.emojis.error} You cannot set <@${args.role.id}> as a level role since it is managed.`);
+ return await reply(`${emojis.error} You cannot set <@${args.role.id}> as a level role since it is managed.`);
else if (args.role.id === message.guild.id)
- return await reply(`${util.emojis.error} You cannot set the @everyone role as a level role.`);
+ return await reply(`${emojis.error} You cannot set the @everyone role as a level role.`);
else if (args.role.comparePositionTo(message.member.roles.highest) >= 0)
- return await reply(`${util.emojis.error} <@${args.role.id}> is higher or equal to your highest role.`);
+ return await reply(`${emojis.error} <@${args.role.id}> is higher or equal to your highest role.`);
else if (args.role.comparePositionTo(message.guild.members.me!.roles.highest) >= 0)
- return await reply(`${util.emojis.error} <@${args.role.id}> is higher or equal to my highest role.`);
+ return await reply(`${emojis.error} <@${args.role.id}> is higher or equal to my highest role.`);
}
const oldRoles = Object.freeze(await message.guild.getSetting('levelRoles'));
@@ -74,17 +83,17 @@ export default class LevelRolesCommand extends BushCommand {
const success = await message.guild.setSetting('levelRoles', newRoles, message.member).catch(() => false);
- if (!success) return await reply(`${util.emojis.error} An error occurred while setting the level roles.`);
+ if (!success) return await reply(`${emojis.error} An error occurred while setting the level roles.`);
if (!oldRoles[args.level] && newRoles[args.level]) {
- return await reply(`${util.emojis.success} The level role for **${args.level}** is now <@&${newRoles[args.level]}>.`);
+ return await reply(`${emojis.success} The level role for **${args.level}** is now <@&${newRoles[args.level]}>.`);
} else if (oldRoles[args.level] && !newRoles[args.level]) {
return await reply(
- `${util.emojis.success} The level role for **${args.level}** was <@&${oldRoles[args.level]}> but is now disabled.`
+ `${emojis.success} The level role for **${args.level}** was <@&${oldRoles[args.level]}> but is now disabled.`
);
} else if (oldRoles[args.level] && newRoles[args.level]) {
return await reply(
- `${util.emojis.success} The level role for **${args.level}** has been updated from <@&${oldRoles[args.level]}> to <@&${
+ `${emojis.success} The level role for **${args.level}** has been updated from <@&${oldRoles[args.level]}> to <@&${
newRoles[args.level]
}>.`
);
diff --git a/src/commands/leveling/setLevel.ts b/src/commands/leveling/setLevel.ts
index 8abdb57..b1d9516 100644
--- a/src/commands/leveling/setLevel.ts
+++ b/src/commands/leveling/setLevel.ts
@@ -1,4 +1,14 @@
-import { AllowedMentions, BushCommand, Level, type ArgType, type CommandMessage, type SlashMessage } from '#lib';
+import {
+ AllowedMentions,
+ BushCommand,
+ clientSendAndPermCheck,
+ emojis,
+ format,
+ Level,
+ type ArgType,
+ type CommandMessage,
+ type SlashMessage
+} from '#lib';
import assert from 'assert';
import { ApplicationCommandOptionType, PermissionFlagsBits } from 'discord.js';
@@ -30,7 +40,7 @@ export default class SetLevelCommand extends BushCommand {
],
slash: true,
channel: 'guild',
- clientPermissions: (m) => util.clientSendAndPermCheck(m),
+ clientPermissions: (m) => clientSendAndPermCheck(m),
userPermissions: [PermissionFlagsBits.Administrator]
});
}
@@ -43,9 +53,9 @@ export default class SetLevelCommand extends BushCommand {
assert(user.id);
if (isNaN(level) || !Number.isInteger(level))
- return await message.util.reply(`${util.emojis.error} Provide a valid number to set the user's level to.`);
+ return await message.util.reply(`${emojis.error} Provide a valid number to set the user's level to.`);
if (level > 6553 || level < 0)
- return await message.util.reply(`${util.emojis.error} You cannot set a level higher than **6,553**.`);
+ return await message.util.reply(`${emojis.error} You cannot set a level higher than **6,553**.`);
const [levelEntry] = await Level.findOrBuild({
where: { user: user.id, guild: message.guild.id },
@@ -53,7 +63,7 @@ export default class SetLevelCommand extends BushCommand {
});
await levelEntry.update({ xp: Level.convertLevelToXp(level), user: user.id, guild: message.guild.id });
return await message.util.send({
- content: `Successfully set level of <@${user.id}> to ${util.format.input(level.toLocaleString())} (${util.format.input(
+ content: `Successfully set level of <@${user.id}> to ${format.input(level.toLocaleString())} (${format.input(
levelEntry.xp.toLocaleString()
)} XP)`,
allowedMentions: AllowedMentions.none()
diff --git a/src/commands/leveling/setXp.ts b/src/commands/leveling/setXp.ts
index 60e0b94..96b3ad7 100644
--- a/src/commands/leveling/setXp.ts
+++ b/src/commands/leveling/setXp.ts
@@ -1,4 +1,14 @@
-import { AllowedMentions, BushCommand, Level, type ArgType, type CommandMessage, type SlashMessage } from '#lib';
+import {
+ AllowedMentions,
+ BushCommand,
+ clientSendAndPermCheck,
+ emojis,
+ format,
+ Level,
+ type ArgType,
+ type CommandMessage,
+ type SlashMessage
+} from '#lib';
import assert from 'assert';
import { ApplicationCommandOptionType, PermissionFlagsBits } from 'discord.js';
@@ -31,7 +41,7 @@ export default class SetXpCommand extends BushCommand {
],
slash: true,
channel: 'guild',
- clientPermissions: (m) => util.clientSendAndPermCheck(m),
+ clientPermissions: (m) => clientSendAndPermCheck(m),
userPermissions: [PermissionFlagsBits.Administrator]
});
}
@@ -43,10 +53,10 @@ export default class SetXpCommand extends BushCommand {
assert(message.inGuild());
assert(user.id);
- if (isNaN(xp)) return await message.util.reply(`${util.emojis.error} Provide a valid number.`);
+ if (isNaN(xp)) return await message.util.reply(`${emojis.error} Provide a valid number.`);
if (xp > 2147483647 || xp < 0)
return await message.util.reply(
- `${util.emojis.error} Provide an positive integer under **2,147,483,647** to set the user's xp to.`
+ `${emojis.error} Provide an positive integer under **2,147,483,647** to set the user's xp to.`
);
const [levelEntry] = await Level.findOrBuild({
@@ -57,9 +67,9 @@ export default class SetXpCommand extends BushCommand {
await levelEntry.update({ xp: xp, user: user.id, guild: message.guild.id });
return await message.util.send({
- content: `Successfully set <@${user.id}>'s xp to ${util.format.input(
- levelEntry.xp.toLocaleString()
- )} (level ${util.format.input(Level.convertXpToLevel(levelEntry.xp).toLocaleString())}).`,
+ content: `Successfully set <@${user.id}>'s xp to ${format.input(levelEntry.xp.toLocaleString())} (level ${format.input(
+ Level.convertXpToLevel(levelEntry.xp).toLocaleString()
+ )}).`,
allowedMentions: AllowedMentions.none()
});
}