diff --git a/.env.example b/.env.example index cebdd5d..6c5c807 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,4 @@ BOT_TOKEN=YOUR-BOT-TOKEN MEMBER_ROLE_ID=123 -WELCOME_CHANNEL_ID=321 \ No newline at end of file +WELCOME_CHANNEL_ID=321 +ADMIN_ID=1 \ No newline at end of file diff --git a/src/commands/avatar.rs b/src/commands/avatar.rs new file mode 100644 index 0000000..40769d8 --- /dev/null +++ b/src/commands/avatar.rs @@ -0,0 +1,24 @@ +use serenity::builder::{CreateCommand, CreateCommandOption}; +use serenity::model::application::{CommandOptionType, ResolvedOption, ResolvedValue}; + +pub fn run(options: &[ResolvedOption]) -> String { + if let Some(ResolvedOption { + value: ResolvedValue::User(user, _), .. + }) = options.first() + { + if let Some(avatar_url) = user.avatar_url() { + avatar_url + } else { + "This user has no avatar".to_string() + } + } else { + "Please provide a valid user".to_string() + } +} + +pub fn register() -> CreateCommand { + CreateCommand::new("avatar").description("Get a user avatar").add_option( + CreateCommandOption::new(CommandOptionType::User, "mention", "The user to lookup") + .required(true), + ) +} diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 08c78cf..d567589 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,2 +1,4 @@ pub mod ping; -pub mod id; \ No newline at end of file +pub mod id; +pub mod setstatus; +pub mod avatar; \ No newline at end of file diff --git a/src/commands/setstatus.rs b/src/commands/setstatus.rs new file mode 100644 index 0000000..f10ce36 --- /dev/null +++ b/src/commands/setstatus.rs @@ -0,0 +1,36 @@ +use serenity::model::id::UserId; +use serenity::builder::{CreateCommand, CreateCommandOption}; +use serenity::model::application::{CommandOptionType, ResolvedOption, ResolvedValue}; +use serenity::gateway::ActivityData; +use serenity::model::user::OnlineStatus; +use serenity::prelude::*; + +use crate::config; + +pub fn run(options: &[ResolvedOption], user_id: UserId, ctx: &Context, config: &config::Config) -> String { + if user_id != config.admin_id { + return ":x:".to_string(); + } + let status = match options.first() { + Some(option) => { + if let ResolvedValue::String(status) = option.value { + status + } else { + "Unknown Status" + } + }, + None => "Unknown Status", + }; + ctx.set_presence( + Some(ActivityData::playing(status)), + OnlineStatus::DoNotDisturb + ); + ":ok:".to_string() +} + +pub fn register() -> CreateCommand { + CreateCommand::new("setstatus").description("Admins only | Set bot status").add_option( + CreateCommandOption::new(CommandOptionType::String, "status", "Bot status") + .required(true), + ) +} diff --git a/src/config.rs b/src/config.rs index 0219e27..723ee63 100644 --- a/src/config.rs +++ b/src/config.rs @@ -5,4 +5,5 @@ pub struct Config { pub bot_token: String, pub member_role_id: u64, pub welcome_channel_id: u64, + pub admin_id: u64, } diff --git a/src/main.rs b/src/main.rs index abe17e3..59c6a31 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,10 +41,11 @@ impl EventHandler for Handler { async fn interaction_create(&self, ctx: Context, interaction: Interaction) { if let Interaction::Command(command) = interaction { - let content = match command.data.name.as_str() { "ping" => Some(commands::ping::run(&command.data.options())), "id" => Some(commands::id::run(&command.data.options())), + "setstatus" => Some(commands::setstatus::run(&command.data.options(), command.user.id, &ctx, &self.config)), + "avatar" => Some(commands::avatar::run(&command.data.options())), _ => Some(":no_entry:".to_string()), }; @@ -69,6 +70,8 @@ impl EventHandler for Handler { vec![ commands::ping::register(), commands::id::register(), + commands::setstatus::register(), + commands::avatar::register(), ] ) .await