added logging honeypot

This commit is contained in:
liyunze 2026-06-18 13:24:24 +10:00
parent 746d019a05
commit 6bf8e0c99d
2 changed files with 38 additions and 17 deletions

View file

@ -1,11 +1,10 @@
use crate::{Context, Error};
use dotenv::dotenv;
use poise::CreateReply;
use serenity::{all::CreateEmbed, builder::CreateMessage, model::id::ChannelId};
use poise::{serenity_prelude as serenity, CreateReply};
/// Send message to logs channel
pub async fn log_embed(
ctx: Context<'_>,
ctx: &serenity::Context,
title: Option<String>,
title_url: Option<String>,
description: Option<String>,
@ -16,7 +15,7 @@ pub async fn log_embed(
timestamp: Option<bool>,
) -> Result<(), Error> {
dotenv().ok();
let mut embed = CreateEmbed::new();
let mut embed = serenity::CreateEmbed::new();
// Set title and title URL
if let Some(title) = title {
@ -33,7 +32,7 @@ pub async fn log_embed(
// Set footer
if let Some(footer_text) = footer {
embed = embed.footer(serenity::all::CreateEmbedFooter::new(footer_text));
embed = embed.footer(serenity::CreateEmbedFooter::new(footer_text));
}
// Set color (parse hex color)
@ -55,7 +54,7 @@ pub async fn log_embed(
// Set timestamp
if timestamp.unwrap_or(false) {
embed = embed.timestamp(serenity::model::Timestamp::now());
embed = embed.timestamp(serenity::Timestamp::now());
}
// Send the embed
@ -63,8 +62,8 @@ pub async fn log_embed(
.expect("missing LOGS_CHANNEL_ID")
.parse::<u64>()
.expect("Invalid LOGS_CHANNEL_ID value");
let logs_channel_id = ChannelId::new(logs_channel_id_env);
let builder = CreateMessage::new().embed(embed);
let logs_channel_id = serenity::ChannelId::new(logs_channel_id_env);
let builder = serenity::CreateMessage::new().embed(embed);
let send_log = logs_channel_id.send_message(ctx, builder).await;
send_log.expect("LOG FAIL");
@ -89,7 +88,7 @@ pub async fn embed(
#[description = "Image URL"] image_url: Option<String>,
#[description = "Show timestamp"] timestamp: Option<bool>,
) -> Result<(), Error> {
let mut embed = CreateEmbed::new();
let mut embed = serenity::CreateEmbed::new();
// Set title and title URL
if let Some(title) = title {
@ -106,7 +105,7 @@ pub async fn embed(
// Set footer
if let Some(footer_text) = footer {
embed = embed.footer(serenity::all::CreateEmbedFooter::new(footer_text));
embed = embed.footer(serenity::CreateEmbedFooter::new(footer_text));
}
// Set color (parse hex color)
@ -128,7 +127,7 @@ pub async fn embed(
// Set timestamp
if timestamp.unwrap_or(false) {
embed = embed.timestamp(serenity::model::Timestamp::now());
embed = embed.timestamp(serenity::Timestamp::now());
}
// Send the embed

View file

@ -1,15 +1,18 @@
use crate::Error;
use crate::{Error, commands::mods_only::log_embed};
use ::serenity::model::id::{ChannelId, GuildId};
use dotenv::dotenv;
use poise::serenity_prelude as serenity;
use ::serenity::model::id::{ChannelId, GuildId};
pub async fn on_message(
ctx: &serenity::Context,
new_message: &serenity::Message
new_message: &serenity::Message,
) -> Result<(), Error> {
dotenv().ok();
// check if it's the honeypot channel
let discord_guild_id = std::env::var("GUILD_ID").expect("missing GUILD_ID").parse::<u64>().expect("Invalid GUILD_ID value");
let discord_guild_id = std::env::var("GUILD_ID")
.expect("missing GUILD_ID")
.parse::<u64>()
.expect("Invalid GUILD_ID value");
let honeypot_channel_id_env = std::env::var("HONEYPOT_CHANNEL_ID")
.expect("missing HONEYPOT_CHANNEL_ID")
@ -20,8 +23,27 @@ pub async fn on_message(
if honeypot_channel_id.eq(current_channel_id) {
let user = &new_message.author;
let ban_user = GuildId::new(discord_guild_id).ban_with_reason(ctx, user, 2, "Message sent in honeypot channel.").await;
ban_user.expect("Failed to ban user");
let username = &user.name;
let user_id = &user.id;
let avatar_url = user.avatar_url();
let ban_user = GuildId::new(discord_guild_id)
.ban_with_reason(ctx, user_id, 2, "Message sent in honeypot channel.")
.await;
if ban_user.is_ok() {
log_embed(
ctx,
Some("Honeypot activated!".to_string()),
None,
Some(format!("User got banned: {}", username)),
Some(format!("ID: {}", user_id)),
None,
avatar_url,
None,
Some(true),
)
.await?;
}
}
Ok(())