mirror of
https://github.com/kurbezz/discord-bot.git
synced 2025-12-06 07:05:36 +01:00
Test command
This commit is contained in:
@@ -8,5 +8,5 @@ edition = "2021"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
once_cell = "1.19.0"
|
once_cell = "1.19.0"
|
||||||
tokio = { version = "1.35.1", features = ["rt-multi-thread", "macros", "time"] }
|
tokio = { version = "1.35.1", features = ["rt-multi-thread", "macros", "time"] }
|
||||||
serenity = "0.12.1"
|
serenity = { verstion = "0.12.1", features = ["collector"] }
|
||||||
reqwest = { version = "0.11.23", features = ["json"] }
|
reqwest = { version = "0.11.23", features = ["json"] }
|
||||||
|
|||||||
32
src/commands/add_game.rs
Normal file
32
src/commands/add_game.rs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
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("Добавить игру в список")
|
||||||
|
}
|
||||||
1
src/commands/mod.rs
Normal file
1
src/commands/mod.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pub mod add_game;
|
||||||
@@ -8,10 +8,11 @@ fn get_env(env: &'static str) -> String {
|
|||||||
|
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub discord_bot_token: String,
|
pub discord_bot_token: String,
|
||||||
|
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 telegram_bot_token: String,
|
pub telegram_bot_token: String,
|
||||||
pub telgram_channel_id: i128,
|
pub telegram_channel_id: i128,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -19,10 +20,11 @@ impl Config {
|
|||||||
pub fn load() -> Config {
|
pub fn load() -> Config {
|
||||||
Config {
|
Config {
|
||||||
discord_bot_token: get_env("DISCORD_BOT_TOKEN"),
|
discord_bot_token: get_env("DISCORD_BOT_TOKEN"),
|
||||||
|
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"),
|
||||||
telegram_bot_token: get_env("TELEGRAM_BOT_TOKEN"),
|
telegram_bot_token: get_env("TELEGRAM_BOT_TOKEN"),
|
||||||
telgram_channel_id: get_env("TELEGRAM_CHANNEL_ID").parse().unwrap(),
|
telegram_channel_id: get_env("TELEGRAM_CHANNEL_ID").parse().unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
17
src/main.rs
17
src/main.rs
@@ -1,10 +1,11 @@
|
|||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
use serenity::all::ActivityData;
|
use serenity::all::{ActivityData, GuildId};
|
||||||
use serenity::async_trait;
|
use serenity::async_trait;
|
||||||
use serenity::model::channel::Message;
|
use serenity::model::channel::Message;
|
||||||
use serenity::prelude::*;
|
use serenity::prelude::*;
|
||||||
|
|
||||||
pub mod config;
|
pub mod config;
|
||||||
|
pub mod commands;
|
||||||
|
|
||||||
|
|
||||||
async fn send_to_telegram(msg: &str) {
|
async fn send_to_telegram(msg: &str) {
|
||||||
@@ -13,7 +14,7 @@ async fn send_to_telegram(msg: &str) {
|
|||||||
let url = Url::parse_with_params(
|
let url = Url::parse_with_params(
|
||||||
base_url.as_ref(),
|
base_url.as_ref(),
|
||||||
&[
|
&[
|
||||||
("chat_id", &config::CONFIG.telgram_channel_id.to_string().as_ref()),
|
("chat_id", &config::CONFIG.telegram_channel_id.to_string().as_ref()),
|
||||||
("text", &msg)
|
("text", &msg)
|
||||||
]
|
]
|
||||||
).unwrap();
|
).unwrap();
|
||||||
@@ -33,6 +34,18 @@ impl EventHandler for Handler {
|
|||||||
|
|
||||||
send_to_telegram(&msg.content).await;
|
send_to_telegram(&msg.content).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn ready(&self, ctx: Context, _ready: serenity::model::gateway::Ready) {
|
||||||
|
let guild_id = GuildId::new(config::CONFIG.discord_guild_id);
|
||||||
|
|
||||||
|
let _ = guild_id
|
||||||
|
.set_commands(
|
||||||
|
&ctx.http,
|
||||||
|
vec![
|
||||||
|
commands::add_game::register(),
|
||||||
|
]
|
||||||
|
).await.unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user