2020-01-02 17:51:02 +01:00
#[ macro_use ]
extern crate lazy_static ;
use commands ::* ;
use serenity ::model ::channel ::Message ;
use serenity ::model ::id ::ChannelId ;
use serenity ::prelude ::* ;
mod commands ;
2020-01-02 23:10:28 +01:00
mod config ;
2020-01-02 17:51:02 +01:00
pub fn main ( ) {
print_commands ( ) ;
2020-01-02 23:10:28 +01:00
Client ::new ( & config ::CONFIG . secret , Handler )
. expect ( " Error creating client " )
. start ( )
. expect ( " Could not connect to discord " ) ;
2020-01-02 17:51:02 +01:00
}
2020-01-02 23:10:28 +01:00
const PREFIX : char = '>' ;
2020-01-02 17:51:02 +01:00
pub struct Handler ;
impl EventHandler for Handler {
fn message ( & self , ctx : Context , msg : Message ) {
if ! msg . content . starts_with ( PREFIX ) {
return ;
}
if let Some ( command ) = find_matching ( & msg . content ) {
let response = match command . execute ( & msg ) {
Err ( e ) = > e ,
2020-01-02 23:10:28 +01:00
Ok ( ( ) ) = > " Done " . to_owned ( ) ,
2020-01-02 17:51:02 +01:00
} ;
2020-01-02 23:10:28 +01:00
send ( msg . channel_id , & response , & ctx ) ;
2020-01-02 17:51:02 +01:00
}
}
}
pub fn send ( target : ChannelId , message : & str , ctx : & Context ) {
if let Err ( cause ) = target . say ( & ctx . http , message ) {
println! ( " Could not send message: {} " , cause ) ;
}
}