blob: dbe74b95880afe34e3fe2af71f6d47b662f3d8df (
plain)
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
65
66
67
68
69
70
|
use crate::utils::{bottom_decode, bottom_encode};
use serenity::builder::CreateApplicationCommand;
use serenity::model::prelude::command::CommandOptionType;
use serenity::model::prelude::interaction::application_command::{
CommandDataOption, CommandDataOptionValue,
};
pub fn run(options: &[CommandDataOption]) -> String {
let err = "failed to get nested option in";
let data = options
.get(0)
.unwrap_or_else(|| panic!("{} {:?}", err, options));
// get subcommand to decide whether to encode/decode
let subcommand = data.name.as_str();
// TODO: this is horrendous
// get message content
let option = data
.options
.get(0)
.unwrap_or_else(|| panic!("{} {:?}", err, data))
.resolved
.as_ref()
.expect("failed to resolve string!"); // this is annoying
if let CommandDataOptionValue::String(msg) = option {
match subcommand {
"encode" => bottom_encode(msg),
"decode" => bottom_decode(msg),
_ => "something went wrong :(".to_owned(),
}
} else {
"did you forget to enter a message?".to_owned()
}
}
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
command
.name("bottom")
.description("teawie will translate something to/from bottom for you 🥺")
// nesting...so much nesting
.create_option(|option| {
option
.name("encode")
.description("teawie will encode a message in bottom for you 🥺")
.kind(CommandOptionType::SubCommand)
.create_sub_option(|suboption| {
suboption
.name("content")
.description("what teawie will translate into bottom")
.kind(CommandOptionType::String)
.required(true)
})
})
.create_option(|option| {
option
.name("decode")
.description("teawie will decode a message in bottom for you 🥸")
.kind(CommandOptionType::SubCommand)
.create_sub_option(|suboption| {
suboption
.name("content")
.description("what teawie will translate from bottom")
.kind(CommandOptionType::String)
.required(true)
})
})
}
|