added more config options & made python type-safe(r).
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use rand::{seq::IteratorRandom, Rng};
|
||||
|
||||
use crate::{lang, messages::send_msg, Context, Error};
|
||||
use crate::{data::get_toml_mutex, lang, messages::send_msg, Context, Error};
|
||||
|
||||
|
||||
#[poise::command(
|
||||
@@ -16,14 +16,15 @@ pub async fn cmd(
|
||||
#[description = "Question to ask."] question: String
|
||||
) -> Result<(), Error>
|
||||
{
|
||||
let is_quirky = rand::rng().random_bool(0.2);
|
||||
let quirky_chance = get_toml_mutex(&ctx.data().cfg).await.unwrap()["commands"]["eight_ball_quirky_chance"].as_float().unwrap();
|
||||
let is_quirky = rand::rng().random_bool(quirky_chance.clamp(0.0, 1.0));
|
||||
let list = &ctx.data().ball_prompts[if is_quirky { 1 } else { 0 }];
|
||||
let rand_item = list.iter().choose(&mut rand::rng());
|
||||
|
||||
send_msg(
|
||||
ctx,
|
||||
lang!("dc_msg_8-ball_answer", question, rand_item.unwrap()),
|
||||
true,
|
||||
false,
|
||||
true
|
||||
).await;
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use serde_json::json;
|
||||
|
||||
use crate::{data::{get_toml_mutex, read_cfg_data}, lang, messages::send_msg, websocket::send_cmd_json, Context, Error};
|
||||
use crate::{data::{self, get_toml_mutex, read_cfg_data}, lang, messages::send_msg, Context, Error};
|
||||
|
||||
|
||||
#[poise::command(
|
||||
@@ -16,13 +14,15 @@ pub async fn cmd(
|
||||
ctx: Context<'_>
|
||||
) -> Result<(), Error>
|
||||
{
|
||||
read_cfg_data(&ctx.data(), false).await;
|
||||
let r = read_cfg_data(&ctx.data(), false).await;
|
||||
let d = get_toml_mutex(&ctx.data().cfg).await.unwrap();
|
||||
let d_str = toml::to_string(&d)?;
|
||||
let r = send_cmd_json("update_cfg", Some(json!([d_str])), true).await;
|
||||
|
||||
if r.is_none() { return Ok(()); }
|
||||
|
||||
let data_binding = get_toml_mutex(&ctx.data().cfg).await.unwrap();
|
||||
let lang_cfg = data_binding["general"]["lang"].as_str().unwrap();
|
||||
data::load_lang_data(lang_cfg.to_string());
|
||||
|
||||
if r.unwrap()["value"].as_bool().unwrap() {
|
||||
send_msg(
|
||||
ctx,
|
||||
|
||||
Reference in New Issue
Block a user