mirror of
https://github.com/kurbezz/discord-bot.git
synced 2025-12-06 07:05:36 +01:00
Update
This commit is contained in:
@@ -10,5 +10,6 @@ pub fn register() -> CreateCommand {
|
||||
CommandOptionType::String, "game", "Игра"
|
||||
)
|
||||
.required(true)
|
||||
.set_autocomplete(true)
|
||||
)
|
||||
}
|
||||
|
||||
57
src/main.rs
57
src/main.rs
@@ -1,5 +1,5 @@
|
||||
use reqwest::Url;
|
||||
use serenity::all::{ActivityData, CreateMessage, GuildId};
|
||||
use serenity::all::{ActivityData, CreateInteractionResponse, CreateInteractionResponseMessage, CreateMessage, GuildId, Interaction};
|
||||
use serenity::async_trait;
|
||||
use serenity::model::channel::Message;
|
||||
use serenity::prelude::*;
|
||||
@@ -27,6 +27,55 @@ struct Handler;
|
||||
|
||||
#[async_trait]
|
||||
impl EventHandler for Handler {
|
||||
async fn interaction_create(&self, ctx: Context, interaction: Interaction) {
|
||||
if let Interaction::Command(command) = interaction {
|
||||
println!("Received command interaction: {command:#?}");
|
||||
|
||||
let content = match command.data.name.as_str() {
|
||||
"create_message" => Some("#init".to_string()),
|
||||
_ => 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}");
|
||||
}
|
||||
}
|
||||
} else if let Interaction::Autocomplete(interaction) = interaction {
|
||||
// println!("Received autocomplete interaction: {interaction:#?}");
|
||||
|
||||
// let content = match interaction.data.name.as_str() {
|
||||
// "game" => {
|
||||
// let games = vec!["Dota 2", "CS:GO", "PUBG"];
|
||||
// let options = games.iter().map(|game| {
|
||||
// CreateCommandOptionChoice::new(game, game)
|
||||
// }).collect();
|
||||
|
||||
// let data = CreateInteractionResponseMessage::new().content("Выберите игру").add_option(
|
||||
// CreateCommandOption::new(
|
||||
// CommandOptionType::String, "game", "Игра"
|
||||
// )
|
||||
// .required(true)
|
||||
// .set_autocomplete(true)
|
||||
// .add_choices(options)
|
||||
// );
|
||||
|
||||
// Some(data)
|
||||
// },
|
||||
// _ => None,
|
||||
// };
|
||||
|
||||
// if let Some(content) = content {
|
||||
// let builder = CreateInteractionResponse::Message(content);
|
||||
// if let Err(why) = interaction.create_response(&ctx.http, builder).await {
|
||||
// println!("Cannot respond to autocomplete command: {why}");
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
async fn message(&self, _ctx: Context, msg: Message) {
|
||||
if msg.guild_id != Some(config::CONFIG.discord_guild_id.into()) {
|
||||
return;
|
||||
@@ -36,12 +85,6 @@ impl EventHandler for Handler {
|
||||
send_to_telegram(&msg.content).await;
|
||||
return;
|
||||
}
|
||||
|
||||
if msg.content == "/create_message" {
|
||||
let _ = msg.channel_id.send_message(&_ctx.http, CreateMessage::new().content("#Init")).await;
|
||||
}
|
||||
|
||||
println!("{}: {}", msg.author.name, msg.content);
|
||||
}
|
||||
|
||||
async fn ready(&self, ctx: Context, _ready: serenity::model::gateway::Ready) {
|
||||
|
||||
Reference in New Issue
Block a user