New commands: /setstatus & /avatar
This commit is contained in:
parent
a8bb9bc8fd
commit
ae91b00730
6 changed files with 70 additions and 3 deletions
|
|
@ -1,3 +1,4 @@
|
|||
BOT_TOKEN=YOUR-BOT-TOKEN
|
||||
MEMBER_ROLE_ID=123
|
||||
WELCOME_CHANNEL_ID=321
|
||||
ADMIN_ID=1
|
||||
24
src/commands/avatar.rs
Normal file
24
src/commands/avatar.rs
Normal file
|
|
@ -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),
|
||||
)
|
||||
}
|
||||
|
|
@ -1,2 +1,4 @@
|
|||
pub mod ping;
|
||||
pub mod id;
|
||||
pub mod setstatus;
|
||||
pub mod avatar;
|
||||
36
src/commands/setstatus.rs
Normal file
36
src/commands/setstatus.rs
Normal file
|
|
@ -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),
|
||||
)
|
||||
}
|
||||
|
|
@ -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,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue