-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
233 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { Channel, Role, User } from 'discord.js'; | ||
import * as CT from '../../../../Typings/Typings.js'; | ||
|
||
export default (t: CT.Language) => ({ | ||
...t.JSON.events.messageCreate, | ||
pingReporter: { | ||
...t.JSON.events.messageCreate.pingReporter, | ||
desc: (role: Role, channel: Channel, user: User) => | ||
t.stp(t.JSON.events.messageCreate.pingReporter.desc, { | ||
role: t.languageFunction.getRole(role), | ||
channel: t.languageFunction.getChannel(channel, t.channelTypes[channel.type]), | ||
user: t.languageFunction.getUser(user), | ||
}), | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
src/Commands/SlashCommands/settings/roles/ping-reporter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import * as Discord from 'discord.js'; | ||
import client from '../../../../BaseClient/Bot/Client.js'; | ||
import * as CT from '../../../../Typings/Typings.js'; | ||
|
||
const name = CT.SettingNames.PingReporter; | ||
|
||
export default async (cmd: Discord.ChatInputCommandInteraction) => { | ||
if (!cmd.inCachedGuild()) return; | ||
|
||
const language = await client.util.getLanguage(cmd.guild.id); | ||
const lan = language.slashCommands.settings.categories[name]; | ||
const { embedParsers, buttonParsers } = client.util.settingsHelpers; | ||
const settings = await client.util.DataBase[CT.SettingsName2TableName[name]] | ||
.findUnique({ where: { guildid: cmd.guildId } }) | ||
.then( | ||
(r) => | ||
r ?? | ||
client.util.DataBase[CT.SettingsName2TableName[name]].create({ | ||
data: { guildid: cmd.guildId }, | ||
}), | ||
); | ||
|
||
cmd.reply({ | ||
embeds: await getEmbeds(embedParsers, settings, language, lan, cmd.guild), | ||
components: await getComponents(buttonParsers, settings, language), | ||
ephemeral: true, | ||
}); | ||
}; | ||
|
||
export const getEmbeds: CT.SettingsFile<typeof name>['getEmbeds'] = ( | ||
embedParsers, | ||
settings, | ||
language, | ||
lan, | ||
) => [ | ||
{ | ||
author: embedParsers.author(language, lan), | ||
description: `${lan.description}\n${ | ||
client.util.constants.tutorials[name as keyof typeof client.util.constants.tutorials]?.length | ||
? `${language.slashCommands.settings.tutorial}\n${client.util.constants.tutorials[ | ||
name as keyof typeof client.util.constants.tutorials | ||
].map((t) => `[${t.name}](${t.link})`)}` | ||
: '' | ||
}`, | ||
fields: [ | ||
{ | ||
name: language.slashCommands.settings.active, | ||
value: embedParsers.boolean(settings?.active, language), | ||
inline: true, | ||
}, | ||
{ | ||
name: lan.fields.cooldown.name, | ||
value: embedParsers.time( | ||
settings?.cooldown ? Number(settings.cooldown) * 1000 : null, | ||
language, | ||
), | ||
inline: true, | ||
}, | ||
{ | ||
name: lan.fields.roleIds.name, | ||
value: embedParsers.roles(settings?.roleIds, language), | ||
inline: false, | ||
}, | ||
{ | ||
name: lan.fields.channelIds.name, | ||
value: embedParsers.channels(settings?.channelIds, language), | ||
inline: false, | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
export const getComponents: CT.SettingsFile<typeof name>['getComponents'] = ( | ||
buttonParsers, | ||
settings, | ||
language, | ||
) => [ | ||
{ | ||
type: Discord.ComponentType.ActionRow, | ||
components: [ | ||
buttonParsers.global(language, !!settings?.active, CT.GlobalDescType.Active, name, undefined), | ||
buttonParsers.specific(language, settings?.cooldown, 'cooldown', name, undefined), | ||
], | ||
}, | ||
{ | ||
type: Discord.ComponentType.ActionRow, | ||
components: [ | ||
buttonParsers.specific( | ||
language, | ||
settings?.roleIds, | ||
'roleIds', | ||
name, | ||
undefined, | ||
CT.EditorTypes.Role, | ||
), | ||
buttonParsers.specific( | ||
language, | ||
settings?.channelIds, | ||
'channelIds', | ||
name, | ||
undefined, | ||
CT.EditorTypes.Channel, | ||
), | ||
], | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/Events/BotEvents/messageEvents/messageCreate/pingReporter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { ButtonStyle, ComponentType, type APIEmbed, type Message } from 'discord.js'; | ||
import Redis from '../../../../BaseClient/Bot/Redis.js'; | ||
|
||
export default async (msg: Message) => { | ||
if (!msg.inGuild()) return; | ||
if (msg.author.bot) return; | ||
if (!msg.mentions.roles.size) return; | ||
|
||
const settings = await msg.client.util.DataBase.pingReport.findUnique({ | ||
where: { | ||
guildid: msg.guildId, | ||
roleIds: { hasSome: msg.mentions.roles.map((r) => r.id) }, | ||
channelIds: { isEmpty: false }, | ||
}, | ||
}); | ||
if (!settings) return; | ||
|
||
const mentionedRoles = msg.mentions.roles.filter((r) => settings.roleIds.includes(r.id)); | ||
if (!mentionedRoles.size) return; | ||
|
||
const cooldownKeys = await Redis.keys(`${process.env.mainId}:ratelimits:*`); | ||
const rolesWithoutCooldown = mentionedRoles.filter( | ||
(r) => !cooldownKeys.find((c) => c.includes(r.id)), | ||
); | ||
if (!rolesWithoutCooldown.size) return; | ||
|
||
const language = await msg.client.util.getLanguage(msg.guildId); | ||
const lan = language.events.messageCreate.pingReporter; | ||
const me = await msg.client.util.getBotMemberFromGuild(msg.guild); | ||
|
||
rolesWithoutCooldown.forEach((role) => { | ||
const members = role.members.map((m) => m.id); | ||
if (members.length > 100) return; | ||
|
||
Redis.setex(`${process.env.mainId}:ratelimits:${role.id}`, Number(settings.cooldown), 'true'); | ||
|
||
const content = members.map((m) => `<@${m}>`).join(' '); | ||
|
||
const embed: APIEmbed = { | ||
author: { name: lan.author }, | ||
description: lan.desc(role, msg.channel, msg.author), | ||
color: msg.client.util.getColor(me), | ||
}; | ||
|
||
msg.client.util.send( | ||
{ id: settings.channelIds, guildId: msg.guildId }, | ||
{ | ||
content, | ||
embeds: [embed], | ||
components: [ | ||
{ | ||
type: ComponentType.ActionRow, | ||
components: [ | ||
{ | ||
type: ComponentType.Button, | ||
style: ButtonStyle.Link, | ||
label: language.t.JumpToMessage, | ||
url: msg.url, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters