Fix breaking changes caused by Poise update
All checks were successful
Build and push container image / build (push) Successful in 6m36s
All checks were successful
Build and push container image / build (push) Successful in 6m36s
This commit is contained in:
parent
eb56809350
commit
929ef0467a
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -800,7 +800,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kon"
|
name = "kon"
|
||||||
version = "0.1.8"
|
version = "0.1.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cargo_toml",
|
"cargo_toml",
|
||||||
"gamedig",
|
"gamedig",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "kon"
|
name = "kon"
|
||||||
version = "0.1.8"
|
version = "0.1.9"
|
||||||
rust-version = "1.74"
|
rust-version = "1.74"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
@ -11,7 +11,7 @@ cargo_toml = "0.18.0"
|
|||||||
gamedig = "0.4.1"
|
gamedig = "0.4.1"
|
||||||
once_cell = "1.19.0"
|
once_cell = "1.19.0"
|
||||||
poise = "0.6.1"
|
poise = "0.6.1"
|
||||||
reqwest = "0.11.23"
|
reqwest = { version = "0.11.23", features = ["json"] }
|
||||||
serde_json = "1.0.111"
|
serde_json = "1.0.111"
|
||||||
serenity = "0.12.0"
|
serenity = "0.12.0"
|
||||||
sysinfo = "0.30.5"
|
sysinfo = "0.30.5"
|
||||||
|
@ -18,6 +18,8 @@ use reqwest::{
|
|||||||
Client,
|
Client,
|
||||||
header::USER_AGENT
|
header::USER_AGENT
|
||||||
};
|
};
|
||||||
|
use poise::CreateReply;
|
||||||
|
use serenity::builder::CreateEmbed;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use cargo_toml::Manifest;
|
use cargo_toml::Manifest;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
@ -79,10 +81,11 @@ pub async fn status(_: poise::Context<'_, (), Error>) -> Result<(), Error> {
|
|||||||
/// Retrieve the server status from ATS
|
/// Retrieve the server status from ATS
|
||||||
#[poise::command(slash_command)]
|
#[poise::command(slash_command)]
|
||||||
pub async fn ats(ctx: poise::Context<'_, (), Error>) -> Result<(), Error> {
|
pub async fn ats(ctx: poise::Context<'_, (), Error>) -> Result<(), Error> {
|
||||||
|
let embed = CreateEmbed::new().color(EMBED_COLOR);
|
||||||
match query_server() {
|
match query_server() {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
ctx.send(|m| m.embed(|e|
|
ctx.send(CreateReply::default()
|
||||||
e.color(EMBED_COLOR)
|
.embed(embed
|
||||||
.title("American Truck Simulator Server Status")
|
.title("American Truck Simulator Server Status")
|
||||||
.fields(vec![
|
.fields(vec![
|
||||||
("Name", format!("{}", response.info.name), true),
|
("Name", format!("{}", response.info.name), true),
|
||||||
@ -101,6 +104,7 @@ pub async fn ats(ctx: poise::Context<'_, (), Error>) -> Result<(), Error> {
|
|||||||
pub async fn wg(ctx: poise::Context<'_, (), Error>) -> Result<(), Error> {
|
pub async fn wg(ctx: poise::Context<'_, (), Error>) -> Result<(), Error> {
|
||||||
let pms_asia = &PMS_BASE;
|
let pms_asia = &PMS_BASE;
|
||||||
let pms_eu = PMS_BASE.replace("asia", "eu");
|
let pms_eu = PMS_BASE.replace("asia", "eu");
|
||||||
|
let embed = CreateEmbed::new().color(EMBED_COLOR);
|
||||||
|
|
||||||
let (servers_asia, servers_eu) = join!(pms_serverstatus(&pms_asia), pms_serverstatus(&pms_eu));
|
let (servers_asia, servers_eu) = join!(pms_serverstatus(&pms_asia), pms_serverstatus(&pms_eu));
|
||||||
|
|
||||||
@ -125,11 +129,7 @@ pub async fn wg(ctx: poise::Context<'_, (), Error>) -> Result<(), Error> {
|
|||||||
embed_fields.push((name, status, true));
|
embed_fields.push((name, status, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.send(|m| m.embed(|e|
|
ctx.send(CreateReply::default().embed(embed.title("World of Tanks Server Status").fields(embed_fields))).await?;
|
||||||
e.color(EMBED_COLOR)
|
|
||||||
.title("World of Tanks Server Status")
|
|
||||||
.fields(embed_fields)
|
|
||||||
)).await?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
31
src/main.rs
31
src/main.rs
@ -1,7 +1,12 @@
|
|||||||
mod commands;
|
mod commands;
|
||||||
|
|
||||||
use poise::serenity_prelude::{self as serenity};
|
|
||||||
use std::env::var;
|
use std::env::var;
|
||||||
|
use poise::serenity_prelude::{self as serenity};
|
||||||
|
use serenity::builder::{
|
||||||
|
CreateMessage,
|
||||||
|
CreateEmbed,
|
||||||
|
CreateEmbedAuthor
|
||||||
|
};
|
||||||
|
|
||||||
type Error = Box<dyn std::error::Error + Send + Sync>;
|
type Error = Box<dyn std::error::Error + Send + Sync>;
|
||||||
|
|
||||||
@ -15,22 +20,19 @@ async fn on_ready(
|
|||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
println!("Connected to API as {}", ready.user.name);
|
println!("Connected to API as {}", ready.user.name);
|
||||||
|
|
||||||
serenity::ChannelId(BOT_READY_NOTIFY).send_message(&ctx.http, |m| m.embed(|e|
|
let message = CreateMessage::new();
|
||||||
e.color(EMBED_COLOR)
|
let ready_embed = CreateEmbed::new()
|
||||||
|
.color(EMBED_COLOR)
|
||||||
.thumbnail(ready.user.avatar_url().unwrap_or_default())
|
.thumbnail(ready.user.avatar_url().unwrap_or_default())
|
||||||
.author(|a|
|
.author(CreateEmbedAuthor::new(format!("{} is ready!", ready.user.name)).clone());
|
||||||
a.name(format!("{} is ready!", ready.user.name))
|
|
||||||
)
|
serenity::ChannelId::new(BOT_READY_NOTIFY).send_message(&ctx.http, message.add_embed(ready_embed)).await?;
|
||||||
)).await?;
|
|
||||||
|
|
||||||
let register_commands = var("REGISTER_CMDS").unwrap_or_else(|_| String::from("true")).parse::<bool>().unwrap_or(true);
|
let register_commands = var("REGISTER_CMDS").unwrap_or_else(|_| String::from("true")).parse::<bool>().unwrap_or(true);
|
||||||
|
|
||||||
if register_commands {
|
if register_commands {
|
||||||
let builder = poise::builtins::create_application_commands(&framework.options().commands);
|
let builder = poise::builtins::create_application_commands(&framework.options().commands);
|
||||||
let commands = serenity::Command::set_global_application_commands(&ctx.http, |commands| {
|
let commands = serenity::Command::set_global_commands(&ctx.http, builder).await;
|
||||||
*commands = builder.clone();
|
|
||||||
commands
|
|
||||||
}).await;
|
|
||||||
|
|
||||||
match commands {
|
match commands {
|
||||||
Ok(cmdmap) => for command in cmdmap.iter() {
|
Ok(cmdmap) => for command in cmdmap.iter() {
|
||||||
@ -47,8 +49,7 @@ async fn on_ready(
|
|||||||
async fn main() {
|
async fn main() {
|
||||||
let token = var("DISCORD_TOKEN").expect("Expected a \"DISCORD_TOKEN\" in the envvar but none was found");
|
let token = var("DISCORD_TOKEN").expect("Expected a \"DISCORD_TOKEN\" in the envvar but none was found");
|
||||||
|
|
||||||
let client = poise::Framework::builder().token(token)
|
let framework = poise::Framework::builder()
|
||||||
.intents(serenity::GatewayIntents::GUILDS)
|
|
||||||
.options(poise::FrameworkOptions {
|
.options(poise::FrameworkOptions {
|
||||||
commands: vec![
|
commands: vec![
|
||||||
commands::ping::ping(),
|
commands::ping::ping(),
|
||||||
@ -65,7 +66,9 @@ async fn main() {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.setup(|ctx, ready, framework| Box::pin(on_ready(ctx, ready, framework)))
|
.setup(|ctx, ready, framework| Box::pin(on_ready(ctx, ready, framework)))
|
||||||
.build().await.expect("Error while building the client");
|
.build();
|
||||||
|
|
||||||
|
let mut client = serenity::ClientBuilder::new(token, serenity::GatewayIntents::GUILDS).framework(framework).await.expect("Error creating client");
|
||||||
|
|
||||||
if let Err(why) = client.start().await {
|
if let Err(why) = client.start().await {
|
||||||
println!("Client error: {:?}", why);
|
println!("Client error: {:?}", why);
|
||||||
|
Loading…
Reference in New Issue
Block a user