mirror of
https://github.com/dsec-hub/dsec-discord-bot.git
synced 2026-09-22 07:44:26 +00:00
added honeypot and send log
This commit is contained in:
parent
4fb7280680
commit
746d019a05
6 changed files with 117 additions and 13 deletions
14
.env.example
14
.env.example
|
|
@ -1,10 +1,10 @@
|
|||
DISCORD_TOKEN=""
|
||||
SUPABASE_URL=""
|
||||
SUPABASE_KEY=""
|
||||
|
||||
# Optional
|
||||
VERIFIED_ROLE_ID=""
|
||||
GUILD_ID=""
|
||||
WEATHER_TOKEN=""
|
||||
|
||||
# Weather API token from: https://www.weatherapi.com/
|
||||
VERIFIED_ROLE_ID=""
|
||||
GUILD_ID=""
|
||||
LOGS_CHANNEL_ID=""
|
||||
HONEYPOT_CHANNEL_ID=""
|
||||
|
||||
SUPABASE_URL=""
|
||||
SUPABASE_KEY=""
|
||||
|
|
|
|||
|
|
@ -1,6 +1,76 @@
|
|||
use crate::{Context, Error};
|
||||
use dotenv::dotenv;
|
||||
use poise::CreateReply;
|
||||
use serenity::all::CreateEmbed;
|
||||
use serenity::{all::CreateEmbed, builder::CreateMessage, model::id::ChannelId};
|
||||
|
||||
/// Send message to logs channel
|
||||
pub async fn log_embed(
|
||||
ctx: Context<'_>,
|
||||
title: Option<String>,
|
||||
title_url: Option<String>,
|
||||
description: Option<String>,
|
||||
footer: Option<String>,
|
||||
colour: Option<String>,
|
||||
thumbnail_url: Option<String>,
|
||||
image_url: Option<String>,
|
||||
timestamp: Option<bool>,
|
||||
) -> Result<(), Error> {
|
||||
dotenv().ok();
|
||||
let mut embed = CreateEmbed::new();
|
||||
|
||||
// Set title and title URL
|
||||
if let Some(title) = title {
|
||||
embed = embed.title(title);
|
||||
if let Some(url) = title_url {
|
||||
embed = embed.url(url);
|
||||
}
|
||||
}
|
||||
|
||||
// Set description
|
||||
if let Some(desc) = description {
|
||||
embed = embed.description(desc);
|
||||
}
|
||||
|
||||
// Set footer
|
||||
if let Some(footer_text) = footer {
|
||||
embed = embed.footer(serenity::all::CreateEmbedFooter::new(footer_text));
|
||||
}
|
||||
|
||||
// Set color (parse hex color)
|
||||
if let Some(color_str) = colour {
|
||||
if let Ok(color_value) = u32::from_str_radix(color_str.trim_start_matches('#'), 16) {
|
||||
embed = embed.color(color_value);
|
||||
}
|
||||
}
|
||||
|
||||
// Set thumbnail
|
||||
if let Some(thumb_url) = thumbnail_url {
|
||||
embed = embed.thumbnail(thumb_url);
|
||||
}
|
||||
|
||||
// Set image
|
||||
if let Some(img_url) = image_url {
|
||||
embed = embed.image(img_url);
|
||||
}
|
||||
|
||||
// Set timestamp
|
||||
if timestamp.unwrap_or(false) {
|
||||
embed = embed.timestamp(serenity::model::Timestamp::now());
|
||||
}
|
||||
|
||||
// Send the embed
|
||||
let logs_channel_id_env = std::env::var("LOGS_CHANNEL_ID")
|
||||
.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 send_log = logs_channel_id.send_message(ctx, builder).await;
|
||||
send_log.expect("LOG FAIL");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Create a message embed
|
||||
#[poise::command(
|
||||
|
|
|
|||
|
|
@ -1,2 +1,3 @@
|
|||
pub mod ready;
|
||||
pub mod interaction_create;
|
||||
pub mod interaction_create;
|
||||
pub mod message;
|
||||
|
|
@ -5,8 +5,7 @@ use crate::{
|
|||
commands::verification::{StudentRow, VerificationModal},
|
||||
};
|
||||
use ::serenity::all::{
|
||||
ComponentInteraction, Context, CreateEmbed, CreateEmbedFooter, CreateInteractionResponse,
|
||||
CreateInteractionResponseFollowup, CreateInteractionResponseMessage, GuildId, RoleId,
|
||||
ComponentInteraction, Context, CreateEmbed, CreateEmbedFooter, CreateInteractionResponse, CreateInteractionResponseFollowup, CreateInteractionResponseMessage, GuildId, RoleId
|
||||
};
|
||||
use dotenv::dotenv;
|
||||
use poise::{modal, serenity_prelude as serenity};
|
||||
|
|
@ -205,6 +204,9 @@ pub async fn on_interaction_create(
|
|||
format!("You have been assigned the <@&{}> role!", verified_role_id),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// post to logs channel
|
||||
|
||||
} else {
|
||||
embed_followup(
|
||||
ctx,
|
||||
|
|
|
|||
28
src/events/message.rs
Normal file
28
src/events/message.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
use crate::Error;
|
||||
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
|
||||
) -> 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 honeypot_channel_id_env = std::env::var("HONEYPOT_CHANNEL_ID")
|
||||
.expect("missing HONEYPOT_CHANNEL_ID")
|
||||
.parse::<u64>()
|
||||
.expect("Invalid HONEYPOT_CHANNEL_ID value");
|
||||
let honeypot_channel_id = ChannelId::new(honeypot_channel_id_env);
|
||||
let current_channel_id = &new_message.channel_id;
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -48,6 +48,9 @@ async fn event_handler(
|
|||
serenity::FullEvent::InteractionCreate { interaction } => {
|
||||
events::interaction_create::on_interaction_create(ctx, interaction, &data).await?;
|
||||
}
|
||||
serenity::FullEvent::Message { new_message } => {
|
||||
events::message::on_message(ctx, new_message).await?;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
Ok(())
|
||||
|
|
@ -61,7 +64,7 @@ async fn main() {
|
|||
|
||||
// -- discord bot start --
|
||||
let token = std::env::var("DISCORD_TOKEN").expect("missing DISCORD_TOKEN");
|
||||
let intents = serenity::GatewayIntents::non_privileged();
|
||||
let intents = serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT;
|
||||
|
||||
let framework = poise::Framework::builder()
|
||||
.options(poise::FrameworkOptions {
|
||||
|
|
@ -96,7 +99,7 @@ async fn main() {
|
|||
.expect("Client failed to start")
|
||||
.start()
|
||||
.await
|
||||
.expect("Client failed to start 2");
|
||||
.expect("Client failed to start");
|
||||
|
||||
// -- discord bot end --
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue