mirror of
https://github.com/kurbezz/discord-bot.git
synced 2025-12-06 07:05:36 +01:00
Update
This commit is contained in:
13
src/commands/copy_message.rs
Normal file
13
src/commands/copy_message.rs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
use serenity::{all::CommandOptionType, builder::*};
|
||||||
|
|
||||||
|
|
||||||
|
pub fn register() -> CreateCommand {
|
||||||
|
CreateCommand::new("copy_message")
|
||||||
|
.description("Не вызывать, только для настройки")
|
||||||
|
.add_option(
|
||||||
|
CreateCommandOption::new(
|
||||||
|
CommandOptionType::Integer, "message_id", "ID сообщения"
|
||||||
|
)
|
||||||
|
.required(true)
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
use serenity::builder::*;
|
|
||||||
|
|
||||||
|
|
||||||
pub fn register() -> CreateCommand {
|
|
||||||
CreateCommand::new("create_message")
|
|
||||||
.description("Не вызывать, только для настройки")
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
pub mod add_game;
|
pub mod add_game;
|
||||||
pub mod delete_game;
|
pub mod delete_game;
|
||||||
pub mod create_message;
|
pub mod copy_message;
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ pub struct Config {
|
|||||||
pub discord_guild_id: u64,
|
pub discord_guild_id: u64,
|
||||||
pub discord_channel_id: u64,
|
pub discord_channel_id: u64,
|
||||||
pub discord_bot_activity: String,
|
pub discord_bot_activity: String,
|
||||||
|
// pub discord_game_list_channel_id: u64,
|
||||||
|
// pub discord_game_list_message_id: u64,
|
||||||
pub telegram_bot_token: String,
|
pub telegram_bot_token: String,
|
||||||
pub telegram_channel_id: i128,
|
pub telegram_channel_id: i128,
|
||||||
}
|
}
|
||||||
@@ -23,6 +25,8 @@ impl Config {
|
|||||||
discord_guild_id: get_env("DISCORD_GUILD_ID").parse().unwrap(),
|
discord_guild_id: get_env("DISCORD_GUILD_ID").parse().unwrap(),
|
||||||
discord_channel_id: get_env("DISCORD_CHANNEL_ID").parse().unwrap(),
|
discord_channel_id: get_env("DISCORD_CHANNEL_ID").parse().unwrap(),
|
||||||
discord_bot_activity: get_env("DISCORD_BOT_ACTIVITY"),
|
discord_bot_activity: get_env("DISCORD_BOT_ACTIVITY"),
|
||||||
|
// discord_game_list_channel_id: get_env("DISCORD_GAME_LIST_CHANNEL_ID").parse().unwrap(),
|
||||||
|
// discord_game_list_message_id: get_env("DISCORD_GAME_LIST_MESSAGE_ID").parse().unwrap(),
|
||||||
telegram_bot_token: get_env("TELEGRAM_BOT_TOKEN"),
|
telegram_bot_token: get_env("TELEGRAM_BOT_TOKEN"),
|
||||||
telegram_channel_id: get_env("TELEGRAM_CHANNEL_ID").parse().unwrap(),
|
telegram_channel_id: get_env("TELEGRAM_CHANNEL_ID").parse().unwrap(),
|
||||||
}
|
}
|
||||||
|
|||||||
45
src/main.rs
45
src/main.rs
@@ -29,22 +29,39 @@ struct Handler;
|
|||||||
impl EventHandler for Handler {
|
impl EventHandler for Handler {
|
||||||
async fn interaction_create(&self, ctx: Context, interaction: Interaction) {
|
async fn interaction_create(&self, ctx: Context, interaction: Interaction) {
|
||||||
if let Interaction::Command(command) = interaction {
|
if let Interaction::Command(command) = interaction {
|
||||||
println!("Received command interaction: {command:#?}");
|
match command.data.name.as_str() {
|
||||||
|
"create_message" => {
|
||||||
|
let message_id = command.data.options[0].value.as_str().unwrap().parse::<u64>().unwrap();
|
||||||
|
let message = command.channel_id.message(&ctx.http, message_id).await.unwrap();
|
||||||
|
|
||||||
let content = match command.data.name.as_str() {
|
let data = CreateInteractionResponseMessage::new().content(message.content);
|
||||||
"create_message" => Some("#init".to_string()),
|
let builder = CreateInteractionResponse::Message(data);
|
||||||
_ => Some("not implemented :(".to_string()),
|
if let Err(why) = command.create_response(&ctx.http, builder).await {
|
||||||
|
println!("Cannot respond to slash command: {why}");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"add_game" => {
|
||||||
|
// let message = command.channel_id.message(&ctx.http, config::CONFIG.discord_game_list_message_id).await.unwrap();
|
||||||
|
|
||||||
|
let data = CreateInteractionResponseMessage::new().content("Игра добавлена!").ephemeral(true);
|
||||||
|
let builder = CreateInteractionResponse::Message(data);
|
||||||
|
if let Err(why) = command.create_response(&ctx.http, builder).await {
|
||||||
|
println!("Cannot respond to slash command: {why}");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"delete_game" => {
|
||||||
|
// let message = command.channel_id.message(&ctx.http, config::CONFIG.discord_game_list_message_id).await.unwrap();
|
||||||
|
|
||||||
|
let data = CreateInteractionResponseMessage::new().content("Игра удалена!").ephemeral(true);
|
||||||
|
let builder = CreateInteractionResponse::Message(data);
|
||||||
|
if let Err(why) = command.create_response(&ctx.http, builder).await {
|
||||||
|
println!("Cannot respond to slash command: {why}");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => (),
|
||||||
};
|
};
|
||||||
|
|
||||||
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 {
|
} else if let Interaction::Autocomplete(interaction) = interaction {
|
||||||
// println!("Received autocomplete interaction: {interaction:#?}");
|
println!("Received autocomplete interaction: {interaction:#?}");
|
||||||
|
|
||||||
// let content = match interaction.data.name.as_str() {
|
// let content = match interaction.data.name.as_str() {
|
||||||
// "game" => {
|
// "game" => {
|
||||||
@@ -96,7 +113,7 @@ impl EventHandler for Handler {
|
|||||||
vec![
|
vec![
|
||||||
commands::add_game::register(),
|
commands::add_game::register(),
|
||||||
commands::delete_game::register(),
|
commands::delete_game::register(),
|
||||||
commands::create_message::register()
|
commands::copy_message::register(),
|
||||||
]
|
]
|
||||||
).await.unwrap();
|
).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user