chore: documentation, dependency updates, etc.

This commit is contained in:
Ladislav Hano 2024-12-07 13:07:24 +01:00
parent d3acda2eeb
commit 47976b822b
10 changed files with 74 additions and 16 deletions

10
.env.example Normal file
View file

@ -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

16
Cargo.lock generated
View file

@ -61,9 +61,9 @@ dependencies = [
[[package]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.89" version = "1.0.94"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" checksum = "c1fd03a028ef38ba2276dce7e33fcd6369c158a1bca17946c4b1b701891c1ff7"
[[package]] [[package]]
name = "arrayvec" name = "arrayvec"
@ -1611,9 +1611,9 @@ dependencies = [
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.11.0" version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
@ -2001,9 +2001,9 @@ dependencies = [
[[package]] [[package]]
name = "serenity" name = "serenity"
version = "0.12.2" version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "880a04106592d0a8f5bdacb1d935889bfbccb4a14f7074984d9cd857235d34ac" checksum = "3d72ec4323681bf9a3cabe40fd080abc2435859b502a1b5aa9bf693f125bfa76"
dependencies = [ dependencies = [
"arrayvec", "arrayvec",
"async-trait", "async-trait",
@ -2530,9 +2530,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "1.40.0" version = "1.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" checksum = "5cec9b21b0450273377fc97bd4c33a8acffc8c996c987a7c5b319a0083707551"
dependencies = [ dependencies = [
"backtrace", "backtrace",
"bytes", "bytes",

View file

@ -11,10 +11,10 @@ anyhow = "1.0.89"
tokio-cron-scheduler = "0.13.0" tokio-cron-scheduler = "0.13.0"
dotenv = "0.15.0" dotenv = "0.15.0"
poise = "0.6.1" 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" # serenity_utils = "0.7.0"
tokio = { version = "1.40.0", features = ["macros", "rt-multi-thread"] } tokio = { version = "1.42.0", features = ["macros", "rt-multi-thread"] }
regex = "1.11.0" regex = "1.11.1"
chrono = "0.4.38" chrono = "0.4.38"
sqlx = {version="0.8.2", features=["runtime-tokio", "sqlite"]} sqlx = {version="0.8.2", features=["runtime-tokio", "sqlite"]}
form_urlencoded = "1.2.1" form_urlencoded = "1.2.1"

35
README.md Normal file
View file

@ -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
```

View file

@ -8,5 +8,5 @@ run:
cargo build --features DEBUG cargo build --features DEBUG
./target/debug/moover_rust ./target/debug/moover_rust
run_release: run_rel:
./target/release/moover_rust ./target/release/moover_rust

View file

@ -9,10 +9,9 @@ use tokio::time::sleep;
use regex::Regex; use regex::Regex;
use serenity::model::id::ChannelId; 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<u64> { pub async fn moove_check(msg: &Message) -> Option<u64> {
let word_count = msg.content.trim().split_whitespace().count(); let word_count = msg.content.trim().split_whitespace().count();
let re = Regex::new(r"<#[0-9]*>$").unwrap(); let re = Regex::new(r"<#[0-9]*>$").unwrap();
@ -29,8 +28,11 @@ pub async fn moove_check(msg: &Message) -> Option<u64> {
return Some(channel_id); return Some(channel_id);
} }
/// Move message to new channel (will delete the old message)
pub async fn moove(http: Arc<Http>, msg: Message, m_channel_id: u64) -> anyhow::Result<()> { pub async fn moove(http: Arc<Http>, 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")?; 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 //steals all attachments, but sets all of them as Image urls, so rip actual docs etc

View file

@ -0,0 +1,5 @@
pub use birthday::*;
pub use events::*;
pub mod birthday;
pub mod events;

View file

View file

@ -4,6 +4,8 @@ use tenorv2::tenor_builder::Tenor;
use crate::{types::Context, util::{gifs::get_random_tenor_gif, utilities}}; 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<()> { pub(super) async fn send_with_embed(ctx: Context<'_>, query: &str, title: &str, desc: &str) -> anyhow::Result<()> {
let tenor_response = Tenor::new()? let tenor_response = Tenor::new()?
.random(true) .random(true)

View file

@ -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<Http>) -> anyhow::Result<()> { async fn announce_event(guild_id: GuildId, name: &str, special_message: &str, http: Arc<Http>) -> anyhow::Result<()> {
let mut event_embed = CreateEmbed::new() let mut event_embed = CreateEmbed::new()
@ -46,6 +47,7 @@ async fn announce_event(guild_id: GuildId, name: &str, special_message: &str, ht
Ok(()) Ok(())
} }
/// Send birthday embed to guild's general channel
async fn celebrate_birthday(guild_id: GuildId, user_id: UserId, nick: &str, http: Arc<Http>) -> anyhow::Result<()> { async fn celebrate_birthday(guild_id: GuildId, user_id: UserId, nick: &str, http: Arc<Http>) -> anyhow::Result<()> {
const LIMIT: u8 = 20; const LIMIT: u8 = 20;
@ -98,6 +100,8 @@ struct EventRow {
special_message: String, special_message: String,
} }
/// Fetches guild/global events and birthdays for current day
/// Sends notification to relevant channels
async fn notice(http: Arc<Http>) -> anyhow::Result<()> { async fn notice(http: Arc<Http>) -> anyhow::Result<()> {
use anyhow::Context; use anyhow::Context;