Fixed stories

+ Removed story mutex, using the channel mutex instead
+ clippy + fmt
This commit is contained in:
2022-12-31 23:28:53 -06:00
parent 7c9cb2a81f
commit 35f157b42a
3 changed files with 44 additions and 17 deletions
+14 -15
View File
@@ -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::<Channel<String>>().unwrap().clone()
};
let global_data = data.get::<GlobalData>().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::<Channel<String>>().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::<GlobalData>().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::<GlobalData>().unwrap();
let story_channel = data.get::<Channel<String>>().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::<Channel<String>>().unwrap();
let story_send = story_channel.send.lock().await;
let resp = MessageBuilder::default().push_safe(args.rest()).build();