feat: set presence info on ready again
Signed-off-by: seth <getchoo@tuta.io>
This commit is contained in:
parent
1c168bd8ba
commit
5b16c14b45
5 changed files with 55 additions and 5 deletions
|
@ -9,7 +9,7 @@ const DADJOKE: &str = "https://icanhazdadjoke.com";
|
|||
pub async fn get_joke() -> Result<String> {
|
||||
let req = REQWEST_CLIENT.get(DADJOKE).build()?;
|
||||
|
||||
info!("making request to {}", req.url());
|
||||
info!("Making request to {}", req.url());
|
||||
let resp = REQWEST_CLIENT.execute(req).await?;
|
||||
let status = resp.status();
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use once_cell::sync::Lazy;
|
||||
|
||||
pub mod dadjoke;
|
||||
pub mod prism_meta;
|
||||
pub mod rory;
|
||||
|
||||
pub static USER_AGENT: Lazy<String> = Lazy::new(|| {
|
||||
|
|
41
src/api/prism_meta.rs
Normal file
41
src/api/prism_meta.rs
Normal file
|
@ -0,0 +1,41 @@
|
|||
use crate::api::REQWEST_CLIENT;
|
||||
|
||||
use color_eyre::eyre::{eyre, Result};
|
||||
use log::*;
|
||||
use reqwest::StatusCode;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct MinecraftPackageJson {
|
||||
pub format_version: u8,
|
||||
pub name: String,
|
||||
pub recommended: Vec<String>,
|
||||
pub uid: String,
|
||||
}
|
||||
|
||||
const PRISM_META: &str = "https://meta.prismlauncher.org/v1";
|
||||
const MINECRAFT_PACKAGEJSON_ENDPOINT: &str = "/net.minecraft/package.json";
|
||||
|
||||
pub async fn get_latest_minecraft_version() -> Result<String> {
|
||||
let req = REQWEST_CLIENT
|
||||
.get(format!("{PRISM_META}{MINECRAFT_PACKAGEJSON_ENDPOINT}"))
|
||||
.build()?;
|
||||
|
||||
info!("Making request to {}", req.url());
|
||||
let resp = REQWEST_CLIENT.execute(req).await?;
|
||||
let status = resp.status();
|
||||
|
||||
if let StatusCode::OK = status {
|
||||
let data = resp.json::<MinecraftPackageJson>().await?;
|
||||
let version = data
|
||||
.recommended
|
||||
.first()
|
||||
.ok_or_else(|| eyre!("Couldn't find first recommended version!"))?;
|
||||
|
||||
Ok(version.clone())
|
||||
} else {
|
||||
Err(eyre!(
|
||||
"Failed to get latest Minecraft version from {PRISM_META}{MINECRAFT_PACKAGEJSON_ENDPOINT} with {status}",
|
||||
))
|
||||
}
|
||||
}
|
|
@ -27,7 +27,7 @@ pub async fn get_rory(id: Option<u64>) -> Result<RoryResponse> {
|
|||
.get(format!("{RORY}{ENDPOINT}/{target}"))
|
||||
.build()?;
|
||||
|
||||
info!("making request to {}", req.url());
|
||||
info!("Making request to {}", req.url());
|
||||
let resp = REQWEST_CLIENT.execute(req).await?;
|
||||
let status = resp.status();
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use crate::Data;
|
||||
use crate::{api, Data};
|
||||
|
||||
use color_eyre::eyre::{Report, Result};
|
||||
use poise::serenity_prelude::Context;
|
||||
use log::*;
|
||||
use poise::serenity_prelude::{Activity, Context, OnlineStatus};
|
||||
use poise::{Event, FrameworkContext};
|
||||
|
||||
mod delete;
|
||||
|
@ -17,13 +18,20 @@ pub async fn handle(
|
|||
) -> Result<()> {
|
||||
match event {
|
||||
Event::Ready { data_about_bot } => {
|
||||
log::info!("Logged in as {}!", data_about_bot.user.name)
|
||||
info!("Logged in as {}!", data_about_bot.user.name);
|
||||
|
||||
let latest_minecraft_version = api::prism_meta::get_latest_minecraft_version().await?;
|
||||
let activity = Activity::playing(format!("Minecraft {}", latest_minecraft_version));
|
||||
|
||||
info!("Setting presence to activity {activity:#?}");
|
||||
ctx.set_presence(Some(activity), OnlineStatus::Online).await;
|
||||
}
|
||||
|
||||
Event::Message { new_message } => {
|
||||
// ignore new messages from bots
|
||||
// NOTE: the webhook_id check allows us to still respond to PK users
|
||||
if new_message.author.bot && new_message.webhook_id.is_none() {
|
||||
debug!("Ignoring message {} from bot", new_message.id);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue