aboutsummaryrefslogtreecommitdiff
path: root/src/commands.rs
blob: fb31f148b97c82dc48be80221377e31ef16b412b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (C) 2021-2021 Fuwn
// SPDX-License-Identifier: GPL-3.0-only

use serenity::{
  framework::standard::{macros::command, Args, CommandResult},
  model::prelude::*,
  prelude::*,
  utils::{content_safe, ContentSafeOptions},
};

#[command]
pub async fn ping(ctx: &Context, msg: &Message) -> CommandResult {
  msg.channel_id.say(&ctx.http, "Pong!").await?;

  Ok(())
}

#[command]
pub async fn help(ctx: &Context, msg: &Message) -> CommandResult {
  msg
    .channel_id
    .say(
      &ctx.http,
      r#"```
  commands
  ========

help - you are here
ping - pong!

  information
  ===========

- https://github.com/fuwn/dos-bot
- https://discord.io/assembly
```"#,
    )
    .await?;

  Ok(())
}

#[command]
pub async fn say(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
  let settings = msg.guild_id.map_or_else(
    || {
      ContentSafeOptions::default()
        .clean_channel(false)
        .clean_role(false)
    },
    |guild_id| {
      ContentSafeOptions::default()
        .clean_channel(false)
        .display_as_member_from(guild_id)
    },
  );

  let content = content_safe(&ctx.cache, &args.rest(), &settings).await;
  msg.delete(&ctx.http).await?;

  msg.channel_id.say(&ctx.http, &content).await?;

  Ok(())
}