2020-08-28 10:05:52 +02:00
use serenity ::model ::id ::{ EmojiId , GuildId } ;
2020-08-28 09:45:19 +02:00
use serenity ::model ::prelude ::* ;
use serenity ::prelude ::* ;
use serenity ::Client ;
#[ macro_use ]
extern crate lazy_static ;
struct Handler ;
lazy_static! {
static ref SERVER_ID : GuildId = GuildId ( std ::env ::args ( ) . nth ( 1 ) . unwrap ( ) . parse ( ) . unwrap ( ) ) ;
}
impl EventHandler for Handler {
fn message ( & self , ctx : Context , message : Message ) {
2020-08-28 10:05:52 +02:00
if is_based ( & message . content . to_lowercase ( ) ) {
react ( & ctx , & message , 748609686273523844 ) ;
}
if is_cringe ( & message . content . to_lowercase ( ) ) {
react ( & ctx , & message , 748609686273523844 ) ;
2020-08-28 09:45:19 +02:00
}
}
}
2020-08-28 10:05:52 +02:00
fn react ( ctx : & Context , msg : & Message , emoji : u64 ) {
if let Err ( e ) = msg . react ( ctx , EmojiId ( emoji ) ) {
println! ( " Could not react, error was: {:?} " , e ) ;
}
}
2020-08-28 09:45:19 +02:00
fn is_cringe ( s : & str ) -> bool {
s . contains ( " cringe " )
}
fn is_based ( s : & str ) -> bool {
( s . contains ( " based " ) | | s . contains ( " basiert " ) ) & & ! s . contains ( " based on " )
}
pub fn main ( ) {
let mut client = Client ::new (
std ::env ::var ( " DISCORD_TOKEN " ) . expect ( " no token in environment " ) ,
Handler ,
)
. expect ( " Could not create client " ) ;
client . start ( ) . expect ( " could not start " ) ;
}