summaryrefslogtreecommitdiff
path: root/src/events/mod.rs
blob: 5b4c88d8ab1820e4bf586be56a7e98d9ac275780 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use crate::{client::Data, consts};

use anyhow::Result;
use log::{debug, info};
use poise::serenity_prelude::{self as serenity, CreateBotAuthParameters};
use serenity::FullEvent;

pub mod error;
mod guild;
mod message;
mod pinboard;
mod reactboard;

pub async fn handle(ctx: &serenity::Context, event: &FullEvent, data: &Data) -> Result<()> {
	match event {
		FullEvent::Ready { data_about_bot } => {
			info!("Logged in as {}!", data_about_bot.user.name);

			if let Ok(invite_link) = CreateBotAuthParameters::new().auto_client_id(ctx).await {
				let link = invite_link
					.scopes(consts::bot_scopes())
					.permissions(*consts::bot_permissions())
					.build();
				info!("Invite me to your server at {link}");
			} else {
				debug!("Not displaying invite_link since we couldn't find our client ID");
			}
		}

		FullEvent::Message { new_message } => {
			message::handle(ctx, new_message, data).await?;
			pinboard::handle(ctx, new_message, data).await?;
		}

		FullEvent::ReactionAdd { add_reaction } => {
			reactboard::handle(ctx, add_reaction, data).await?;
		}

		FullEvent::GuildCreate { guild, is_new: _ } => {
			guild::handle_create(guild, data).await?;
		}

		FullEvent::GuildDelete {
			incomplete,
			full: _,
		} => guild::handle_delete(incomplete, data).await?,

		_ => {}
	}

	Ok(())
}