feat: include ping and help
This commit is contained in:
parent
a54d14783a
commit
6f2b15493d
3
.vscode/extensions.json
vendored
3
.vscode/extensions.json
vendored
@ -12,6 +12,7 @@
|
|||||||
"helixquar.randomeverything",
|
"helixquar.randomeverything",
|
||||||
"shardulm94.trailing-spaces",
|
"shardulm94.trailing-spaces",
|
||||||
"tamasfe.even-better-toml",
|
"tamasfe.even-better-toml",
|
||||||
"edwinkofler.vscode-hyperupcall-pack-markdown"
|
"edwinkofler.vscode-hyperupcall-pack-markdown",
|
||||||
|
"proxzima.sweetdracula"
|
||||||
]
|
]
|
||||||
}
|
}
|
12
Cargo.lock
generated
12
Cargo.lock
generated
@ -570,6 +570,7 @@ dependencies = [
|
|||||||
"lock_api",
|
"lock_api",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"parking_lot_core",
|
"parking_lot_core",
|
||||||
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -846,6 +847,15 @@ dependencies = [
|
|||||||
"slab",
|
"slab",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fxhash"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "generic-array"
|
name = "generic-array"
|
||||||
version = "0.14.7"
|
version = "0.14.7"
|
||||||
@ -1858,8 +1868,10 @@ dependencies = [
|
|||||||
"bitflags 2.4.1",
|
"bitflags 2.4.1",
|
||||||
"bytes",
|
"bytes",
|
||||||
"command_attr",
|
"command_attr",
|
||||||
|
"dashmap",
|
||||||
"flate2",
|
"flate2",
|
||||||
"futures",
|
"futures",
|
||||||
|
"fxhash",
|
||||||
"levenshtein",
|
"levenshtein",
|
||||||
"mime_guess",
|
"mime_guess",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
|
@ -37,6 +37,7 @@ serenity = { version = "0.12", default-features = false, features = [
|
|||||||
"model",
|
"model",
|
||||||
"framework",
|
"framework",
|
||||||
"standard_framework",
|
"standard_framework",
|
||||||
|
"cache",
|
||||||
] }
|
] }
|
||||||
tokio = { version = "1.35", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.35", features = ["macros", "rt-multi-thread"] }
|
||||||
|
|
||||||
|
@ -12,3 +12,6 @@ password = "postgres"
|
|||||||
database = "postgres"
|
database = "postgres"
|
||||||
tls = false
|
tls = false
|
||||||
tls_insecure = false
|
tls_insecure = false
|
||||||
|
|
||||||
|
[image]
|
||||||
|
path = "/projects/base-image"
|
||||||
|
@ -2,7 +2,7 @@ bot_name = "AGAU_DEV"
|
|||||||
env = "test"
|
env = "test"
|
||||||
port = 5437
|
port = 5437
|
||||||
token = ""
|
token = ""
|
||||||
prefix= "&"
|
prefix = "&"
|
||||||
|
|
||||||
[persistence]
|
[persistence]
|
||||||
host = "localhost"
|
host = "localhost"
|
||||||
@ -12,3 +12,6 @@ password = "1OLlRZo1tnNluvx"
|
|||||||
database = "1pNkVsX3FgFeiQdga"
|
database = "1pNkVsX3FgFeiQdga"
|
||||||
tls = false
|
tls = false
|
||||||
tls_insecure = false
|
tls_insecure = false
|
||||||
|
|
||||||
|
[image]
|
||||||
|
path = "/projects/base-image"
|
||||||
|
27
src/bot/cmd/help.rs
Normal file
27
src/bot/cmd/help.rs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
use serenity::client::Context;
|
||||||
|
use serenity::framework::standard::macros::help;
|
||||||
|
use serenity::framework::standard::{
|
||||||
|
help_commands, Args, CommandGroup, CommandResult, HelpOptions,
|
||||||
|
};
|
||||||
|
use serenity::model::prelude::{Message, UserId};
|
||||||
|
use std::collections::HashSet;
|
||||||
|
#[help]
|
||||||
|
#[individual_command_tip = "Hello! Pour plus d'information sur une commande, passer la en argument."]
|
||||||
|
#[command_not_found_text = "La commande `{}` n'a pas été trouver."]
|
||||||
|
#[max_levenshtein_distance(3)]
|
||||||
|
#[wrong_channel = "Strike"]
|
||||||
|
#[lacking_role = "Hide"]
|
||||||
|
#[lacking_permissions = "Hide"]
|
||||||
|
#[strikethrough_commands_tip_in_guild("")]
|
||||||
|
#[embed_success_colour = "#5F021F"]
|
||||||
|
async fn help(
|
||||||
|
context: &Context,
|
||||||
|
msg: &Message,
|
||||||
|
args: Args,
|
||||||
|
help_options: &'static HelpOptions,
|
||||||
|
groups: &[&'static CommandGroup],
|
||||||
|
owners: HashSet<UserId>,
|
||||||
|
) -> CommandResult {
|
||||||
|
let _ = help_commands::with_embeds(context, msg, args, help_options, groups, owners).await;
|
||||||
|
Ok(())
|
||||||
|
}
|
2
src/bot/cmd/mod.rs
Normal file
2
src/bot/cmd/mod.rs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
pub mod help;
|
||||||
|
pub mod ping;
|
14
src/bot/cmd/ping.rs
Normal file
14
src/bot/cmd/ping.rs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
use serenity::{
|
||||||
|
all::Message,
|
||||||
|
client::Context,
|
||||||
|
framework::standard::{macros::command, CommandResult},
|
||||||
|
};
|
||||||
|
|
||||||
|
#[command]
|
||||||
|
#[description = "Pong!"]
|
||||||
|
pub async fn ping(ctx: &Context, msg: &Message) -> CommandResult {
|
||||||
|
if let Err(why) = msg.channel_id.say(&ctx.http, "Pong from framework!").await {
|
||||||
|
println!("Error sending message: {:?}", why)
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
@ -12,7 +12,7 @@ impl EventHandler for Handler {
|
|||||||
if msg.author.bot {
|
if msg.author.bot {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if msg.content == "!ping" {
|
if msg.content == "&ping" {
|
||||||
if let Err(why) = msg.channel_id.say(&ctx.http, "Pong!").await {
|
if let Err(why) = msg.channel_id.say(&ctx.http, "Pong!").await {
|
||||||
println!("Error sending message: {:?}", why);
|
println!("Error sending message: {:?}", why);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,20 @@
|
|||||||
|
use super::cmd::{help::HELP, ping::PING_COMMAND};
|
||||||
use super::handler::Handler;
|
use super::handler::Handler;
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use serenity::{all::GatewayIntents, http::Http, Client};
|
use serenity::framework::standard::Configuration;
|
||||||
|
use serenity::{
|
||||||
|
all::GatewayIntents,
|
||||||
|
framework::{standard::macros::group, StandardFramework},
|
||||||
|
http::Http,
|
||||||
|
Client,
|
||||||
|
};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use tokio::task::spawn_blocking;
|
use tokio::task::spawn_blocking;
|
||||||
|
|
||||||
|
#[group]
|
||||||
|
#[commands(ping)]
|
||||||
|
struct General;
|
||||||
|
|
||||||
pub fn start_bot(config: Config) {
|
pub fn start_bot(config: Config) {
|
||||||
if config.token != "" {
|
if config.token != "" {
|
||||||
spawn_blocking(move || {
|
spawn_blocking(move || {
|
||||||
@ -17,9 +28,11 @@ pub fn start_bot(config: Config) {
|
|||||||
| GatewayIntents::MESSAGE_CONTENT
|
| GatewayIntents::MESSAGE_CONTENT
|
||||||
| GatewayIntents::GUILD_VOICE_STATES
|
| GatewayIntents::GUILD_VOICE_STATES
|
||||||
| GatewayIntents::GUILDS
|
| GatewayIntents::GUILDS
|
||||||
| GatewayIntents::GUILD_MEMBERS;
|
| GatewayIntents::GUILD_MEMBERS
|
||||||
|
| GatewayIntents::GUILD_PRESENCES
|
||||||
|
| GatewayIntents::GUILD_MESSAGE_REACTIONS;
|
||||||
let http = Http::new(&config.token);
|
let http = Http::new(&config.token);
|
||||||
let (_owners, _bot_id) = match http.get_current_application_info().await {
|
let (owners, _bot_id) = match http.get_current_application_info().await {
|
||||||
Ok(info) => {
|
Ok(info) => {
|
||||||
let mut owners = HashSet::new();
|
let mut owners = HashSet::new();
|
||||||
match info.owner {
|
match info.owner {
|
||||||
@ -34,8 +47,19 @@ pub fn start_bot(config: Config) {
|
|||||||
}
|
}
|
||||||
Err(why) => panic!("Could not access application info: {:?}", why),
|
Err(why) => panic!("Could not access application info: {:?}", why),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let framework = StandardFramework::new().help(&HELP).group(&GENERAL_GROUP);
|
||||||
|
|
||||||
|
framework.configure(
|
||||||
|
Configuration::new()
|
||||||
|
.with_whitespace(true)
|
||||||
|
.prefix(config.prefix)
|
||||||
|
.owners(owners),
|
||||||
|
);
|
||||||
|
|
||||||
let mut client = Client::builder(&config.token, intents)
|
let mut client = Client::builder(&config.token, intents)
|
||||||
.event_handler(Handler)
|
.event_handler(Handler)
|
||||||
|
.framework(framework)
|
||||||
.await
|
.await
|
||||||
.expect("Err creating client");
|
.expect("Err creating client");
|
||||||
if let Err(why) = client.start().await {
|
if let Err(why) = client.start().await {
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
|
pub mod cmd;
|
||||||
pub mod handler;
|
pub mod handler;
|
||||||
pub mod init;
|
pub mod init;
|
||||||
|
@ -16,6 +16,8 @@ const BOT_NAME: &str = "BOT_NAME";
|
|||||||
const BOT_TOKEN: &str = "BOT_TOKEN";
|
const BOT_TOKEN: &str = "BOT_TOKEN";
|
||||||
const BOT_PREFIX: &str = "BOT_PREFIX";
|
const BOT_PREFIX: &str = "BOT_PREFIX";
|
||||||
|
|
||||||
|
const IMAGE_PATH: &str = "IMAGE_PATH";
|
||||||
|
|
||||||
const RUST_ENV: &str = "RUST_ENV";
|
const RUST_ENV: &str = "RUST_ENV";
|
||||||
|
|
||||||
const PORT: &str = "PORT";
|
const PORT: &str = "PORT";
|
||||||
@ -28,6 +30,12 @@ pub struct Config {
|
|||||||
pub port: u16,
|
pub port: u16,
|
||||||
pub token: String,
|
pub token: String,
|
||||||
pub prefix: String,
|
pub prefix: String,
|
||||||
|
pub image: ImageConfig,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Clone)]
|
||||||
|
pub struct ImageConfig {
|
||||||
|
pub path: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone)]
|
#[derive(Deserialize, Clone)]
|
||||||
@ -108,6 +116,9 @@ fn override_config_with_env_vars(config: Config) -> Config {
|
|||||||
.ok()
|
.ok()
|
||||||
.or(pers.tls_insecure),
|
.or(pers.tls_insecure),
|
||||||
},
|
},
|
||||||
|
image: ImageConfig {
|
||||||
|
path: env::var(IMAGE_PATH).unwrap_or(config.image.path),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ use actix_web::{App, HttpServer};
|
|||||||
use bot::init::start_bot;
|
use bot::init::start_bot;
|
||||||
use config::parse_local_config;
|
use config::parse_local_config;
|
||||||
|
|
||||||
#[actix_web::main] // or #[tokio::main]
|
#[tokio::main] // or #[actix_web::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
let config = parse_local_config();
|
let config = parse_local_config();
|
||||||
let port = config.port;
|
let port = config.port;
|
||||||
|
Loading…
Reference in New Issue
Block a user