Add !status command

This commit is contained in:
Agatha Rose 2020-06-11 21:18:30 +03:00
parent ce2bb6c088
commit 186c82998a
No known key found for this signature in database
GPG Key ID: 3F9F2317B3D5C3AC
1 changed files with 41 additions and 4 deletions

View File

@ -54,8 +54,8 @@ impl EventHandler for Handler {
#[group] #[group]
#[commands( #[commands(
init, ping, halt, servers, host, ship, bottom_rng, headpat, uwu, gayculator, sausage, help, init, ping, halt, servers, host, status, ship, bottom_rng, headpat, uwu, gayculator, sausage,
embed, define, owo, info, echo, desc, pinned, brainfuck help, embed, define, owo, info, echo, desc, pinned, brainfuck
)] )]
struct General; struct General;
@ -130,7 +130,7 @@ fn main() {
); );
if let Err(e) = client.start() { 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); 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] #[command]
#[checks(Owner)] #[checks(Owner)]
fn servers(ctx: &mut Context, message: &Message) -> CommandResult { 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), ("owo!owo ``text``", "owoify input text", true),
("\u{200B}", "**Admin commands:**", false), ("\u{200B}", "**Admin commands:**", false),
("owo!halt", "Kill the bot process", true), ("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), ("owo!host", "Display host info", true),
]) ])
.color(0xffd1dc) .color(0xffd1dc)