Skip to content

Commit

Permalink
chore: bump all dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
imatpot committed Aug 30, 2024
1 parent 6f5a8e1 commit 294a3c4
Show file tree
Hide file tree
Showing 15 changed files with 1,095 additions and 442 deletions.
1,254 changes: 941 additions & 313 deletions Cargo.lock

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
[package]
name = "lunaro_manager"
version = "2.0.0"
version = "2.1.0"
edition = "2021"

[dependencies]
async-trait = "0.1.73"
chrono = "0.4.31"
dotenv = "0.15.0"
futures = "0.3.28"
log = "0.4.20"
log4rs = "1.2.0"
poise = { version = "0.5.6" }
regex = "1.9.6"
reqwest = "0.11.22"
rustc_version_runtime = "0.2.1"
serde = "1.0.188"
serde_json = "1.0.107"
thiserror = "1.0.49"
tokio = { version = "1.32.0", features = ["rt-multi-thread"] }
toml = "0.7.6"
uuid = { version = "1.4.1", features = ["v4"] }
async-trait = { version = "0.1.81" }
chrono = { version = "0.4.38" }
dotenv = { version = "0.15.0" }
futures = { version = "0.3.30" }
log = { version = "0.4.22" }
log4rs = { version = "1.3.0" }
poise = { version = "0.6.1" }
regex = { version = "1.10.6" }
reqwest = { version = "0.12.7" }
rustc_version_runtime = { version = "0.3.0" }
serde = { version = "1.0.209" }
serde_json = { version = "1.0.127" }
thiserror = { version = "1.0.63" }
tokio = { version = "1.40.0", features = ["rt-multi-thread"] }
toml = { version = "0.8.19" }
uuid = { version = "1.10.0", features = ["v4"] }
33 changes: 20 additions & 13 deletions src/commands/about.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use chrono::{DateTime, Utc};
use poise::command;
use poise::{command, CreateReply};
use serde::Deserialize;

use crate::{
Expand All @@ -14,6 +14,9 @@ use crate::{
struct GitHubCommit {
/// The actual commit.
commit: Commit,

/// The URL to the commit on GitHub.
html_url: String,
}

/// A Git commit.
Expand Down Expand Up @@ -75,28 +78,32 @@ pub async fn run(context: PoiseContext<'_>) -> Result<(), Error> {

let latest_commits: Vec<GitHubCommit> = serde_json::from_str(&latest_commit)?;

let latest_commit_date = match latest_commits.first() {
Some(commit) => format!("<t:{}:R>", commit.commit.committer.date.timestamp()),
None => "[unknown date]".to_string(),
let latest_commit = match latest_commits.first() {
Some(commit) => commit,
None => return Err("No commits found".into()),
};

let commit_date = format!("<t:{}:R>", latest_commit.commit.committer.date.timestamp());
let commit_url = &latest_commit.html_url;

let uptime = format!("<t:{}:R>", context.data().started_at.timestamp());

context
.send(|reply| {
reply.content(
.send(
CreateReply::default().content(
[
format!("🔎 Tracking activity of {tracked_member_count} members"),
String::new(),
format!("📦 Bot {bot_version}"),
format!("🦀 Rust Compiler {rustc_version}"),
format!("⚙️ Serenity {serenity_version} + Poise {poise_version}"),
format!("🚧 Last updated {latest_commit_date}",),
format!("⏱️ Instance went online {uptime}"),
format!("📦 [Bot](<https://github.com/imatpot/lunaro-manager>) {bot_version}"),
format!("🦀 [Rust](<https://www.rust-lang.org/>) v{rustc_version}"),
format!("⚙️ [Serenity](<https://github.com/serenity-rs/serenity>) {serenity_version} / [Poise](<https://github.com/serenity-rs/poise>) {poise_version}"),
format!("🚧 [Last updated](<{commit_url}>) {commit_date}",),
String::new(),
format!("⏱️ Started online {uptime}"),
]
.join("\n"),
)
})
),
)
.await?;

Ok(())
Expand Down
10 changes: 5 additions & 5 deletions src/commands/contribute.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use poise::command;
use poise::{command, CreateReply};

use crate::types::{error::Error, poise::PoiseContext};

/// 🤝 Let's work together
#[command(slash_command, rename = "contribute")]
pub async fn run(context: PoiseContext<'_>) -> Result<(), Error> {
context
.send(|reply| {
reply.content(
.send(
CreateReply::default().content(
[
"🤝 Feel like helping out? Create an issue or pull request on GitHub:",
"https://github.com/imatpot/lunaro-manager",
]
.join("\n"),
)
})
),
)
.await?;

Ok(())
Expand Down
8 changes: 4 additions & 4 deletions src/commands/help.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use poise::command;
use poise::{command, CreateReply};

use crate::types::{error::Error, poise::PoiseContext};

/// ❓ Learn how to use Lunaro Manager
#[command(slash_command, rename = "help")]
pub async fn run(context: PoiseContext<'_>) -> Result<(), Error> {
context
.send(|reply| {
reply.content(
.send(
CreateReply::default().content(
[
"👋 Swazdo-lah, surah!",
"",
Expand All @@ -18,7 +18,7 @@ pub async fn run(context: PoiseContext<'_>) -> Result<(), Error> {
]
.join("\n"),
)
})
)
.await?;

Ok(())
Expand Down
19 changes: 15 additions & 4 deletions src/commands/ping.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
use chrono::{DateTime, Utc};
use poise::command;
use poise::{command, CreateReply};

use crate::types::{error::Error, poise::PoiseContext};

/// 🏓 Check the bot's connection latency
#[command(slash_command, rename = "ping")]
pub async fn run(context: PoiseContext<'_>) -> Result<(), Error> {
let now = Utc::now();
let interaction_created =
DateTime::parse_from_rfc3339(&context.created_at().to_rfc3339())?.with_timezone(&Utc);

let created_at = match context.created_at().to_rfc3339() {
Some(created_at) => created_at,
None => {
context
.send(CreateReply::default().content("🏓 I'm not sure how long I've been online"))
.await?;

return Ok(());
}
};

let interaction_created = DateTime::parse_from_rfc3339(&created_at)?.with_timezone(&Utc);

let latency = now
.signed_duration_since(interaction_created)
Expand All @@ -18,7 +29,7 @@ pub async fn run(context: PoiseContext<'_>) -> Result<(), Error> {
log::debug!("Latency: {latency}ms");

context
.send(|reply| reply.content(format!("🏓 My ping is around {latency}ms")))
.send(CreateReply::default().content(format!("🏓 My ping is around {latency}ms")))
.await?;

Ok(())
Expand Down
27 changes: 13 additions & 14 deletions src/commands/rtp.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use poise::command;
use poise::{command, CreateReply};

use crate::{
env::Environment,
Expand All @@ -21,7 +21,7 @@ async fn join(context: PoiseContext<'_>) -> Result<(), Error> {
let member = &mut context
.serenity_context()
.http
.get_member(env.home_guild_id, context.author().id.0)
.get_member(env.home_guild_id.into(), context.author().id)
.await?;

rtp::add(member, context.serenity_context()).await?;
Expand All @@ -32,7 +32,10 @@ async fn join(context: PoiseContext<'_>) -> Result<(), Error> {
};

context
.send(|message| message.content(format!("🟢 {display_name} is now available for Lunaro")))
.send(
CreateReply::default()
.content(format!("🟢 {display_name} is now available for Lunaro")),
)
.await?;

Ok(())
Expand All @@ -46,7 +49,7 @@ async fn leave(context: PoiseContext<'_>) -> Result<(), Error> {
let member = &mut context
.serenity_context()
.http
.get_member(env.home_guild_id, context.author().id.0)
.get_member(env.home_guild_id, context.author().id)
.await?;

let display_name = match &member.nick {
Expand All @@ -55,11 +58,9 @@ async fn leave(context: PoiseContext<'_>) -> Result<(), Error> {
};

context
.send(|message| {
message.content(format!(
"⭕ {display_name} is no longer available for Lunaro"
))
})
.send(CreateReply::default().content(format!(
"⭕ {display_name} is no longer available for Lunaro"
)))
.await?;

rtp::remove(member, context.serenity_context()).await?;
Expand All @@ -78,11 +79,9 @@ async fn check(context: PoiseContext<'_>) -> Result<(), Error> {
};

context
.send(|message| {
message.content(format!(
"👀 There {verb} {ready_member_count} Tenno available for Lunaro"
))
})
.send(CreateReply::default().content(format!(
"👀 There {verb} {ready_member_count} Tenno available for Lunaro"
)))
.await?;

Ok(())
Expand Down
22 changes: 11 additions & 11 deletions src/commands/tracking.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use poise::command;
use poise::{command, CreateReply};

use crate::{
types::{error::Error, poise::PoiseContext},
Expand All @@ -20,11 +20,11 @@ async fn pause(context: PoiseContext<'_>) -> Result<(), Error> {
activity_tracking::deny_for(member).await?;

context
.send(|message| {
message
.content("⛔ Paused activity tracking for your account")
.ephemeral(true)
})
.send(
CreateReply::default()
.content("⛔ Paused activity tracking for your account")
.ephemeral(true),
)
.await?;

Ok(())
Expand All @@ -38,11 +38,11 @@ async fn resume(context: PoiseContext<'_>) -> Result<(), Error> {
activity_tracking::allow_for(member).await?;

context
.send(|message| {
message
.content("⚡ Resumed activity tracking for your account")
.ephemeral(true)
})
.send(
CreateReply::default()
.content("⚡ Resumed activity tracking for your account")
.ephemeral(true),
)
.await?;

Ok(())
Expand Down
13 changes: 7 additions & 6 deletions src/env.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{env, sync::OnceLock};

use dotenv::dotenv;
use poise::serenity_prelude::{GuildId, RoleId, UserId};
use regex::Regex;
use serde::Deserialize;

Expand All @@ -13,16 +14,16 @@ static CARGO_LOCK_PATH: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"),
#[derive(Default, Debug)]
pub struct Environment {
/// The bot's Discord user ID.
pub client_id: u64,
pub client_id: UserId,

/// Token to connect to the Discord API.
pub client_token: String,

/// The guild ID of the guild the bot will be used in.
pub home_guild_id: u64,
pub home_guild_id: GuildId,

/// The role ID of the role to be given to users playing Lunaro.
pub ready_role_id: u64,
pub ready_role_id: RoleId,

/// The bot's Cargo package information.
pub cargo: Cargo,
Expand Down Expand Up @@ -67,10 +68,10 @@ impl Environment {
dotenv()?;

Ok(Environment {
client_id: get_client_id()?,
client_id: get_client_id()?.into(),
client_token: get_client_token()?,
home_guild_id: get_home_guild_id()?,
ready_role_id: get_ready_role_id()?,
home_guild_id: get_home_guild_id()?.into(),
ready_role_id: get_ready_role_id()?.into(),
cargo: get_cargo()?,
})
}
Expand Down
5 changes: 1 addition & 4 deletions src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ impl RawEventHandler for EventHandlers {
};

if let Err(error) = handler {
log::warn!(
"Error while handling {:?}: {error:?}: {error}",
raw_event.event_type()
);
log::warn!("Error while handling {:?}: {error:?}: {error}", raw_event);
}
}
}
4 changes: 2 additions & 2 deletions src/events/presence_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ pub async fn handle(context: Context, presence: &Presence) -> Result<(), Error>
let env = Environment::instance();
let tracking_config = activity_tracking::Config::instance().await;

if tracking_config.is_blocked(presence.user.id.0) {
if tracking_config.is_blocked(&presence.user.id) {
return Ok(());
}

let member = &mut context
.http
.get_member(presence.guild_id.unwrap().0, presence.user.id.0)
.get_member(presence.guild_id.unwrap(), presence.user.id)
.await?;

let is_ready = member
Expand Down
3 changes: 2 additions & 1 deletion src/events/ready.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use crate::types::error::Error;
pub async fn handle(context: Context, ready: &Ready) -> Result<(), Error> {
let bot_tag = ready.user.tag();
log::info!("{} is ready", bot_tag);
context.idle().await;

context.idle();

Ok(())
}
Loading

0 comments on commit 294a3c4

Please sign in to comment.