Skip to content

Commit

Permalink
Fixed a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill13579 committed Apr 27, 2020
1 parent 6346bca commit 53aed5b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ pub fn strip_stylization(s: &str) -> String {

pub struct Handler {
states: Arc<Vec<State>>,
statusMap: Mutex<HashMap<u64, Option<std::sync::mpsc::Sender<Message>>>>,
statusMap: Arc<Mutex<HashMap<u64, Option<std::sync::mpsc::Sender<Message>>>>>,
db: Arc<Mutex<Connection>>,
}
impl Handler {
pub fn new() -> Handler {
let conn = Connection::open("attrs.db").unwrap();
Handler {
states: Arc::new(Handler::gen_state()),
statusMap: Mutex::new(HashMap::new()),
statusMap: Arc::new(Mutex::new(HashMap::new())),
db: Arc::new(Mutex::new(conn)),
}
}
Expand Down Expand Up @@ -85,7 +85,7 @@ impl Handler {
impl EventHandler for Handler {
fn message(&self, ctx: Context, msg: Message) {
let entry = &mut self.statusMap.lock().unwrap();
let mut entry = entry.entry(msg.channel_id.0).or_insert(None);
let entry = entry.entry(msg.channel_id.0).or_insert(None);
let mut timeout = 0.0;
if let None = entry {
if let State::Trigger(req, t) = &self.states[0] {
Expand All @@ -94,6 +94,7 @@ impl EventHandler for Handler {
let mut i = 1;
let states = self.states.clone();
let db = self.db.clone();
let statusMap = self.statusMap.clone();
let guard = db.lock().unwrap();
let original_user = format!("u{}", msg.author.id.0.to_string());
guard.execute(
Expand Down Expand Up @@ -203,6 +204,8 @@ impl EventHandler for Handler {
timeout = *t;
},
State::End => {
let entry = &mut statusMap.lock().unwrap();
let entry = entry.entry(msg.channel_id.0).or_insert(None);
*entry = None;
break;
}
Expand Down

0 comments on commit 53aed5b

Please sign in to comment.