mirror of
https://github.com/kurbezz/discord-bot.git
synced 2026-03-03 14:50:47 +01:00
Update
This commit is contained in:
@@ -1,32 +1,23 @@
|
|||||||
use serenity::builder::*;
|
use serenity::builder::*;
|
||||||
use serenity::model::prelude::*;
|
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 {
|
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)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
26
src/main.rs
26
src/main.rs
@@ -27,32 +27,13 @@ struct Handler;
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl EventHandler for Handler {
|
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) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
send_to_telegram(&msg.content).await;
|
println!("{}: {}", msg.author.name, msg.content);
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn ready(&self, ctx: Context, _ready: serenity::model::gateway::Ready) {
|
async fn ready(&self, ctx: Context, _ready: serenity::model::gateway::Ready) {
|
||||||
@@ -63,6 +44,7 @@ impl EventHandler for Handler {
|
|||||||
&ctx.http,
|
&ctx.http,
|
||||||
vec![
|
vec![
|
||||||
commands::add_game::register(),
|
commands::add_game::register(),
|
||||||
|
// commands::delete_game::register(),
|
||||||
]
|
]
|
||||||
).await.unwrap();
|
).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user