chore: documentation, dependency updates, etc.

This commit is contained in:
Ladislav Hano 2024-12-09 15:39:54 +01:00
parent aadad9d0b8
commit 0b95d6f7e5
9 changed files with 64 additions and 8 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

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

@ -1,2 +1,5 @@
pub use birthday::*;
pub use events::*;
pub mod birthday; pub mod birthday;
pub mod events; 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;