From 79809029484eb62b7648a0e73b0e44a8fddcc254 Mon Sep 17 00:00:00 2001 From: Ladislav Hano Date: Mon, 9 Dec 2024 15:39:54 +0100 Subject: [PATCH] chore: documentation, dependency updates, etc. --- .env.example | 10 ++++++ Cargo.lock | 16 ++++----- Cargo.toml | 6 ++-- README.md | 35 +++++++++++++++++++ makefile | 2 +- src/commands/moover/moove.rs | 10 +++--- src/commands/notice/mod.rs | 3 ++ src/commands/other/mod.rs | 0 src/commands/user_interactions/interaction.rs | 2 ++ src/other/notice.rs | 4 +++ 10 files changed, 72 insertions(+), 16 deletions(-) create mode 100644 .env.example create mode 100644 README.md create mode 100644 src/commands/other/mod.rs diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..1363c8f --- /dev/null +++ b/.env.example @@ -0,0 +1,10 @@ +TOKEN=token used for release version +DEBUGTOKEN=token I use for debugging on standalone bot +DBPASS=password for database (currently not used) +DEBUG=ON + +DEBUG_CHANNEL_ID=channel where debug info will be sent +DEBUG_GUILD_ID=guild where local slash commands will be registered + +DATABASE_URL=sqlite://path_to_database +TENORV2_TOKEN=token to tenor API v2 \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index c63ac13..6926099 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,9 +61,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.89" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" +checksum = "c1fd03a028ef38ba2276dce7e33fcd6369c158a1bca17946c4b1b701891c1ff7" [[package]] name = "arrayvec" @@ -1611,9 +1611,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", @@ -2001,9 +2001,9 @@ dependencies = [ [[package]] name = "serenity" -version = "0.12.2" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "880a04106592d0a8f5bdacb1d935889bfbccb4a14f7074984d9cd857235d34ac" +checksum = "3d72ec4323681bf9a3cabe40fd080abc2435859b502a1b5aa9bf693f125bfa76" dependencies = [ "arrayvec", "async-trait", @@ -2530,9 +2530,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.40.0" +version = "1.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" +checksum = "5cec9b21b0450273377fc97bd4c33a8acffc8c996c987a7c5b319a0083707551" dependencies = [ "backtrace", "bytes", diff --git a/Cargo.toml b/Cargo.toml index 359cd1d..1a16780 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,10 +11,10 @@ anyhow = "1.0.89" tokio-cron-scheduler = "0.13.0" dotenv = "0.15.0" poise = "0.6.1" -serenity = { version = "0.12.2", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "http", "cache"] } +serenity = { version = "0.12.4", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "http", "cache"] } # serenity_utils = "0.7.0" -tokio = { version = "1.40.0", features = ["macros", "rt-multi-thread"] } -regex = "1.11.0" +tokio = { version = "1.42.0", features = ["macros", "rt-multi-thread"] } +regex = "1.11.1" chrono = "0.4.38" sqlx = {version="0.8.2", features=["runtime-tokio", "sqlite"]} form_urlencoded = "1.2.1" diff --git a/README.md b/README.md new file mode 100644 index 0000000..7ff7f51 --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +# Discord bot made in rust + +## Current feature list: + - move message from one channel to another + - send hug and headpat embed and tag user in it + - announces events and birthdays that are in database + +## Technologies used + - Discord API - serenity, poise + - Database - sqlite + - gifs - my partial implementation of tenor API + +## Compilation +Make sure you have cargo installed! +Edit .env.example and rename to .env + +Compile debug version +``` +make dev +``` + +Compile release version +``` +make release +``` + +Compile debug version and run it +``` +make run +``` + +Run release version +``` +make run_rel +``` diff --git a/makefile b/makefile index e16831f..7815468 100644 --- a/makefile +++ b/makefile @@ -8,5 +8,5 @@ run: cargo build --features DEBUG ./target/debug/moover_rust -run_release: +run_rel: ./target/release/moover_rust \ No newline at end of file diff --git a/src/commands/moover/moove.rs b/src/commands/moover/moove.rs index 85539d8..046e433 100644 --- a/src/commands/moover/moove.rs +++ b/src/commands/moover/moove.rs @@ -9,10 +9,9 @@ use tokio::time::sleep; use regex::Regex; use serenity::model::id::ChannelId; -// Checks if the message should be mooved -// If the message should be mooved, try to move it and return Ok if mooved succesfully -// else returns Err() +/// Checks if the message should be mooved +/// If the message should be mooved, try to move it and return Ok if mooved succesfully pub async fn moove_check(msg: &Message) -> Option { let word_count = msg.content.trim().split_whitespace().count(); let re = Regex::new(r"<#[0-9]*>$").unwrap(); @@ -29,8 +28,11 @@ pub async fn moove_check(msg: &Message) -> Option { return Some(channel_id); } +/// Move message to new channel (will delete the old message) pub async fn moove(http: Arc, msg: Message, m_channel_id: u64) -> anyhow::Result<()> { - // this should be in moove_check, but I need to find a good way to return in with channel_id + msg.react(http.clone(), '🐮').await?; + + // this should be in moove_check, but I need to find a good way to return it with channel_id let msg_to_moove = msg.clone().referenced_message.context("Referenced message not found")?; //steals all attachments, but sets all of them as Image urls, so rip actual docs etc diff --git a/src/commands/notice/mod.rs b/src/commands/notice/mod.rs index ef275cb..d63767d 100644 --- a/src/commands/notice/mod.rs +++ b/src/commands/notice/mod.rs @@ -1,2 +1,5 @@ +pub use birthday::*; +pub use events::*; + pub mod birthday; pub mod events; \ No newline at end of file diff --git a/src/commands/other/mod.rs b/src/commands/other/mod.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/commands/user_interactions/interaction.rs b/src/commands/user_interactions/interaction.rs index 439ef72..6db121a 100644 --- a/src/commands/user_interactions/interaction.rs +++ b/src/commands/user_interactions/interaction.rs @@ -4,6 +4,8 @@ use tenorv2::tenor_builder::Tenor; use crate::{types::Context, util::{gifs::get_random_tenor_gif, utilities}}; +/// Sends embed with random tenor gif from searched query +/// title and desc are used in the embed pub(super) async fn send_with_embed(ctx: Context<'_>, query: &str, title: &str, desc: &str) -> anyhow::Result<()> { let tenor_response = Tenor::new()? .random(true) diff --git a/src/other/notice.rs b/src/other/notice.rs index 2294637..69b39ed 100644 --- a/src/other/notice.rs +++ b/src/other/notice.rs @@ -24,6 +24,7 @@ pub async fn notice_wrapper(ctx: Context) { } } +/// Send embed with event name and optional special message to guild's general channel async fn announce_event(guild_id: GuildId, name: &str, special_message: &str, http: Arc) -> anyhow::Result<()> { let mut event_embed = CreateEmbed::new() @@ -46,6 +47,7 @@ async fn announce_event(guild_id: GuildId, name: &str, special_message: &str, ht Ok(()) } +/// Send birthday embed to guild's general channel async fn celebrate_birthday(guild_id: GuildId, user_id: UserId, nick: &str, http: Arc) -> anyhow::Result<()> { const LIMIT: u8 = 20; @@ -98,6 +100,8 @@ struct EventRow { special_message: String, } +/// Fetches guild/global events and birthdays for current day +/// Sends notification to relevant channels async fn notice(http: Arc) -> anyhow::Result<()> { use anyhow::Context;