Skip to content

Commit

Permalink
Add hook and event logging
Browse files Browse the repository at this point in the history
  • Loading branch information
xNul committed Oct 7, 2020
1 parent 953bbc9 commit 650e245
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct Handler;
#[async_trait]
impl EventHandler for Handler {
async fn ready(&self, ctx: Context, ready: Ready) {
println!("{} is connected!", ready.user.name);
log::info!("{} is connected!", ready.user.name);
ctx.set_activity(Activity::playing("Among Us")).await;
}

Expand All @@ -55,6 +55,8 @@ impl EventHandler for Handler {
let voice_channel_id = voice_state.channel_id.unwrap();
let user_id = voice_state.user_id.0;

log::info!("\"{}\" is leaving Voice Channel \"{}\" in Guild \"{}\"", voice_state.user_id.to_user(&_ctx.http).await.unwrap().tag(), voice_channel_id, guild_id);

// If a game existed for the VC.
let mut data = _ctx.data.write().await;
let games = data.get_mut::<Games>().expect("Expected Games in TypeMap.");
Expand Down Expand Up @@ -84,6 +86,8 @@ impl EventHandler for Handler {
let voice_channel_id = voice_state.channel_id.unwrap();
let user_id = voice_state.user_id.0;

log::info!("\"{}\" is joining Voice Channel \"{}\" in Guild \"{}\"", voice_state.user_id.to_user(&_ctx.http).await.unwrap().tag(), voice_channel_id, guild_id);

let mut game_muted = false;

// If a game existed for the VC, check if it's muted.
Expand All @@ -106,7 +110,8 @@ impl EventHandler for Handler {

#[hook]
async fn before_hook(ctx: &Context, msg: &Message, cmd_name: &str) -> bool {
log::info!("Command \"{}\" sent by \"{}\" in \"{}\"", msg.content, msg.author.tag(), msg.guild_id.unwrap());
let guild_id = msg.guild_id.unwrap();
log::info!("Command \"{}\" sent by \"{}\" in \"{}\"", msg.content, msg.author.tag(), guild_id);

let guild = msg.guild(&ctx.cache).await.unwrap();
let voice_states = guild.voice_states;
Expand All @@ -129,6 +134,8 @@ async fn before_hook(ctx: &Context, msg: &Message, cmd_name: &str) -> bool {
true
},
0 => {
log::info!("\"{}\" has become the Leader of Voice Channel \"{}\" in Guild \"{}\"", voice_state.user_id.to_user(&ctx.http).await.unwrap().tag(), voice_channel_id, guild_id);

game_instance.leader_user_id = user_id;
game_instance.recent_text_channel_id = msg.channel_id.0;
msg.channel_id.say(&ctx.http, "Congratulations, you \
Expand All @@ -146,6 +153,8 @@ async fn before_hook(ctx: &Context, msg: &Message, cmd_name: &str) -> bool {
}
},
None => {
log::info!("Creating a new Game Instance for Voice Channel \"{}\" in Guild \"{}\"", voice_channel_id, guild_id);
log::info!("\"{}\" has become the Leader of Voice Channel \"{}\" in Guild \"{}\"", voice_state.user_id.to_user(&ctx.http).await.unwrap().tag(), voice_channel_id, guild_id);
let new_game = GameInstance{
leader_user_id: user_id,
recent_text_channel_id: msg.channel_id.0,
Expand Down

0 comments on commit 650e245

Please sign in to comment.