check time to kill users that get stuck in executing state
This commit is contained in:
parent
9109250fe8
commit
b31843c478
@ -397,9 +397,7 @@ async fn language(ctx: &Context, msg: &Message, args: String) {
|
||||
async fn prefix(ctx: &Context, msg: &Message, args: String) {
|
||||
let (pool, lm) = get_ctx_data(&ctx).await;
|
||||
|
||||
let mut guild_data = GuildData::from_guild(msg.guild(&ctx).await.unwrap(), &pool)
|
||||
.await
|
||||
.unwrap();
|
||||
let guild_data = ctx.guild_data(msg.guild_id.unwrap()).await.unwrap();
|
||||
let language = UserData::language_of(&msg.author, &pool).await;
|
||||
|
||||
if args.len() > 5 {
|
||||
@ -413,18 +411,15 @@ async fn prefix(ctx: &Context, msg: &Message, args: String) {
|
||||
.say(&ctx, lm.get(&language, "prefix/no_argument"))
|
||||
.await;
|
||||
} else {
|
||||
guild_data.prefix = args;
|
||||
guild_data.write().await.prefix = args;
|
||||
|
||||
#[cfg(feature = "prefix-cache")]
|
||||
let prefix_cache = ctx.data.read().await.get::<PrefixCache>().cloned().unwrap();
|
||||
#[cfg(feature = "prefix-cache")]
|
||||
prefix_cache.insert(msg.guild_id.unwrap(), guild_data.prefix.clone());
|
||||
guild_data.read().await.commit_changes(&pool).await;
|
||||
|
||||
guild_data.commit_changes(&pool).await;
|
||||
|
||||
let content =
|
||||
lm.get(&language, "prefix/success")
|
||||
.replacen("{prefix}", &guild_data.prefix, 1);
|
||||
let content = lm.get(&language, "prefix/success").replacen(
|
||||
"{prefix}",
|
||||
&guild_data.read().await.prefix,
|
||||
1,
|
||||
);
|
||||
|
||||
let _ = msg.channel_id.say(&ctx, content).await;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ use crate::language_manager::LanguageManager;
|
||||
use crate::models::{CtxGuildData, GuildData, UserData};
|
||||
use crate::{models::ChannelData, CurrentlyExecuting, SQLPool};
|
||||
use serenity::model::id::MessageId;
|
||||
use std::time::Duration;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
type CommandFn = for<'fut> fn(&'fut Context, &'fut Message, String) -> BoxFuture<'fut, ()>;
|
||||
|
||||
@ -361,8 +361,10 @@ impl Framework for RegexFramework {
|
||||
{
|
||||
let mut lock = currently_executing.lock().unwrap();
|
||||
|
||||
user_is_executing = lock.contains(&msg.author.id);
|
||||
lock.insert(msg.author.id);
|
||||
user_is_executing = lock
|
||||
.get(&msg.author.id)
|
||||
.map_or(false, |now| now.elapsed().as_secs() < 4);
|
||||
lock.insert(msg.author.id, Instant::now());
|
||||
}
|
||||
|
||||
if !user_is_executing || msg.id == MessageId(0) {
|
||||
@ -532,6 +534,8 @@ impl Framework for RegexFramework {
|
||||
let mut lock = currently_executing.lock().unwrap();
|
||||
lock.remove(&msg.author.id);
|
||||
}
|
||||
} else {
|
||||
warn!("User {} is still executing!", msg.author.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,8 +47,8 @@ use dashmap::DashMap;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use chrono_tz::Tz;
|
||||
use std::collections::HashSet;
|
||||
use std::sync::Mutex;
|
||||
use std::time::Instant;
|
||||
|
||||
struct GuildDataCache;
|
||||
|
||||
@ -83,7 +83,7 @@ impl TypeMapKey for PopularTimezones {
|
||||
struct CurrentlyExecuting;
|
||||
|
||||
impl TypeMapKey for CurrentlyExecuting {
|
||||
type Value = Arc<Mutex<HashSet<UserId>>>;
|
||||
type Value = Arc<Mutex<HashMap<UserId, Instant>>>;
|
||||
}
|
||||
|
||||
struct Handler;
|
||||
@ -317,7 +317,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
let mut data = client.data.write().await;
|
||||
|
||||
data.insert::<GuildDataCache>(Arc::new(guild_data_cache));
|
||||
data.insert::<CurrentlyExecuting>(Arc::new(Mutex::new(HashSet::new())));
|
||||
data.insert::<CurrentlyExecuting>(Arc::new(Mutex::new(HashMap::new())));
|
||||
data.insert::<SQLPool>(pool);
|
||||
data.insert::<PopularTimezones>(Arc::new(popular_timezones));
|
||||
data.insert::<ReqwestClient>(Arc::new(reqwest::Client::new()));
|
||||
|
Loading…
Reference in New Issue
Block a user