Add !status command

This commit is contained in:
Agatha Rose 2020-06-11 21:18:30 +03:00
parent 3a3c9253d9
commit 7b6829bc43
1 changed files with 41 additions and 4 deletions

View File

@ -54,8 +54,8 @@ impl EventHandler for Handler {
#[group]
#[commands(
init, ping, halt, servers, host, ship, bottom_rng, headpat, uwu, gayculator, sausage, help,
embed, define, owo, info, echo, desc, pinned, brainfuck
init, ping, halt, servers, host, status, ship, bottom_rng, headpat, uwu, gayculator, sausage,
help, embed, define, owo, info, echo, desc, pinned, brainfuck
)]
struct General;
@ -130,7 +130,7 @@ fn main() {
);
if let Err(e) = client.start() {
println!("An error occurred while running the client: {:?}", e);
eprintln!("An error occurred while running the client: {:?}", e);
}
}
@ -223,6 +223,39 @@ fn halt(ctx: &mut Context) -> CommandResult {
process::exit(0);
}
// set bot's status to input text
#[command]
#[checks(Owner)]
fn status(ctx: &mut Context, _message: &Message, mut args: Args) -> CommandResult {
use serenity::model::gateway::Activity;
if args.is_empty() {
return Err(CommandError("Called without args!".to_string()));
}
let mut input = args.single::<String>()?;
input = input.trim().to_string();
let activity;
// if args contain 'listening', use the appropriate activity type
if input.contains("listening") {
activity = Activity::listening(args.rest().trim());
// reset status
} else if input.contains("reset") {
activity = Activity::listening("catgirls nyaaing");
// otherwise default to playing
} else {
args.restore();
activity = Activity::playing(args.rest().trim());
};
let status = OnlineStatus::Online;
ctx.set_presence(Some(activity), status);
Ok(())
}
#[command]
#[checks(Owner)]
fn servers(ctx: &mut Context, message: &Message) -> CommandResult {
@ -585,7 +618,11 @@ fn help(ctx: &mut Context, message: &Message) -> CommandResult {
("owo!owo ``text``", "owoify input text", true),
("\u{200B}", "**Admin commands:**", false),
("owo!halt", "Kill the bot process", true),
("owo!servers", "List the servers I'm in", true),
("owo!status ``[args]``", "Sets the bot status", true)(
"owo!servers",
"List the servers I'm in",
true,
),
("owo!host", "Display host info", true),
])
.color(0xffd1dc)