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