Skip to content

Commit 42c9db8

Browse files
authored
Update honeypotService.js
1 parent 7e98da8 commit 42c9db8

1 file changed

Lines changed: 37 additions & 21 deletions

File tree

src/services/honeypotService.js

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ const HONEYPOT_IMAGE = 'https://honeypot.riskymh.dev/honeypot.png';
99
export async function getHoneypotConfig(guildId) {
1010
try {
1111
const data = await getFromDb(getHoneypotKey(guildId), null);
12-
return data || { channelId: null, enabled: false, banCount: 0 };
12+
return data || { channelId: null, enabled: false, banCount: 0, method: 'ban' };
1313
} catch (err) {
1414
logger.error(`Failed to get honeypot config for ${guildId}:`, err);
15-
return { channelId: null, enabled: false, banCount: 0 };
15+
return { channelId: null, enabled: false, banCount: 0, method: 'ban' };
1616
}
1717
}
1818

@@ -26,24 +26,25 @@ export async function setHoneypotConfig(guildId, config) {
2626
}
2727
}
2828

29-
export function buildHoneypotWarningEmbed(banCount = 0) {
29+
export function buildHoneypotWarningEmbed(method = 'ban') {
3030
return new EmbedBuilder()
3131
.setColor(0xFF0000)
3232
.setTitle('DO NOT SEND MESSAGES IN THIS CHANNEL')
3333
.setDescription(
3434
'This channel is used to catch spam bots and scammers.\n' +
35-
'Any messages sent here will result in a **ban**.',
35+
`Any messages sent here will result in a **${method}**.`,
3636
)
3737
.setThumbnail(HONEYPOT_IMAGE);
3838
}
3939

40-
export function buildHoneypotComponents(banCount = 0) {
40+
export function buildHoneypotComponents(banCount = 0, method = 'ban') {
41+
const label = method === 'kick' ? `🍯 Kicks: ${banCount}` : `🍯 Bans: ${banCount}`;
4142
return new ActionRowBuilder().addComponents(
4243
new ButtonBuilder()
43-
.setCustomId('honeypot_ban_count')
44-
.setLabel(`🍯 Kicks: ${banCount}`)
44+
.setCustomId('honeypot_action_count')
45+
.setLabel(label)
4546
.setStyle(ButtonStyle.Danger)
46-
.setDisabled(true),
47+
.setDisabled(true),
4748
);
4849
}
4950

@@ -59,35 +60,50 @@ export async function refreshHoneypotMessage(client, guildId) {
5960
if (!msg) return;
6061

6162
await msg.edit({
62-
embeds: [buildHoneypotWarningEmbed(config.banCount)],
63-
components: [buildHoneypotComponents(config.banCount)],
63+
embeds: [buildHoneypotWarningEmbed(config.method || 'ban')],
64+
components: [buildHoneypotComponents(config.banCount, config.method || 'ban')],
6465
});
6566
} catch (err) {
6667
logger.error(`Honeypot: failed to refresh warning message in guild ${guildId}:`, err);
6768
}
6869
}
6970

70-
7171
export async function handleHoneypotMessage(message, client) {
7272
const { guild, author } = message;
73+
7374
await message.delete().catch(() => null);
75+
7476
const botMember = guild.members.me;
77+
const config = await getHoneypotConfig(guild.id);
78+
const method = config.method || 'ban';
7579

7680
try {
77-
await ModerationService.banUser({
78-
guild,
79-
user: author,
80-
moderator: botMember,
81-
reason: 'Honeypot triggered — sent a message in a protected channel.',
82-
deleteDays: 1,
83-
});
81+
if (method === 'kick') {
82+
const member = await guild.members.fetch(author.id).catch(() => null);
83+
if (member) {
84+
await ModerationService.kickUser({
85+
guild,
86+
member,
87+
moderator: botMember,
88+
reason: 'Honeypot triggered — sent a message in a protected channel.',
89+
});
90+
}
91+
logger.info(`Honeypot: kicked ${author.tag} (${author.id}) in guild ${guild.id}`);
92+
} else {
93+
await ModerationService.banUser({
94+
guild,
95+
user: author,
96+
moderator: botMember,
97+
reason: 'Honeypot triggered — sent a message in a protected channel.',
98+
deleteDays: 1,
99+
});
100+
logger.info(`Honeypot: banned ${author.tag} (${author.id}) in guild ${guild.id}`);
101+
}
84102

85-
logger.info(`Honeypot: banned ${author.tag} (${author.id}) in guild ${guild.id}`);
86-
const config = await getHoneypotConfig(guild.id);
87103
const newCount = (config.banCount || 0) + 1;
88104
await setHoneypotConfig(guild.id, { ...config, banCount: newCount });
89105
await refreshHoneypotMessage(client, guild.id);
90106
} catch (err) {
91-
logger.error(`Honeypot: failed to ban ${author.tag} in guild ${guild.id}:`, err);
107+
logger.error(`Honeypot: failed to ${method} ${author.tag} in guild ${guild.id}:`, err);
92108
}
93109
}

0 commit comments

Comments
 (0)