From 2d5da2a98fb21bd815b2ef1052b323022bb0cab9 Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Sun, 12 Dec 2021 23:14:09 +0100
Subject: [PATCH] Fix most unused imports

---
 src/config.rs | 12 +++++++----
 src/main.rs   | 12 ++---------
 src/matrix.rs | 59 ++++++++++++++++++++++++++++++---------------------
 3 files changed, 45 insertions(+), 38 deletions(-)

diff --git a/src/config.rs b/src/config.rs
index c98d967..520e633 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -2,8 +2,8 @@
 
 use ini::{Error::Io as IniErrIo, Error::Parse as IniErrParse, Ini};
 use log::{error, info, warn, LevelFilter};
+use std::{env, path::Path, process::abort};
 use url::Url;
-use std::{ process::abort, path::Path, env };
 
 pub struct Config {
     pub display_name: String,  // The display name to set for the bot
@@ -61,9 +61,12 @@ pub fn write_default(file_name: &String) -> Result<(), String> {
         .set("id", "@some_id:matrix.org")
         .set("password", "no-password")
         .set("display_name", "MGB-Hitagi");
-    return match conf.write_to_file_policy(file_name, ini::EscapePolicy::Everything) {
-        Ok(()) => Ok(()),
-        Err(e) => Err(e.to_string()),
+    match conf.write_to_file_policy(file_name, ini::EscapePolicy::Everything) {
+        Ok(()) => {
+            info!("Default config file written to {}", file_name);
+            return Ok(());
+        }
+        Err(e) => return Err(e.to_string()),
     };
 }
 
@@ -84,6 +87,7 @@ pub fn check_argument_or_abort(should_write_default: bool) {
             );
             abort();
         } else if should_write_default {
+            warn!("Try to write the default config file to {}", default_file);
             match write_default(&default_file) {
                 Ok(()) => error!(
                     "Args count is {}, you need to only specify the config file for the bot. \
diff --git a/src/main.rs b/src/main.rs
index d3a9be7..4f15b66 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,17 +1,9 @@
-#![allow(unused_imports)]
-
 mod config;
 mod matrix;
-use crate::config::Config;
-
-use log::{error, info, warn};
-use log4rs;
-// use log4rs::config::{Appender, Config, Logger, Root};
 
+use log::{error, info};
 use matrix_sdk;
-use std::convert::TryFrom;
-use std::path::Path;
-use std::{env, process::exit, process::abort};
+use std::{env, process::abort};
 
 #[tokio::main]
 async fn main() -> matrix_sdk::Result<()> {
diff --git a/src/matrix.rs b/src/matrix.rs
index 6ecd4c8..78f91b0 100644
--- a/src/matrix.rs
+++ b/src/matrix.rs
@@ -5,16 +5,12 @@ use matrix_sdk::{
     room::Room,
     ruma::{
         events::{
-            macros::EventContent,
-            push_rules::PushRulesEvent,
             room::message::{MessageEventContent, MessageType, TextMessageEventContent},
-            room::topic::TopicEventContent,
-            AnyMessageEventContent, AnyRoomEvent, AnySyncRoomEvent, StateEvent, SyncMessageEvent,
-            SyncStateEvent,
+            AnyMessageEventContent, SyncMessageEvent,
         },
-        Int, MilliSecondsSinceUnixEpoch, UserId,
+        UserId,
     },
-    Client, LoopCtrl, Result, RoomInfo, SyncSettings,
+    Client, Result, RoomInfo, SyncSettings,
 };
 use std::convert::TryFrom;
 
@@ -29,24 +25,39 @@ async fn on_room_message(
         return;
     }
 
-    if let Room::Joined(room) = room {
-        let room_name = match room.name() {
-            Some(n) => "<".to_string() + &n + ">",
-            None => "<--none-->".to_string(),
-        };
-        let _body = match ev.content.msgtype {
-            MessageType::Text(TextMessageEventContent { body, .. }) => "Text: ".to_string() + &body,
-            _ => "Unsupported type".to_string(),
-        };
-        info!(
-            "{} a.k.a. {}, from {}",
+    let room_name = match room.name() {
+        Some(n) => "<".to_string() + &n + ">",
+        None => "<--none-->".to_string(),
+    };
+
+    match room {
+        Room::Joined(room) => {
+            let _body = match ev.content.msgtype {
+                MessageType::Text(TextMessageEventContent { body, .. }) => {
+                    "Text: ".to_string() + &body
+                }
+                _ => "Unsupported type".to_string(),
+            };
+            info!(
+                "Got message from {} in {} a.k.a. {}",
+                sender_id,
+                room.room_id(),
+                room_name
+            );
+            // room.send(
+            //     AnyMessageEventContent::RoomMessage(MessageEventContent::text_plain("Hello world")),
+            //     None,
+            // )
+            // .await
+            // .unwrap();
+        }
+        Room::Invited(room) => warn!(
+            "Bot was invited by {} to room {} a.k.a. {}",
+            sender_id,
             room.room_id(),
-            room_name,
-            sender_id
-        );
-        let content =
-            AnyMessageEventContent::RoomMessage(MessageEventContent::text_plain("Hello world"));
-        room.send(content, None).await.unwrap();
+            room_name
+        ),
+        Room::Left(room) => error!("Bot left room {} a.k.a. {}", room.room_id(), room_name),
     }
 }
 
-- 
GitLab