mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-04-18 16:28:55 +00:00
admin.rs
This commit is contained in:
parent
d36323c12c
commit
4f6a0a2316
2 changed files with 90 additions and 44 deletions
90
youmubot/src/commands/admin.rs
Normal file
90
youmubot/src/commands/admin.rs
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
use serenity::prelude::*;
|
||||||
|
use serenity::{
|
||||||
|
framework::standard::{
|
||||||
|
macros::{command, group},
|
||||||
|
Args, CommandResult,
|
||||||
|
},
|
||||||
|
model::{channel::Message, id::UserId},
|
||||||
|
};
|
||||||
|
use std::{thread::sleep, time::Duration};
|
||||||
|
|
||||||
|
group!({
|
||||||
|
name: "admin",
|
||||||
|
options: {
|
||||||
|
only_in: "guilds",
|
||||||
|
prefixes: ["admin", "a"],
|
||||||
|
description: "Administrative commands for the server.",
|
||||||
|
},
|
||||||
|
commands: [clean, ban, kick],
|
||||||
|
});
|
||||||
|
|
||||||
|
#[command]
|
||||||
|
#[aliases("cleanall")]
|
||||||
|
#[required_permissions(MANAGE_MESSAGES)]
|
||||||
|
#[description = "Clean at most X latest messages from the current channel. Defaults to 10."]
|
||||||
|
#[usage = "clean 50"]
|
||||||
|
#[min_args(0)]
|
||||||
|
#[max_args(1)]
|
||||||
|
fn clean(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||||
|
let limit = args.single().unwrap_or(10);
|
||||||
|
let messages = msg
|
||||||
|
.channel_id
|
||||||
|
.messages(&ctx.http, |b| b.before(msg.id).limit(limit))?;
|
||||||
|
msg.channel_id.delete_messages(&ctx.http, messages.iter())?;
|
||||||
|
msg.react(&ctx, "🌋")?;
|
||||||
|
|
||||||
|
sleep(Duration::from_secs(2));
|
||||||
|
msg.delete(&ctx)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[command]
|
||||||
|
#[required_permissions(ADMINISTRATOR)]
|
||||||
|
#[description = "Ban an user with a certain reason."]
|
||||||
|
#[usage = "ban user#1234 spam"]
|
||||||
|
#[min_args(1)]
|
||||||
|
#[max_args(2)]
|
||||||
|
fn ban(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||||
|
let user = args.single::<UserId>()?.to_user(&ctx)?;
|
||||||
|
let reason = args
|
||||||
|
.remains()
|
||||||
|
.map(|v| format!("`{}`", v))
|
||||||
|
.unwrap_or("no provided reason".to_owned());
|
||||||
|
|
||||||
|
msg.reply(
|
||||||
|
&ctx,
|
||||||
|
format!("🔨 Banning user {} for reason `{}`.", user.tag(), reason),
|
||||||
|
)?;
|
||||||
|
|
||||||
|
msg.guild_id
|
||||||
|
.ok_or("Can't get guild from message?")? // we had a contract
|
||||||
|
.ban(&ctx.http, user, &reason)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[command]
|
||||||
|
#[required_permissions(ADMINISTRATOR)]
|
||||||
|
#[description = "Kick an user with a certain reason."]
|
||||||
|
#[usage = "kick user#1234 spam"]
|
||||||
|
#[min_args(1)]
|
||||||
|
#[max_args(2)]
|
||||||
|
fn kick(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||||
|
let user = args.single::<UserId>()?.to_user(&ctx)?;
|
||||||
|
let reason = args
|
||||||
|
.remains()
|
||||||
|
.map(|v| format!("`{}`", v))
|
||||||
|
.unwrap_or("no provided reason".to_owned());
|
||||||
|
|
||||||
|
msg.reply(
|
||||||
|
&ctx,
|
||||||
|
format!("🔫 Kicking user {} for {}.", user.tag(), reason),
|
||||||
|
)?;
|
||||||
|
|
||||||
|
msg.guild_id
|
||||||
|
.ok_or("Can't get guild from message?")? // we had a contract
|
||||||
|
.ban(&ctx.http, user, &reason)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
|
@ -1,44 +0,0 @@
|
||||||
use serenity::prelude::*;
|
|
||||||
use serenity::{
|
|
||||||
framework::standard::{
|
|
||||||
macros::{command, group},
|
|
||||||
Args, CommandResult,
|
|
||||||
},
|
|
||||||
model::channel::Message,
|
|
||||||
};
|
|
||||||
use std::{thread::sleep, time::Duration};
|
|
||||||
|
|
||||||
group!({
|
|
||||||
name: "admin",
|
|
||||||
options: {
|
|
||||||
only_in: "guilds",
|
|
||||||
prefixes: ["admin", "a"],
|
|
||||||
description: "Administrative commands for the server.",
|
|
||||||
},
|
|
||||||
commands: [clean, ban],
|
|
||||||
});
|
|
||||||
|
|
||||||
#[command]
|
|
||||||
#[aliases("cleanall")]
|
|
||||||
#[required_permissions(MANAGE_MESSAGES)]
|
|
||||||
#[description = "Clean at most X latest messages from the current channel. Defaults to 10."]
|
|
||||||
#[usage = "clean 50"]
|
|
||||||
fn clean(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
|
|
||||||
let limit = args.single().unwrap_or(10);
|
|
||||||
let messages = msg
|
|
||||||
.channel_id
|
|
||||||
.messages(&ctx.http, |b| b.before(msg.id).limit(limit))?;
|
|
||||||
msg.channel_id.delete_messages(&ctx.http, messages.iter())?;
|
|
||||||
msg.react(&ctx, "🌋")?;
|
|
||||||
|
|
||||||
sleep(Duration::from_secs(2));
|
|
||||||
msg.delete(&ctx)?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[command]
|
|
||||||
#[required_permissions(ADMINISTRATOR)]
|
|
||||||
#[description = "Ban an user with a certain reason."]
|
|
||||||
#[usage = "ban user#1234 spam"]
|
|
||||||
fn ban(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {}
|
|
Loading…
Add table
Reference in a new issue