Skip to content

Commit

Permalink
updated bot.ts & updated automod and ban command
Browse files Browse the repository at this point in the history
  • Loading branch information
GhomKrosmonaute committed Jul 3, 2024
1 parent 970d80c commit 045aa9b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 36 deletions.
24 changes: 4 additions & 20 deletions src/app/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,16 +530,8 @@ const defaultSystemMessages: SystemMessages = {
allowedMentions,
embeds: [
new discord.EmbedBuilder()
.setTitle(title ? `${getSystemEmoji("success")} ${title}` : null)
.setAuthor(
author
? {
name: title
? author.name
: `${getSystemEmoji("success")} ${author.name}`,
}
: null,
)
.setTitle(title ?? null)
.setAuthor(author ?? null)
.setDescription(
description
? title || author
Expand Down Expand Up @@ -582,16 +574,8 @@ const defaultSystemMessages: SystemMessages = {
allowedMentions,
embeds: [
new discord.EmbedBuilder()
.setTitle(title ? `${getSystemEmoji("error")} ${title}` : null)
.setAuthor(
author
? {
name: title
? author.name
: `${getSystemEmoji("error")} ${author.name}`,
}
: null,
)
.setTitle(title ?? null)
.setAuthor(author ?? null)
.setDescription(
description
? title || author
Expand Down
19 changes: 15 additions & 4 deletions src/commands/ban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,24 @@ export default new app.Command({
},
],
async run(message) {
const result = await app.globalBan(message.args.target, message.args.reason)
const result = await app.globalBan(
message.author,
message.args.target,
message.args.reason,
)

const fails = result.filter((r) => r.status === "rejected")

await app.sendLog(
message.guild,
`**${message.args.target.tag}** has been banned by **${message.author.tag}** from **${result.length - fails.length}** labs.\nReason: ${message.args.reason}`,
if (fails.length === result.length) {
return message.reply(
`${app.emote(message, "Cross")} Failed to ban the user from all labs.`,
)
}

return message.reply(
`${app.emote(message, "CheckMark")} Banned the user from **${
result.length - fails.length
}** labs.`,
)
},
})
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Config } from "#app"
import { Config, getSystemMessage } from "#app"

import { Emotes } from "#src/namespaces/emotes.ts"

Expand Down
25 changes: 14 additions & 11 deletions src/namespaces/automod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ export async function detectAndBanSpammer(message: app.Message) {
if (!config || !config.auto_ban_channel_id) return

if (message.channel.id === config.auto_ban_channel_id) {
const result = await globalBan(message.author, "Spamming")
const result = await globalBan(
message.client.user,
message.author,
`Spamming in ${message.guild!.name}`,
)

if (config.general_channel_id) {
const general = message.client.channels.cache.get(
Expand Down Expand Up @@ -122,10 +126,11 @@ export async function detectAndBanSpammer(message: app.Message) {
// }

export async function globalBan(
user: discord.PartialUser | discord.User,
author: discord.PartialUser | discord.User,
target: discord.PartialUser | discord.User,
reason: string,
) {
const guilds = user.client.guilds.cache.filter((guild) =>
const guilds = target.client.guilds.cache.filter((guild) =>
guild.members.me?.permissions.has("BanMembers", true),
)

Expand All @@ -141,25 +146,23 @@ export async function globalBan(
if (!config || !labs.includes(config._id)) return

try {
await guild.bans.create(user.id, {
await guild.bans.create(target.id, {
reason,
// delete all messages from the user in the last 5 hours
deleteMessageSeconds: 60 * 60 * 5,
})

await app.sendLog(
guild,
`**${user.tag}** has been banned here for **${reason.toLowerCase()}**.`,
`**${target.tag}** has been banned by **${author.tag}**.\nReason: ${reason.toLowerCase()}`,
)
} catch (error: any) {
await app.sendLog(
guild,
`**${user.tag}** could not be banned for **${reason.toLowerCase()}**...${await app.code.stringify(
{
content: error.message,
lang: "js",
},
)}`,
`**${target.tag}** could not be banned...${await app.code.stringify({
content: error.message,
lang: "js",
})}`,
)

throw error
Expand Down

0 comments on commit 045aa9b

Please sign in to comment.