aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-03-08 20:11:21 -0500
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-03-08 20:11:21 -0500
commitadc01358c14c2b71d932bdbf928e2c216ef8094f (patch)
treeddd970af504c9ed8c65d6f434d38647f0a04d229
parent9ffa112dfef858755b4fbbce2fdd34ce2ab897f5 (diff)
downloadtanzanite-adc01358c14c2b71d932bdbf928e2c216ef8094f.tar.gz
tanzanite-adc01358c14c2b71d932bdbf928e2c216ef8094f.tar.bz2
tanzanite-adc01358c14c2b71d932bdbf928e2c216ef8094f.zip
feat: improve appeal listener
-rw-r--r--src/commands/info/userInfo.ts53
-rw-r--r--src/listeners/bush/appealListener.ts87
2 files changed, 67 insertions, 73 deletions
diff --git a/src/commands/info/userInfo.ts b/src/commands/info/userInfo.ts
index 4f11936..66c0e00 100644
--- a/src/commands/info/userInfo.ts
+++ b/src/commands/info/userInfo.ts
@@ -13,6 +13,7 @@ import {
ActivityType,
ApplicationCommandOptionType,
ApplicationFlagsBitField,
+ ApplicationFlagsString,
Embed,
PermissionFlagsBits,
UserFlags
@@ -118,7 +119,7 @@ export default class UserInfoCommand extends BushCommand {
return userEmbed;
}
- private static async generateGeneralInfoField(embed: Embed, user: BushUser) {
+ public static async generateGeneralInfoField(embed: Embed, user: BushUser, title = '» General Information') {
// General Info
const generalInfo = [
`**Mention:** <@${user.id}>`,
@@ -132,10 +133,10 @@ export default class UserInfoCommand extends BushCommand {
if (pronouns && typeof pronouns === 'string' && pronouns !== 'Unspecified') generalInfo.push(`**Pronouns:** ${pronouns}`);
- embed.addFields({ name: '» General Info', value: generalInfo.join('\n') });
+ embed.addFields({ name: title, value: generalInfo.join('\n') });
}
- private static generateServerInfoField(embed: Embed, member?: BushGuildMember | undefined) {
+ public static generateServerInfoField(embed: Embed, member?: BushGuildMember | undefined, title = '» Server Information') {
if (!member) return;
// Server User Info
@@ -156,10 +157,10 @@ export default class UserInfoCommand extends BushCommand {
)
serverUserInfo.push(`**General Deletions:** ⅓`);
if (member?.nickname) serverUserInfo.push(`**Nickname:** ${util.discord.escapeMarkdown(member?.nickname)}`);
- if (serverUserInfo.length) embed.addFields({ name: '» Server Info', value: serverUserInfo.join('\n') });
+ if (serverUserInfo.length) embed.addFields({ name: title, value: serverUserInfo.join('\n') });
}
- private static generatePresenceField(embed: Embed, member?: BushGuildMember | undefined) {
+ public static generatePresenceField(embed: Embed, member?: BushGuildMember | undefined, title = '» Presence') {
if (!member || !member.presence) return;
if (!member.presence.status && !member.presence.clientStatus && !member.presence.activities) return;
@@ -184,7 +185,7 @@ export default class UserInfoCommand extends BushCommand {
if (activitiesNames.length)
presenceInfo.push(`**Activit${activitiesNames.length - 1 ? 'ies' : 'y'}:** ${util.oxford(activitiesNames, 'and', '')}`);
if (customStatus && customStatus.length) presenceInfo.push(`**Custom Status:** ${util.discord.escapeMarkdown(customStatus)}`);
- embed.addFields({ name: '» Presence', value: presenceInfo.join('\n') });
+ embed.addFields({ name: title, value: presenceInfo.join('\n') });
enum statusEmojis {
online = '787550449435803658',
@@ -199,7 +200,7 @@ export default class UserInfoCommand extends BushCommand {
});
}
- private static generateRolesField(embed: Embed, member?: BushGuildMember | undefined) {
+ public static generateRolesField(embed: Embed, member?: BushGuildMember | undefined) {
if (!member || member.roles.cache.size <= 1) return;
// roles
@@ -215,7 +216,7 @@ export default class UserInfoCommand extends BushCommand {
});
}
- private static generatePermissionsField(embed: Embed, member: BushGuildMember | undefined) {
+ public static generatePermissionsField(embed: Embed, member: BushGuildMember | undefined, title = '» Important Permissions') {
if (!member) return;
// Important Perms
@@ -230,10 +231,10 @@ export default class UserInfoCommand extends BushCommand {
});
}
- if (perms.length) embed.addFields({ name: '» Important Perms', value: perms.join(' ') });
+ if (perms.length) embed.addFields({ name: title, value: perms.join(' ') });
}
- private static async generateBotField(embed: Embed, user: BushUser) {
+ public static async generateBotField(embed: Embed, user: BushUser, title = '» Bot Information') {
if (!user.bot) return;
const applicationInfo = (await client.rest.get(`/applications/${user.id}/rpc`).catch(() => null)) as APIApplication | null;
@@ -241,30 +242,18 @@ export default class UserInfoCommand extends BushCommand {
const flags = new ApplicationFlagsBitField(applicationInfo.flags);
+ const intent = (check: ApplicationFlagsString, warn: ApplicationFlagsString) => {
+ if (flags.has(check)) return util.emojis.check;
+ if (flags.has(warn)) return util.emojis.warn;
+ return util.emojis.cross;
+ };
+
const botInfo = [
`**Publicity:** ${applicationInfo.bot_public ? 'Public' : 'Private'}`,
`**Requires Code Grant:** ${applicationInfo.bot_require_code_grant ? util.emojis.check : util.emojis.cross}`,
- `**Server Members Intent:** ${
- flags.has('GatewayGuildMembers')
- ? util.emojis.check
- : flags.has('GatewayGuildMembersLimited')
- ? util.emojis.warn
- : util.emojis.cross
- }`,
- `**Presence Intent:** ${
- flags.has('GatewayPresence')
- ? util.emojis.check
- : flags.has('GatewayPresenceLimited')
- ? util.emojis.warn
- : util.emojis.cross
- }`,
- `**Message Content Intent:** ${
- flags.has('GatewayMessageContent')
- ? util.emojis.check
- : flags.has('GatewayMessageContentLimited')
- ? util.emojis.warn
- : util.emojis.cross
- }`
+ `**Server Members Intent:** ${intent('GatewayGuildMembers', 'GatewayGuildMembersLimited')}`,
+ `**Presence Intent:** ${intent('GatewayPresence', 'GatewayPresenceLimited')}`,
+ `**Message Content Intent:** ${intent('GatewayMessageContent', 'GatewayMessageContentLimited')}`
];
if (applicationInfo.owner || applicationInfo.team) {
@@ -280,6 +269,6 @@ export default class UserInfoCommand extends BushCommand {
);
}
- if (botInfo.length) embed.addFields({ name: '» Bot Info', value: botInfo.join('\n') });
+ if (botInfo.length) embed.addFields({ name: title, value: botInfo.join('\n') });
}
}
diff --git a/src/listeners/bush/appealListener.ts b/src/listeners/bush/appealListener.ts
index 3ed8861..9f6b166 100644
--- a/src/listeners/bush/appealListener.ts
+++ b/src/listeners/bush/appealListener.ts
@@ -1,5 +1,9 @@
/* eslint-disable no-control-regex */
import { BushListener, ModLog, type BushClientEvents } from '#lib';
+import assert from 'assert';
+import { Embed } from 'discord.js';
+import UserInfoCommand from '../../commands/info/userInfo.js';
+import ModlogCommand from '../../commands/moderation/modlog.js';
export default class AppealListener extends BushListener {
public constructor() {
@@ -10,66 +14,67 @@ export default class AppealListener extends BushListener {
});
}
- public override async exec(...[message]: BushClientEvents['messageCreate']): Promise<void> {
+ public override async exec(...[message]: BushClientEvents['messageCreate']): Promise<any> {
+ if (!message.inGuild() || message.guildId !== client.consts.mappings.guilds.bush) return;
if (message.author.id !== '855446927688335370' || message.embeds.length < 1) return;
+
const userId = message.embeds[0].fields?.find?.((f) => f.name === 'What is your discord ID?')?.value;
if (!userId) return;
+ assert(message.embeds[0].fields);
+
const thread = await message.startThread({
- name: `${message.embeds[0].fields!.find((f) => f.name === 'What type of punishment are you appealing?')!.value} appeal`
+ name: `${message.embeds[0].fields.find((f) => f.name === 'What type of punishment are you appealing?')?.value} appeal`
});
- const user = await this.client.users.fetch(userId).catch(() => null);
- if (!user) {
- await thread.send({
+
+ const user = await client.users.fetch(userId).catch(() => null);
+ if (!user)
+ return await thread.send({
embeds: [
- this.client.util
- .embed()
+ new Embed()
+ .setTimestamp()
+ .setColor(util.colors.error)
.setTitle(
`${message.embeds[0].fields!.find((f) => f.name === 'What type of punishment are you appealing?')!.value} appeal`
)
.addFields({
- name: 'Author',
+ name: '» User Information',
value: 'Unable to fetch author, ID was likely invalid'
})
]
});
- } else {
- const latestModlog = await ModLog.findOne({
+
+ const latestModlogs = (
+ await ModLog.findAll({
where: {
user: user.id,
guild: message.guildId
},
order: [['createdAt', 'DESC']]
- });
- await thread.send({
- embeds: [
- this.client.util
- .embed()
- .setTitle(
- `${message.embeds[0].fields!.find((f) => f.name === 'What type of punishment are you appealing?')!.value} appeal`
- )
- .addField({
- name: 'Author',
- value: `${user} (${user.tag})`
- })
- .addField({
- name: 'Latest modlog',
- value: latestModlog
- ? `
- Case ID: ${latestModlog.id}
- Moderator: <@${latestModlog.moderator}> (${
- (await this.client.users
- .fetch(latestModlog.moderator)
- .then((u) => u.tag)
- .catch(() => null)) ?? latestModlog.moderator
- })
- Reason: ${latestModlog.reason}
- Type: ${latestModlog.type}
- Evidence: ${latestModlog.evidence}
- `.replace(/\x09/g, '')
- : 'No modlogs found'
- })
- ]
- });
+ })
+ )
+ .slice(0, 3)
+ .reverse();
+
+ const embed = new Embed()
+ .setTimestamp()
+ .setColor(util.colors.default)
+ .setTitle(`${message.embeds[0].fields!.find((f) => f.name === 'What type of punishment are you appealing?')!.value} appeal`)
+ .setThumbnail(user.displayAvatarURL());
+
+ await UserInfoCommand.generateGeneralInfoField(embed, user, '» User Information');
+
+ member: {
+ if (!message.guild.members.cache.has(user.id)) break member;
+ const member = message.guild.members.cache.get(user.id)!;
+ UserInfoCommand.generateServerInfoField(embed, member);
+ if (member.roles.cache.size > 1) UserInfoCommand.generateRolesField(embed, member);
}
+
+ embed.addFields({
+ name: '» Latest Modlogs',
+ value: latestModlogs.map((ml) => ModlogCommand.generateModlogInfo(ml, false)).join('\n') ?? 'No Modlogs Found'
+ });
+
+ await thread.send({ embeds: [embed] });
}
}