Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 2d5da2a9 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

Fix most unused imports

parent e146d12e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
use ini::{Error::Io as IniErrIo, Error::Parse as IniErrParse, Ini}; use ini::{Error::Io as IniErrIo, Error::Parse as IniErrParse, Ini};
use log::{error, info, warn, LevelFilter}; use log::{error, info, warn, LevelFilter};
use std::{env, path::Path, process::abort};
use url::Url; use url::Url;
use std::{ process::abort, path::Path, env };
pub struct Config { pub struct Config {
pub display_name: String, // The display name to set for the bot 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> { ...@@ -61,9 +61,12 @@ pub fn write_default(file_name: &String) -> Result<(), String> {
.set("id", "@some_id:matrix.org") .set("id", "@some_id:matrix.org")
.set("password", "no-password") .set("password", "no-password")
.set("display_name", "MGB-Hitagi"); .set("display_name", "MGB-Hitagi");
return match conf.write_to_file_policy(file_name, ini::EscapePolicy::Everything) { match conf.write_to_file_policy(file_name, ini::EscapePolicy::Everything) {
Ok(()) => Ok(()), Ok(()) => {
Err(e) => Err(e.to_string()), 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) { ...@@ -84,6 +87,7 @@ pub fn check_argument_or_abort(should_write_default: bool) {
); );
abort(); abort();
} else if should_write_default { } else if should_write_default {
warn!("Try to write the default config file to {}", default_file);
match write_default(&default_file) { match write_default(&default_file) {
Ok(()) => error!( Ok(()) => error!(
"Args count is {}, you need to only specify the config file for the bot. \ "Args count is {}, you need to only specify the config file for the bot. \
......
#![allow(unused_imports)]
mod config; mod config;
mod matrix; 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 matrix_sdk;
use std::convert::TryFrom; use std::{env, process::abort};
use std::path::Path;
use std::{env, process::exit, process::abort};
#[tokio::main] #[tokio::main]
async fn main() -> matrix_sdk::Result<()> { async fn main() -> matrix_sdk::Result<()> {
......
...@@ -5,16 +5,12 @@ use matrix_sdk::{ ...@@ -5,16 +5,12 @@ use matrix_sdk::{
room::Room, room::Room,
ruma::{ ruma::{
events::{ events::{
macros::EventContent,
push_rules::PushRulesEvent,
room::message::{MessageEventContent, MessageType, TextMessageEventContent}, room::message::{MessageEventContent, MessageType, TextMessageEventContent},
room::topic::TopicEventContent, AnyMessageEventContent, SyncMessageEvent,
AnyMessageEventContent, AnyRoomEvent, AnySyncRoomEvent, StateEvent, SyncMessageEvent,
SyncStateEvent,
}, },
Int, MilliSecondsSinceUnixEpoch, UserId, UserId,
}, },
Client, LoopCtrl, Result, RoomInfo, SyncSettings, Client, Result, RoomInfo, SyncSettings,
}; };
use std::convert::TryFrom; use std::convert::TryFrom;
...@@ -29,24 +25,39 @@ async fn on_room_message( ...@@ -29,24 +25,39 @@ async fn on_room_message(
return; return;
} }
if let Room::Joined(room) = room { let room_name = match room.name() {
let room_name = match room.name() { Some(n) => "<".to_string() + &n + ">",
Some(n) => "<".to_string() + &n + ">", None => "<--none-->".to_string(),
None => "<--none-->".to_string(), };
};
let _body = match ev.content.msgtype { match room {
MessageType::Text(TextMessageEventContent { body, .. }) => "Text: ".to_string() + &body, Room::Joined(room) => {
_ => "Unsupported type".to_string(), let _body = match ev.content.msgtype {
}; MessageType::Text(TextMessageEventContent { body, .. }) => {
info!( "Text: ".to_string() + &body
"{} a.k.a. {}, from {}", }
_ => "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.room_id(),
room_name, room_name
sender_id ),
); Room::Left(room) => error!("Bot left room {} a.k.a. {}", room.room_id(), room_name),
let content =
AnyMessageEventContent::RoomMessage(MessageEventContent::text_plain("Hello world"));
room.send(content, None).await.unwrap();
} }
} }
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter