1use crate::{CmdCtx, Error};
2use stoat::{
3 MemberExt, MessageExt, ServerExt,
4 commands::{Command, ConsumeRest, server_only},
5 types::Member,
6};
7
8async fn ban(ctx: CmdCtx, member: Member, ConsumeRest(reason): ConsumeRest) -> Result<(), Error> {
9 let reason = if reason.is_empty() {
10 "No reason".to_string()
11 } else {
12 reason
13 };
14
15 member.ban(&ctx, Some(reason)).await?;
16
17 ctx.message
18 .reply(&ctx, false)
19 .content(format!("Banned {}.", member.mention()))
20 .build()
21 .await?;
22
23 Ok(())
24}
25
26async fn remove_ban(ctx: CmdCtx, user_id: String) -> Result<(), Error> {
27 let server = ctx.get_current_server().unwrap();
28
29 server.unban_member(&ctx, &user_id).await?;
30
31 ctx.message
32 .reply(&ctx, false)
33 .content(format!("Unbanned <@{user_id}>."))
34 .build()
35 .await?;
36
37 Ok(())
38}
39
40pub fn command() -> Command<Error, ()> {
41 Command::new("ban", ban)
42 .description("Bans a member.")
43 .signature("<member> [reason...]")
44 .check(server_only)
45 .child(
46 Command::new("remove", remove_ban)
47 .description("Unbans a member.")
48 .signature("<user_id>")
49 .check(server_only),
50 )
51}