Respond to DMs

This commit is contained in:
Sakuhl 2018-02-25 11:06:12 +01:00
parent 5e6b32e1db
commit 7629beddcb

View File

@ -88,17 +88,24 @@ impl EventHandler for Handler {
// Event handlers are dispatched through multi-threading, and so multiple // Event handlers are dispatched through multi-threading, and so multiple
// of a single event can be dispatched simultaneously. // of a single event can be dispatched simultaneously.
fn on_message(&self, _: Context, msg: Message) { fn on_message(&self, _: Context, msg: Message) {
if msg.author.name == "WynnBot" {
return;
}
let cfg = Config::generate().unwrap(); let cfg = Config::generate().unwrap();
let prefix = cfg.prefix; let prefix = cfg.prefix;
let connection = commands::establish_connection(); let connection = commands::establish_connection();
let prefix = prefixes::table let mut prefix = prefixes::table
.select(prefixes::prefix) .select(prefixes::prefix)
.filter(prefixes::id.eq(msg.guild_id().unwrap_or(GuildId(0)).0 as i64)) .filter(prefixes::id.eq(msg.guild_id().unwrap_or(GuildId(0)).0 as i64))
.load::<String>(&connection) .load::<String>(&connection)
.expect("Error loading prefix").get(0) .expect("Error loading prefix").get(0)
.map(|x| x.to_owned()) .map(|x| x.to_owned())
.unwrap_or(prefix); .unwrap_or(prefix);
if msg.is_private() {
prefix = String::new();
}
if let Err(error) = self.process_message(&msg, &prefix) { if let Err(error) = self.process_message(&msg, &prefix) {
//eprintln!("Error: {}", error); //eprintln!("Error: {}", error);
@ -117,6 +124,9 @@ impl EventHandler for Handler {
Channel::Guild(channel) => { Channel::Guild(channel) => {
channel.read().unwrap().guild_id.get().unwrap().name channel.read().unwrap().guild_id.get().unwrap().name
}, },
Channel::Private(_) => {
"DM".to_owned()
},
_ => unimplemented!() _ => unimplemented!()
}, msg.channel_id.get().unwrap(), msg.author, command))); }, msg.channel_id.get().unwrap(), msg.author, command)));
} }