Create client to establish connection with discord and add basic framework with sample command
This commit is contained in:
35
cipher_discord_bot/src/utils.rs
Normal file
35
cipher_discord_bot/src/utils.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use cipher_core::repository::RepositoryProvider;
|
||||
use serenity::all::{Color, GuildId};
|
||||
|
||||
use crate::app::{AppCommand, AppContext};
|
||||
|
||||
pub async fn register_in_guilds<R>(
|
||||
serenity_ctx: &serenity::client::Context,
|
||||
commands: &[AppCommand<R, R::BackendError>],
|
||||
guilds: &[GuildId],
|
||||
)
|
||||
where
|
||||
R: RepositoryProvider,
|
||||
{
|
||||
for guild in guilds {
|
||||
let result = poise::builtins::register_in_guild(serenity_ctx, commands, *guild).await;
|
||||
match (guild.name(serenity_ctx), result) {
|
||||
(None, Err(err)) => log::warn!("Failed to register command in guild with id {}: {}", guild.get().to_string(), err),
|
||||
(None, Ok(())) => log::info!("Successfully registered commands in guild with id {}", guild.get().to_string()),
|
||||
(Some(guild_name), Err(err)) => log::warn!("Failed to register command in guild with id {} ({}): {}", guild.get().to_string(), guild_name, err),
|
||||
(Some(guild_name), Ok(())) => log::info!("Successfully registered commands in guild with id {} ({})", guild.get().to_string(), guild_name),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn bot_color<R>(ctx: &AppContext<'_, R, R::BackendError>) -> Color
|
||||
where
|
||||
R: RepositoryProvider + Send + Sync,
|
||||
{
|
||||
let member = match ctx.guild_id() {
|
||||
Some(guild) => guild.member(ctx, ctx.framework.bot_id).await.ok(),
|
||||
None => None,
|
||||
};
|
||||
|
||||
member.and_then(|m| m.colour(ctx)).unwrap_or(Color::BLURPLE)
|
||||
}
|
||||
Reference in New Issue
Block a user