Skip to content

Commit

Permalink
fix:
Browse files Browse the repository at this point in the history
  • Loading branch information
Tricked-dev committed Feb 8, 2024
1 parent 086a218 commit 9746a76
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 8 deletions.
53 changes: 51 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ prisma-client-rust = { git = "https://github.com/Brendonovich/prisma-client-rust
prisma-client-rust-cli = { git = "https://github.com/Brendonovich/prisma-client-rust", tag = "0.6.7", default-features = false, features = [
"sqlite"
] }
dotenv = { version = "0.15.0", features = ["clap"] }
2 changes: 1 addition & 1 deletion src/commands/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub async fn level(ctx: &SlashContext<'_, Arc<Mutex<State>>>) -> CommandResult {
user.level,
pos.unwrap_or_default() + 1,
);

tracing::info!("Level {message}");
ctx.interaction_client
.create_response(
ctx.interaction.id,
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, io, num::ParseIntError, sync::Arc};
use std::{collections::HashMap, io, num::ParseIntError, path::PathBuf, sync::Arc};

use clap::Parser;

Expand All @@ -14,7 +14,7 @@ pub struct Config {
#[arg(long, env, value_parser = vec_u64_parser)]
pub message_indicator_channels: Arc<Vec<u64>>,
#[arg(long, env, default_value = "trickedbot.sqlite")]
pub database_file: String,
pub database_file: PathBuf,
#[arg(short, long, env, default_value = "0")]
pub id: u64,
#[arg(long, env, value_parser(vec_u64_parser))]
Expand Down
20 changes: 17 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use twilight_model::{
};
use zephyrus::prelude::*;

use std::{collections::HashMap, env, error::Error, sync::Arc, time::Duration};
use std::{collections::HashMap, env, error::Error, path, sync::Arc, time::Duration};

Check warning on line 33 in src/main.rs

View workflow job for this annotation

GitHub Actions / build (aarch64-unknown-linux-gnu, aarch64-backend)

unused import: `path`

mod commands;
mod config;
Expand All @@ -48,15 +48,26 @@ const VERSION: &str = env!("CARGO_PKG_VERSION");

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let db: PrismaClient = PrismaClient::_builder().build().await?;
dotenv::dotenv().ok();

tracing_subscriber::fmt().init();
tracing_subscriber::fmt().with_max_level(tracing::Level::DEBUG).init();
let mut cfg = Config::parse();
if cfg.id == 0 {
cfg.id = String::from_utf8_lossy(&base64::decode(cfg.token.split_once('.').unwrap().0).unwrap())
.parse::<u64>()
.unwrap();
}

if std::fs::metadata(&cfg.database_file).is_err() {
std::fs::write(&cfg.database_file, [])?;
}
let db_path = format!(
"file://{}",
cfg.database_file.canonicalize()?.to_string_lossy().to_string()
);

let db: PrismaClient = PrismaClient::_builder().with_url(db_path).build().await?;

let config = Arc::new(cfg);

let client: Client = Client::builder()
Expand Down Expand Up @@ -160,6 +171,7 @@ async fn handle_event(
}
}
Event::InteractionCreate(i) => {
tracing::info!("Slash Command!");
tokio::spawn(async move {
let inner = i.0;
framework.process(inner).await;
Expand Down Expand Up @@ -217,6 +229,8 @@ async fn handle_event(
Event::MessageCreate(msg) => {
tracing::info!("Message received {}", &msg.content.replace('\n', "\\ "));

locked_state.last_typer = msg.id.get();

if msg.guild_id.is_none() || msg.author.bot {
return Ok(());
}
Expand Down

0 comments on commit 9746a76

Please sign in to comment.