Skip to content

Commit

Permalink
Final changes to stats command (#3)
Browse files Browse the repository at this point in the history
* feat(commands): Updated stats command to include:
- Changes since start of monitor
- Start of Monitor
  • Loading branch information
J4yTr1n1ty authored May 14, 2024
1 parent 1572d08 commit 376ecec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This is a Discord bot to provide a Profile Picture History to see how many times
- [x] Previous Profile Pictures

### v0.3.0
- [ ] Add Stats Command
- Amount of changes since monitor
- Start of Monitor
- Average changes per week, month and year
- [x] Add Stats Command
- [x] Amount of changes since monitor
- [x] Start of Monitor
- [x] Average changes per week, month and year
16 changes: 12 additions & 4 deletions src/commands/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ pub async fn run(
let user_id = i64::from(user.id); // Need to cast until I figure out how to implement the
// trait for sqlx.

let entry = sqlx::query!("SELECT discordId FROM User WHERE discordId = ?", user_id)

let user_entry = sqlx::query!("SELECT * FROM User WHERE discordId = ?", user_id)
.fetch_one(database)
.await;

match entry {
match user_entry {

Ok(record) => {
let pfps = sqlx::query!("SELECT * FROM ProfilePicture WHERE userId = ?", record.discordId).fetch_all(database).await;

Expand Down Expand Up @@ -56,15 +58,21 @@ pub async fn run(
let average_duration_in_hours = average_duration_in_seconds / 3600;
let average_duration_in_days = average_duration_in_hours / 24;


let dt = DateTime::from_timestamp(record.trackedSince.unwrap(), 0).unwrap();
let embed_author = CreateEmbedAuthor::new(format!("{}", user.tag()));
let embed_footer = CreateEmbedFooter::new("Use /monitor @member to add someone to the monitor list.");
let embed_footer = CreateEmbedFooter::new(format!("Monitored since {}", dt.to_rfc2822()));

let embed = CreateEmbed::new()
.title("Average times between profile picture changes:")
.author(embed_author)
.footer(embed_footer)
.fields(vec![
("Hours", format!("{average_duration_in_hours}"), true),
("Days", format!("{average_duration_in_days}"), true)
("Days", format!("{average_duration_in_days}"), true),
("", "".to_string(), false), // empty row for spacing
("Changes since beginning of Monitoring", format!("{count}"), false)

]);

// Respond with the average time
Expand Down

0 comments on commit 376ecec

Please sign in to comment.