This commit is contained in:
2024-05-13 20:04:30 +02:00
parent 8a00f3d77c
commit d9fdb5c163
2 changed files with 21 additions and 48 deletions

View File

@@ -1,32 +1,23 @@
use serenity::builder::*;
use serenity::model::prelude::*;
use serenity::prelude::*;
use serenity::utils::CreateQuickModal;
pub async fn run(ctx: &Context, interaction: &CommandInteraction) -> Result<(), serenity::Error> {
let modal = CreateQuickModal::new("Добавление игры")
.timeout(std::time::Duration::from_secs(600))
.short_field("Категория")
.paragraph_field("Игра");
let response = interaction.quick_modal(ctx, modal).await?.unwrap();
let inputs = response.inputs;
let (category, game) = (&inputs[0], &inputs[1]);
response
.interaction
.create_response(
ctx,
CreateInteractionResponse::Message(CreateInteractionResponseMessage::new().content(
format!("{} {}", category, game),
)),
)
.await?;
Ok(())
}
pub fn register() -> CreateCommand {
CreateCommand::new("add_game").description("Добавить игру в список")
CreateCommand::new("add")
.description("Добавить игру в список")
.add_option(
CreateCommandOption::new(
CommandOptionType::String, "category", "Раздел"
)
.required(true)
.add_string_choice("Заказ за баллы", "points")
.add_string_choice("Проплачены", "paids")
.add_string_choice("Подарки", "gifts")
)
.add_option(
CreateCommandOption::new(
CommandOptionType::String, "game", "Игра"
)
.required(true)
)
}

View File

@@ -27,32 +27,13 @@ struct Handler;
#[async_trait]
impl EventHandler for Handler {
async fn interaction_create(&self, ctx: Context, interaction: Interaction) {
if let Interaction::Command(command) = interaction {
let content = match command.data.name.as_str() {
"add_game" => {
commands::add_game::run(&ctx, &command).await.unwrap();
None
},
_ => Some("not implemented :(".to_string()),
};
if let Some(content) = content {
let data = CreateInteractionResponseMessage::new().content(content);
let builder = CreateInteractionResponse::Message(data);
if let Err(why) = command.create_response(&ctx.http, builder).await {
println!("Cannot respond to slash command: {why}");
}
}
}
}
async fn message(&self, _ctx: Context, msg: Message) {
if msg.channel_id != config::CONFIG.discord_channel_id {
if msg.channel_id == config::CONFIG.discord_channel_id {
send_to_telegram(&msg.content).await;
return;
}
send_to_telegram(&msg.content).await;
println!("{}: {}", msg.author.name, msg.content);
}
async fn ready(&self, ctx: Context, _ready: serenity::model::gateway::Ready) {
@@ -63,6 +44,7 @@ impl EventHandler for Handler {
&ctx.http,
vec![
commands::add_game::register(),
// commands::delete_game::register(),
]
).await.unwrap();
}