From 3d07413690c551d9f034c93af85ae8da5a495e14 Mon Sep 17 00:00:00 2001 From: seth Date: Sat, 20 Apr 2024 02:31:40 +0000 Subject: spring cleaning (#165) * treewide: lightly refactor everything * once_cell -> std::sync * remove build.rs we can get our target at runtime * commands::copypasta: refactor selection * drop owo_colors * reactboard: always remove author from count * commands: better handle behavior outside of guilds * ci: garnix -> gha * nix: drop flake-parts & pre-commit-hooks * nix: fix rust flags in derivation * add gha badge to readme * ci: fail when format changes are made * ci: only run on push to main * nix: fix nil script * nix: add libiconv to darwin deps * ci: disable fail-fast * nix: fix actionlint & static checks * ci: add release gates * nix: fix nil check again * ci: give release gates unique names * ci: only build static packages in docker workflow * nix: move dev outputs to subflake * fix some typos * nix: cleanup checks & dev shell * add editorconfig --- src/handlers/event/mod.rs | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'src/handlers/event/mod.rs') diff --git a/src/handlers/event/mod.rs b/src/handlers/event/mod.rs index 9c986e1..cc7d727 100644 --- a/src/handlers/event/mod.rs +++ b/src/handlers/event/mod.rs @@ -1,9 +1,8 @@ -use crate::Data; +use crate::{consts, Data, Error}; -use eyre::{Report, Result}; -use log::info; -use poise::serenity_prelude as serenity; -use poise::FrameworkContext; +use eyre::Result; +use log::{debug, info}; +use poise::serenity_prelude::{self as serenity, CreateBotAuthParameters}; use serenity::FullEvent; mod guild; @@ -11,19 +10,24 @@ mod message; mod pinboard; mod reactboard; -pub async fn handle( - ctx: &serenity::Context, - event: &FullEvent, - framework: FrameworkContext<'_, Data, Report>, - data: &Data, -) -> Result<()> { +pub async fn handle(ctx: &serenity::Context, event: &FullEvent, data: &Data) -> Result<(), Error> { 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, framework, new_message, data).await?; + message::handle(ctx, new_message, data).await?; pinboard::handle(ctx, new_message, data).await?; } @@ -31,8 +35,8 @@ pub async fn handle( reactboard::handle(ctx, add_reaction, data).await?; } - FullEvent::GuildCreate { guild, is_new } => { - guild::handle_create(guild, &is_new.unwrap_or_default(), data).await?; + FullEvent::GuildCreate { guild, is_new: _ } => { + guild::handle_create(guild, data).await?; } FullEvent::GuildDelete { -- cgit v1.2.3