From 63368a9437a4b1ec6cc8276678ddfb2258590ab1 Mon Sep 17 00:00:00 2001 From: Devin R Date: Wed, 15 Apr 2020 08:44:29 -0400 Subject: [PATCH] command_bot: remove timestamp --- examples/command_bot.rs | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/examples/command_bot.rs b/examples/command_bot.rs index 20bbf7a1..effd2e7e 100644 --- a/examples/command_bot.rs +++ b/examples/command_bot.rs @@ -1,8 +1,6 @@ use std::sync::Arc; -use std::time::{SystemTime, UNIX_EPOCH}; use std::{env, process::exit}; -use js_int::UInt; use matrix_sdk::{ self, events::room::message::{MessageEvent, MessageEventContent, TextMessageEventContent}, @@ -15,36 +13,28 @@ struct CommandBot { /// This clone of the `AsyncClient` will send requests to the server, /// while the other keeps us in sync with the server using `sync_forever`. client: AsyncClient, - /// A timestamp so we only respond to messages sent after the bot is running. - start_time: UInt, } impl CommandBot { pub fn new(client: AsyncClient) -> Self { - let now = SystemTime::now(); - let timestamp = now.duration_since(UNIX_EPOCH).unwrap().as_millis(); - Self { - client, - start_time: UInt::new(timestamp as u64).unwrap(), - } + Self { client } } } #[async_trait::async_trait] impl EventEmitter for CommandBot { async fn on_room_message(&self, room: Arc>, event: &MessageEvent) { - let (msg_body, timestamp) = if let MessageEvent { + let msg_body = if let MessageEvent { content: MessageEventContent::Text(TextMessageEventContent { body: msg_body, .. }), - origin_server_ts, .. } = event { - (msg_body.clone(), *origin_server_ts) + msg_body.clone() } else { - (String::new(), UInt::min_value()) + String::new() }; - if msg_body.contains("!party") && timestamp > self.start_time { + if msg_body.contains("!party") { let content = MessageEventContent::Text(TextMessageEventContent { body: "🎉🎊🥳 let's PARTY!! 🥳🎊🎉".to_string(), format: None,