mirror of
https://github.com/dsec-hub/dsec-discord-bot.git
synced 2026-09-22 07:44:26 +00:00
added logging honeypot
This commit is contained in:
parent
746d019a05
commit
6bf8e0c99d
2 changed files with 38 additions and 17 deletions
|
|
@ -1,11 +1,10 @@
|
||||||
use crate::{Context, Error};
|
use crate::{Context, Error};
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
use poise::CreateReply;
|
use poise::{serenity_prelude as serenity, CreateReply};
|
||||||
use serenity::{all::CreateEmbed, builder::CreateMessage, model::id::ChannelId};
|
|
||||||
|
|
||||||
/// Send message to logs channel
|
/// Send message to logs channel
|
||||||
pub async fn log_embed(
|
pub async fn log_embed(
|
||||||
ctx: Context<'_>,
|
ctx: &serenity::Context,
|
||||||
title: Option<String>,
|
title: Option<String>,
|
||||||
title_url: Option<String>,
|
title_url: Option<String>,
|
||||||
description: Option<String>,
|
description: Option<String>,
|
||||||
|
|
@ -16,7 +15,7 @@ pub async fn log_embed(
|
||||||
timestamp: Option<bool>,
|
timestamp: Option<bool>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
let mut embed = CreateEmbed::new();
|
let mut embed = serenity::CreateEmbed::new();
|
||||||
|
|
||||||
// Set title and title URL
|
// Set title and title URL
|
||||||
if let Some(title) = title {
|
if let Some(title) = title {
|
||||||
|
|
@ -33,7 +32,7 @@ pub async fn log_embed(
|
||||||
|
|
||||||
// Set footer
|
// Set footer
|
||||||
if let Some(footer_text) = 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)
|
// Set color (parse hex color)
|
||||||
|
|
@ -55,7 +54,7 @@ pub async fn log_embed(
|
||||||
|
|
||||||
// Set timestamp
|
// Set timestamp
|
||||||
if timestamp.unwrap_or(false) {
|
if timestamp.unwrap_or(false) {
|
||||||
embed = embed.timestamp(serenity::model::Timestamp::now());
|
embed = embed.timestamp(serenity::Timestamp::now());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the embed
|
// Send the embed
|
||||||
|
|
@ -63,8 +62,8 @@ pub async fn log_embed(
|
||||||
.expect("missing LOGS_CHANNEL_ID")
|
.expect("missing LOGS_CHANNEL_ID")
|
||||||
.parse::<u64>()
|
.parse::<u64>()
|
||||||
.expect("Invalid LOGS_CHANNEL_ID value");
|
.expect("Invalid LOGS_CHANNEL_ID value");
|
||||||
let logs_channel_id = ChannelId::new(logs_channel_id_env);
|
let logs_channel_id = serenity::ChannelId::new(logs_channel_id_env);
|
||||||
let builder = CreateMessage::new().embed(embed);
|
let builder = serenity::CreateMessage::new().embed(embed);
|
||||||
|
|
||||||
let send_log = logs_channel_id.send_message(ctx, builder).await;
|
let send_log = logs_channel_id.send_message(ctx, builder).await;
|
||||||
send_log.expect("LOG FAIL");
|
send_log.expect("LOG FAIL");
|
||||||
|
|
@ -89,7 +88,7 @@ pub async fn embed(
|
||||||
#[description = "Image URL"] image_url: Option<String>,
|
#[description = "Image URL"] image_url: Option<String>,
|
||||||
#[description = "Show timestamp"] timestamp: Option<bool>,
|
#[description = "Show timestamp"] timestamp: Option<bool>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let mut embed = CreateEmbed::new();
|
let mut embed = serenity::CreateEmbed::new();
|
||||||
|
|
||||||
// Set title and title URL
|
// Set title and title URL
|
||||||
if let Some(title) = title {
|
if let Some(title) = title {
|
||||||
|
|
@ -106,7 +105,7 @@ pub async fn embed(
|
||||||
|
|
||||||
// Set footer
|
// Set footer
|
||||||
if let Some(footer_text) = 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)
|
// Set color (parse hex color)
|
||||||
|
|
@ -128,7 +127,7 @@ pub async fn embed(
|
||||||
|
|
||||||
// Set timestamp
|
// Set timestamp
|
||||||
if timestamp.unwrap_or(false) {
|
if timestamp.unwrap_or(false) {
|
||||||
embed = embed.timestamp(serenity::model::Timestamp::now());
|
embed = embed.timestamp(serenity::Timestamp::now());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the embed
|
// Send the embed
|
||||||
|
|
|
||||||
|
|
@ -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 dotenv::dotenv;
|
||||||
use poise::serenity_prelude as serenity;
|
use poise::serenity_prelude as serenity;
|
||||||
use ::serenity::model::id::{ChannelId, GuildId};
|
|
||||||
|
|
||||||
pub async fn on_message(
|
pub async fn on_message(
|
||||||
ctx: &serenity::Context,
|
ctx: &serenity::Context,
|
||||||
new_message: &serenity::Message
|
new_message: &serenity::Message,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
// check if it's the honeypot channel
|
// 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")
|
let honeypot_channel_id_env = std::env::var("HONEYPOT_CHANNEL_ID")
|
||||||
.expect("missing 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) {
|
if honeypot_channel_id.eq(current_channel_id) {
|
||||||
let user = &new_message.author;
|
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;
|
let username = &user.name;
|
||||||
ban_user.expect("Failed to ban user");
|
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(())
|
Ok(())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue