Fix breaking changes caused by Poise update
This commit is contained in:
parent
beaeaed159
commit
21e869b053
@ -7,7 +7,7 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
poise = "0.6.1"
|
||||
reqwest = "0.11.23"
|
||||
reqwest = { version = "0.11.23", features = ["json"] }
|
||||
serde_json = "1.0.111"
|
||||
serenity = "0.12.0"
|
||||
tempfile = "3.9.0"
|
||||
|
@ -3,6 +3,12 @@ use crate::Error;
|
||||
use reqwest::get;
|
||||
use std::collections::HashMap;
|
||||
use serde_json::Value;
|
||||
use poise::CreateReply;
|
||||
use serenity::builder::{
|
||||
CreateEmbed,
|
||||
CreateEmbedAuthor,
|
||||
CreateEmbedFooter
|
||||
};
|
||||
|
||||
/// Retrieve the data from FS-Server
|
||||
#[poise::command(slash_command)]
|
||||
@ -27,7 +33,6 @@ pub async fn data(
|
||||
let slot_cap = slots["capacity"].as_i64().unwrap();
|
||||
let slot_cur = slots["used"].as_i64().unwrap();
|
||||
let daytime = server["dayTime"].as_i64().unwrap();
|
||||
// println!("{}", daytime);
|
||||
|
||||
// todo: Add careerSavegame support when passing in DSS url.
|
||||
// So I can get the following values for Autosave, Timescale and Slot usage.
|
||||
@ -37,10 +42,9 @@ pub async fn data(
|
||||
let minute = (daytime / 60 / 1000) % 60;
|
||||
let time = format!("{:02}:{:02}", hour, minute);
|
||||
|
||||
ctx.send(|m| m.embed(|e| e.color(crate::EMBED_COLOR)
|
||||
.author(|a|
|
||||
a.name(format!("{}/{}", slot_cur, slot_cap))
|
||||
)
|
||||
let embed = CreateEmbed::new().color(crate::EMBED_COLOR);
|
||||
ctx.send(CreateReply::default()
|
||||
.embed(embed
|
||||
.title(name)
|
||||
.description("*Nobody is playing*")
|
||||
.fields(vec![
|
||||
@ -51,11 +55,11 @@ pub async fn data(
|
||||
("Autosave", "xx", true),
|
||||
("Timescale", "0x", true)
|
||||
])
|
||||
.footer(|f|
|
||||
f.text("Last updated")
|
||||
)
|
||||
.author(CreateEmbedAuthor::new(format!("{}/{}", slot_cur, slot_cap)).clone())
|
||||
.footer(CreateEmbedFooter::new("Last updated").clone())
|
||||
.timestamp(poise::serenity_prelude::Timestamp::now())
|
||||
)).await?;
|
||||
)
|
||||
).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ use std::{
|
||||
};
|
||||
|
||||
const WHITELISTED_USERS: &[UserId] = &[
|
||||
UserId(190407856527376384)
|
||||
UserId::new(190407856527376384)
|
||||
];
|
||||
|
||||
/// Evaluate a piece of code
|
||||
|
33
src/main.rs
33
src/main.rs
@ -1,7 +1,16 @@
|
||||
mod commands;
|
||||
|
||||
use poise::serenity_prelude::{self as serenity};
|
||||
use std::env::var;
|
||||
use poise::serenity_prelude::{self as serenity};
|
||||
use serenity::{
|
||||
builder::{
|
||||
CreateMessage,
|
||||
CreateEmbed,
|
||||
CreateEmbedAuthor
|
||||
},
|
||||
ClientBuilder,
|
||||
GatewayIntents
|
||||
};
|
||||
|
||||
type Error = Box<dyn std::error::Error + Send + Sync>;
|
||||
|
||||
@ -15,20 +24,19 @@ async fn on_ready(
|
||||
) -> Result<(), Error> {
|
||||
println!("Connected to API as {}", ready.user.name);
|
||||
|
||||
serenity::ChannelId(BOT_READY_NOTIFY).send_message(&ctx.http, |m| m.embed(|e|
|
||||
e.color(EMBED_COLOR)
|
||||
let message = CreateMessage::new();
|
||||
let ready_embed = CreateEmbed::new()
|
||||
.color(EMBED_COLOR)
|
||||
.thumbnail(ready.user.avatar_url().unwrap_or_default())
|
||||
.author(|a| a.name(format!("{} is ready!", ready.user.name)))
|
||||
)).await?;
|
||||
.author(CreateEmbedAuthor::new(format!("{} is ready!", ready.user.name)).clone());
|
||||
|
||||
serenity::ChannelId::new(BOT_READY_NOTIFY).send_message(&ctx.http, message.add_embed(ready_embed)).await?;
|
||||
|
||||
let register_commands = var("REGISTER_CMDS").unwrap_or_else(|_| String::from("true")).parse::<bool>().unwrap_or(true);
|
||||
|
||||
if register_commands {
|
||||
let builder = poise::builtins::create_application_commands(&framework.options().commands);
|
||||
let commands = serenity::Command::set_global_application_commands(&ctx.http, |commands| {
|
||||
*commands = builder.clone();
|
||||
commands
|
||||
}).await;
|
||||
let commands = serenity::Command::set_global_commands(&ctx.http, builder).await;
|
||||
|
||||
match commands {
|
||||
Ok(cmdmap) => for command in cmdmap.iter() {
|
||||
@ -45,8 +53,7 @@ async fn on_ready(
|
||||
async fn main() {
|
||||
let token = var("DISCORD_TOKEN").expect("Expected a \"DISCORD_TOKEN\" in the envvar but none was found");
|
||||
|
||||
let client = poise::Framework::builder().token(token)
|
||||
.intents(serenity::GatewayIntents::MESSAGE_CONTENT | serenity::GatewayIntents::GUILDS)
|
||||
let framework = poise::Framework::builder()
|
||||
.options(poise::FrameworkOptions {
|
||||
commands: vec![
|
||||
commands::ping::ping(),
|
||||
@ -64,7 +71,9 @@ async fn main() {
|
||||
..Default::default()
|
||||
})
|
||||
.setup(|ctx, ready, framework| Box::pin(on_ready(ctx, ready, framework)))
|
||||
.build().await.expect("Error while building the client");
|
||||
.build();
|
||||
|
||||
let mut client = ClientBuilder::new(token, GatewayIntents::GUILDS).framework(framework).await.expect("Error creating client");
|
||||
|
||||
if let Err(why) = client.start().await {
|
||||
println!("Client error: {:?}", why);
|
||||
|
Loading…
Reference in New Issue
Block a user