Skip to content

Commit

Permalink
refactor: improve tracking ux
Browse files Browse the repository at this point in the history
  • Loading branch information
imatpot committed Aug 30, 2024
1 parent f0275e7 commit 0ac5d28
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 21 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,16 @@ Removes the configured playing role from your profile.

Lists the number of members with the playing role.

### ` /tracking pause`
### `💤 /tracking pause`

Disables activity tracking for your account. This is useful because the activity
Disables Lunaro tracking for your account. This is useful because the Lunaro
tracker will otherwise override your manually set playing status.

### `👁️ /tracking resume`

Enables Lunaro tracking for your account. Now you don't have to manually set
your playing status anymore.

### `💡 /about`

Displays details about Lunaro Manager, including amount of actively tracked
Expand Down
6 changes: 3 additions & 3 deletions src/commands/about.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
env::Environment,
traits::config_file::ConfigFile,
types::{error::Error, poise::PoiseContext},
util::activity_tracking,
util::lunaro_tracking,
};

/// Commit data from GitHub's API.
Expand Down Expand Up @@ -38,7 +38,7 @@ struct Committer {
pub async fn run(context: PoiseContext<'_>) -> Result<(), Error> {
let env = Environment::instance();

let tracking_config = activity_tracking::Config::instance().await;
let tracking_config = lunaro_tracking::Config::instance().await;
let member_count = context
.partial_guild()
.await
Expand Down Expand Up @@ -92,7 +92,7 @@ pub async fn run(context: PoiseContext<'_>) -> Result<(), Error> {
.send(
CreateReply::default().content(
[
format!("🔎 Tracking activity of {tracked_member_count} members"),
format!("🔎 Tracking Lunaro activity for {tracked_member_count} members"),
String::new(),
format!("📦 [Bot](<https://github.com/imatpot/lunaro-manager>) {bot_version}"),
format!("🦀 [Rust](<https://www.rust-lang.org/>) v{rustc_version}"),
Expand Down
16 changes: 8 additions & 8 deletions src/commands/tracking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,45 @@ use poise::{command, CreateReply};

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

/// 👁 Manage your tracking permissions
/// 🕵️ Manage your tracking permissions
#[command(slash_command, rename = "tracking", subcommands("pause", "resume"))]
pub async fn run(_context: PoiseContext<'_>) -> Result<(), Error> {
// Handled in subcommands
Ok(())
}

/// Pause activity tracking on your account
/// 💤 Pause Lunaro tracking on your account
#[command(slash_command)]
async fn pause(context: PoiseContext<'_>) -> Result<(), Error> {
let member = context.author();

activity_tracking::deny_for(member).await?;
lunaro_tracking::deny_for(member).await?;

context
.send(
CreateReply::default()
.content(" Paused activity tracking for your account")
.content("💤 Paused Lunaro tracking for your account")
.ephemeral(true),
)
.await?;

Ok(())
}

/// Resume activity tracking on your account
/// 👁️ Resume Lunaro tracking on your account
#[command(slash_command)]
async fn resume(context: PoiseContext<'_>) -> Result<(), Error> {
let member = context.author();

activity_tracking::allow_for(member).await?;
lunaro_tracking::allow_for(member).await?;

context
.send(
CreateReply::default()
.content("️ Resumed activity tracking for your account")
.content("👁️ Resumed Lunaro tracking for your account")
.ephemeral(true),
)
.await?;
Expand Down
6 changes: 3 additions & 3 deletions src/events/presence_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use crate::{
env::Environment,
traits::config_file::ConfigFile,
types::error::Error,
util::{activity_tracking, play},
util::{lunaro_tracking, play},
};

/// Handles the presence update event.
pub async fn handle(context: Context, presence: &Presence) -> Result<(), Error> {
let env = Environment::instance();
let tracking_config = activity_tracking::Config::instance().await;
let tracking_config = lunaro_tracking::Config::instance().await;

if tracking_config.is_blocked(&presence.user.id) {
return Ok(());
Expand All @@ -26,7 +26,7 @@ pub async fn handle(context: Context, presence: &Presence) -> Result<(), Error>
.has_role(&context, env.home_guild_id, env.playing_role_id)
.await?;

let is_playing_lunaro = activity_tracking::is_playing_lunaro(presence).is_ok_and(|value| value);
let is_playing_lunaro = lunaro_tracking::is_playing_lunaro(presence).is_ok_and(|value| value);

if is_playing_lunaro && !is_playing {
play::add(member, &context).await?;
Expand Down
8 changes: 4 additions & 4 deletions src/util/activity_tracking.rs → src/util/lunaro_tracking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ use crate::{errors::data::DataError, traits::config_file::ConfigFile, types::err
use super::data;

static CONFIG: OnceLock<Mutex<Config>> = OnceLock::new();
const CONFIG_FILE: &str = "activity_tracking.json";
const CONFIG_FILE: &str = "lunaro_tracking.json";

/// Configures the activity tracker's behaviour.
/// Configures the Lunaro tracker's behaviour.
#[derive(Serialize, Deserialize, Default, Debug)]
pub struct Config {
/// List of user IDs to ignore activity updates from.
/// List of user IDs to ignore Lunaro updates from.
pub blocklist: HashSet<UserId>,
}

Expand Down Expand Up @@ -91,7 +91,7 @@ pub async fn deny_for(user: &User) -> Result<(), Error> {
Ok(())
}

/// Check if a presence update includes Lunaro activity.
/// Check if a presence update includes Lunaro.
pub fn is_playing_lunaro(presence: &Presence) -> Result<bool, Error> {
let localized_lunaro = ["lunaro", "лунаро", "루나로"];

Expand Down
2 changes: 1 addition & 1 deletion src/util/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod activity_tracking;
pub mod lunaro_tracking;
pub mod data;
pub mod play;

0 comments on commit 0ac5d28

Please sign in to comment.