diff --git a/src/config.rs b/src/config.rs index 57cd038..920e563 100644 --- a/src/config.rs +++ b/src/config.rs @@ -78,7 +78,6 @@ pub struct BotState { pub templates: HashMap, pub albums: HashMap>, pub bad_apple_running: bool, - pub story_in_progress: Mutex<()>, } impl BotState { @@ -109,7 +108,6 @@ impl BotState { templates, albums, bad_apple_running: false, - story_in_progress: Mutex::new(()), }) } diff --git a/src/discord/story.rs b/src/discord/story.rs index 9fe8da4..22733f4 100644 --- a/src/discord/story.rs +++ b/src/discord/story.rs @@ -74,24 +74,25 @@ async fn list_stories(ctx: &Context, msg: &Message, _args: Args) -> CommandResul #[only_in(guilds)] #[description("Let me tell you a tail")] async fn story(ctx: &Context, msg: &Message, args: Args) -> CommandResult { - let data = ctx.data.read().await; + let story_channel = { + let data = ctx.data.read().await; + data.get::>().unwrap().clone() + }; - let global_data = data.get::().unwrap(); - - let _story_lock = match global_data.bot_state.story_in_progress.try_lock() { - Ok(lock) => lock, + let mut story_recv = match story_channel.recv.try_lock() { + Ok(story_recv) => story_recv, Err(_) => { - msg.reply(&ctx.http, "Let me finish telling this story bub.") - .await?; + msg.reply(&ctx.http, "Let me finish this story bub").await?; return Ok(()); } }; - let story_channel = data.get::>().unwrap(); + let stories = { + let data = ctx.data.read().await; - let mut story_recv = story_channel.recv.lock().await; - - let stories = get_all_stories(&global_data.cfg).await; + let global_data = data.get::().unwrap(); + get_all_stories(&global_data.cfg).await + }; let story_path = if args.is_empty() { let mut rng = thread_rng(); @@ -162,15 +163,13 @@ async fn story(ctx: &Context, msg: &Message, args: Args) -> CommandResult { #[description("Give me a word")] async fn word(ctx: &Context, msg: &Message, args: Args) -> CommandResult { let data = ctx.data.read().await; - let global = data.get::().unwrap(); + let story_channel = data.get::>().unwrap(); - if global.bot_state.story_in_progress.try_lock().is_ok() { + if story_channel.recv.try_lock().is_ok() { msg.reply(&ctx.http, "No story in progress!").await?; return Ok(()); } - let story_channel = data.get::>().unwrap(); - let story_send = story_channel.send.lock().await; let resp = MessageBuilder::default().push_safe(args.rest()).build(); diff --git a/toml_output.py b/toml_output.py new file mode 100644 index 0000000..d8573c2 --- /dev/null +++ b/toml_output.py @@ -0,0 +1,30 @@ +import tomlkit.items +from tomlkit import parse + + +def parse_templates(cfg, key): + for insult in cfg[key]: + print(f"template\t{insult['template']}") + for k, v in insult["word_bank"].items(): + if type(v) == tomlkit.items.Array: + print(f"{k}\t", end="") + for p in v: + print(f"{p}\t", end="") + print() + else: + print(f"{k}\t{v}") + + +def main(): + with open("config.toml", "r") as f: + o = f.read() + cfg = parse(o) + + parse_templates(cfg, "compliments") + print() + parse_templates(cfg, "insults") + + +if __name__ == "__main__": + main() +