-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
441 additions
and
18 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[workspace] | ||
members = ["discord","material","image-edit","binding"] | ||
members = ["discord","material","image-edit","binding", "test-bot"] | ||
resolver = "2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#![allow(unused)] | ||
|
||
use std::{collections::HashMap, path::Path, sync::Arc}; | ||
use crate::postgres::custom; | ||
use super::*; | ||
|
||
#[derive(Serialize,Deserialize,Clone,Default)] | ||
pub struct BBQConfig { | ||
pub description:String, | ||
pub cooldown_timer:u32, | ||
pub public_cooldown :Option<u32>, | ||
pub icon:String, | ||
pub thumbnail:String, | ||
pub rules:Vec<String>, | ||
pub solo:BountyReward, | ||
pub multi:BountyReward | ||
} | ||
|
||
|
||
|
||
impl Category { | ||
pub fn name(&self) -> &'static str { | ||
match self { | ||
Self::Gold => "gold", | ||
Self::Free => "free", | ||
Self::Event => "event", | ||
Self::Bronze => "bronze", | ||
Self::Silver => "silver", | ||
Self::Custom => "Custom", | ||
} | ||
} | ||
pub fn config_name(&self) -> String { | ||
format!("bounty_{}.json",self.name()) | ||
} | ||
pub async fn load(&self) -> Result<HashMap<BBQ,BBQConfig>,BountyErr> { | ||
let path = Path::new(".").join("static").join(&self.config_name()); | ||
Ok(serde_json::from_slice(&tokio::fs::read(path).await?)?) | ||
} | ||
} | ||
|
||
impl title::Title { | ||
pub async fn load(&self) -> Result<Self,BountyErr> { | ||
let path = Path::new(".").join("static").join("title.json"); | ||
Ok(serde_json::from_slice(&tokio::fs::read(path).await?)?) | ||
} | ||
} | ||
|
||
struct Cooldown(HashMap<BBQ,u32>); | ||
|
||
impl From<HashMap<BBQ,BBQConfig>> for Cooldown { | ||
fn from(value: HashMap<BBQ,BBQConfig>) -> Self { | ||
Cooldown(value.into_iter() | ||
.map(|(k,v)|(k,v.public_cooldown.unwrap_or(999))) | ||
.collect()) | ||
} | ||
} | ||
|
||
|
||
impl BountyGlobal { | ||
pub fn create() -> Arc<Self> { | ||
Arc::new(Self { cooldown: Mutex::new(HashMap::new()), submision: Mutex::new(HashMap::new()) }) | ||
} | ||
pub async fn refresh(&self) -> Result<(),BountyErr> { | ||
let free = Category::Free.load().await?; | ||
let new_cd:Cooldown = free.into(); | ||
*self.cooldown.lock().await = new_cd.0; | ||
Ok(()) | ||
} | ||
pub async fn caching(&self) -> Result<(),BountyErr> { | ||
let data = self.submision.lock().await; | ||
let path = Path::new(".").join("CACHE"); | ||
tokio::fs::write(path, serde_json::to_string(&*data)?.as_bytes()).await?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "test-bot" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
dotenv = "0.15.0" | ||
poise = { version = "0.5.7", features = ["time", "collector"] } | ||
serenity = { version = "0.12.0", features = ["client", "gateway", "rustls_backend", "model", "collector"] } | ||
tokio = { version = "1.35.0", features = ["full"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#![allow(unused)] | ||
use dotenv::{dotenv,var}; | ||
use poise::{serenity_prelude as serenity, CreateReply}; | ||
use ::serenity::futures::future::ok; | ||
|
||
struct Data; | ||
|
||
type Error = Box<dyn std::error::Error + Send + Sync>; | ||
type Context<'a> = poise::Context<'a,Data,Error>; | ||
|
||
#[poise::command(slash_command,prefix_command)] | ||
async fn ping(ctx:Context<'_>) -> Result<(),Error> { | ||
ctx.say("pong").await?; | ||
Ok(()) | ||
} | ||
#[poise::command(slash_command,prefix_command)] | ||
async fn error(ctx:Context<'_>) -> Result<(),Error> { | ||
ctx.say("a".parse::<u8>()?.to_string()).await?; | ||
Ok(()) | ||
} | ||
|
||
async fn on_error(err:poise::FrameworkError<'_,Data,Error>) { | ||
match err { | ||
poise::FrameworkError::Setup { error, .. } => { | ||
panic!("failed to setup with err messages {error:?}") | ||
} | ||
poise::FrameworkError::Command { error, ctx } => { | ||
ctx.say("this can be error").await; | ||
} | ||
error => { | ||
if let Err(e) = poise::builtins::on_error(error).await { | ||
println!("Error while handling error: {}", e) | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
dotenv(); | ||
let token = var("TOKEN") | ||
.expect("cant find token in .env"); | ||
|
||
let opt = poise::FrameworkOptions { | ||
commands:vec![ping(),error()], | ||
on_error: |err| Box::pin(on_error(err)), | ||
..Default::default() | ||
}; | ||
} |