From 3dd3a3860a8cea87fad96bcb8b9662a578dd15d4 Mon Sep 17 00:00:00 2001 From: washbin <76929116+washbin@users.noreply.github.com> Date: Wed, 12 Oct 2022 21:58:51 +0545 Subject: [PATCH] chore: rename teams to leaderboard in command and some places throughout the codebase --- REQUIREMENTS.md | 16 ++++++++++++---- src/api/team.rs | 6 +++--- src/commands/{teams.rs => leaderboard.rs} | 10 +++++----- src/commands/mod.rs | 2 +- src/commands/team.rs | 8 ++++---- src/events.rs | 10 +++++----- src/fuzzy.rs | 10 +++++----- 7 files changed, 35 insertions(+), 27 deletions(-) rename src/commands/{teams.rs => leaderboard.rs} (92%) diff --git a/REQUIREMENTS.md b/REQUIREMENTS.md index 904497e..feaf092 100644 --- a/REQUIREMENTS.md +++ b/REQUIREMENTS.md @@ -11,10 +11,18 @@ # TODO -- [x] Teams +### HackSquad +- [x] Individual Team - [x] Score - [x] Total PRs - [x] Total PRs Deleted -- [ ] Users - - [ ] Search - - [ ] Info (no email) +- [x] Leaderboard + - [x] Total Score + - [x] All PRs + - [x] Deleted PRs + +### Novu +- [x] Contibutor / Hero + - [x] Info + - [x] Search +- [x] Random Contibutor \ No newline at end of file diff --git a/src/api/team.rs b/src/api/team.rs index de694a8..6c5355c 100644 --- a/src/api/team.rs +++ b/src/api/team.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use crate::{CONFIG, DATABASE}; #[derive(Deserialize, Debug, Serialize)] -pub struct TeamsResponse { +pub struct LeaderboardResponse { pub teams: Vec, } @@ -34,10 +34,10 @@ pub struct PR { pub url: String, } -pub async fn get_teams() -> Vec { +pub async fn get_leaderboard() -> Vec { let db = DATABASE.lock().await; - db.request::( + db.request::( "https://www.hacksquad.dev/api/leaderboard", "leaderboard", CONFIG.lock().await.cache_leaderboard_ttl, diff --git a/src/commands/teams.rs b/src/commands/leaderboard.rs similarity index 92% rename from src/commands/teams.rs rename to src/commands/leaderboard.rs index 554e310..92c5704 100644 --- a/src/commands/teams.rs +++ b/src/commands/leaderboard.rs @@ -5,22 +5,22 @@ use serenity::model::prelude::interaction::Interaction; use serenity::prelude::Context; use serenity::utils::Color; -use crate::api::team::get_teams; +use crate::api::team::get_leaderboard; use crate::pagination::Pagination; use crate::PAGINATION; pub async fn run(ctx: Context, command: ApplicationCommandInteraction) { - let teams = get_teams().await; + let leaderboard = get_leaderboard().await; let mut pages = Vec::new(); - for team_list in teams.chunks(8) { + for team_list in leaderboard.chunks(8) { let mut description = String::new(); for team in team_list { description += &format!( "**[{}](https://hacksquad.dev/team/{})**\n<:reply_multi:1029067132572549142>`đŸĨ‡`Rank: `{}`\n<:reply:1029065416905076808>Points: `{}`\n", team.name.clone(), team.slug, - teams.iter().position(|r| r.slug == team.slug).unwrap() + 1, + leaderboard.iter().position(|r| r.slug == team.slug).unwrap() + 1, team.score ) } @@ -93,5 +93,5 @@ pub async fn handle_interaction( } pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { - command.name("teams").description("Leaderboard") + command.name("leaderboard").description("Get the HackSquad Leaderboard") } diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 2900d39..edef01d 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,3 +1,3 @@ pub mod hero; pub mod team; -pub mod teams; +pub mod leaderboard; diff --git a/src/commands/team.rs b/src/commands/team.rs index f5ef322..a58d6f5 100644 --- a/src/commands/team.rs +++ b/src/commands/team.rs @@ -10,7 +10,7 @@ use serenity::model::prelude::ReactionType; use serenity::prelude::Context; use serenity::utils::Colour; -use crate::api::team::{get_team, get_teams, PR}; +use crate::api::team::{get_team, get_leaderboard, PR}; use crate::fuzzy::search_teams; fn link_button(name: &str, link: String, emoji: ReactionType) -> CreateButton { @@ -34,7 +34,7 @@ pub async fn run(ctx: Context, command: ApplicationCommandInteraction) { if let CommandDataOptionValue::String(team_id) = option { let team = get_team(team_id).await; - let teams = get_teams().await; + let leaderboard = get_leaderboard().await; let mut pull_req = String::new(); let mut user_list = String::new(); @@ -94,7 +94,7 @@ pub async fn run(ctx: Context, command: ApplicationCommandInteraction) { let data = format!( "`ℹī¸` **Information**\n<:reply_multi:1029067132572549142>**Name:** {}\n<:reply_multi:1029067132572549142>**Rank:**`{}`\n<:reply_multi:1029067132572549142>**Score:** `{}`\n<:reply_multi:1029067132572549142>**Total PRs:** `{}`\n<:reply:1029065416905076808>**Total PRs Deleted:** `{}`\n\n`🏆` **Team Members**\n{}\n`🔗` **Last 3 PRs**\n{}", team.name, - teams.iter().position(|r| r.slug == team.slug).unwrap() + 1, + leaderboard.iter().position(|r| r.slug == team.slug).unwrap() + 1, team.score, team.score + deleted, deleted, @@ -128,7 +128,7 @@ pub async fn run(ctx: Context, command: ApplicationCommandInteraction) { response .kind(InteractionResponseType::ChannelMessageWithSource) .interaction_response_data(|message| { - message.content("Please provide a valid teams") + message.content("Please provide a valid team") }) }) .await diff --git a/src/events.rs b/src/events.rs index aa94356..e0be024 100644 --- a/src/events.rs +++ b/src/events.rs @@ -16,22 +16,22 @@ impl EventHandler for Handler { match interaction { Interaction::ApplicationCommand(ref command) => match command.data.name.as_str() { "team" => commands::team::run(ctx, command.to_owned()).await, - "teams" => commands::teams::run(ctx, command.to_owned()).await, + "leaderboard" => commands::leaderboard::run(ctx, command.to_owned()).await, "hero" => commands::hero::hero(ctx, command.to_owned()).await, "randomhero" => commands::hero::random_hero(ctx, command.to_owned()).await, other_commands => println!("Unknown command {}", other_commands), }, Interaction::MessageComponent(ref component) => match component.message.interaction { Some(ref message_interaction) => match message_interaction.name.as_str() { - "teams" => { - commands::teams::handle_interaction( + "leaderboard" => { + commands::leaderboard::handle_interaction( ctx, component.to_owned(), interaction.to_owned(), ) .await } - _ => println!("We only handle component interaction in teams command"), + _ => println!("We only handle component interaction in leaderboard command"), }, None => println!("No interaction"), }, @@ -57,7 +57,7 @@ impl EventHandler for Handler { let commands = GuildId::set_application_commands(&guild_id, &ctx.http, |commands| { commands.create_application_command(|command| commands::team::register(command)); - commands.create_application_command(|command| commands::teams::register(command)); + commands.create_application_command(|command| commands::leaderboard::register(command)); commands.create_application_command(|command| { commands::hero::register_random_hero(command) }); diff --git a/src/fuzzy.rs b/src/fuzzy.rs index 5723341..0411fd5 100644 --- a/src/fuzzy.rs +++ b/src/fuzzy.rs @@ -2,7 +2,7 @@ use serde::Serialize; use serde_json::{json, Value}; use simsearch::{SearchOptions, SimSearch}; -use crate::api::team::{get_teams, Team}; +use crate::api::team::{get_leaderboard, Team}; #[derive(Serialize, Debug)] struct Suggestion { @@ -12,12 +12,12 @@ struct Suggestion { pub async fn search_teams(query: Option) -> Value { if let Some(query) = query { - let teams = get_teams().await; + let leaderboard = get_leaderboard().await; let mut engine = SimSearch::new_with(SearchOptions::new().case_sensitive(false).threshold(0.82)); - for team in &teams { + for team in &leaderboard { engine.insert(team.slug.clone(), &team.name); } @@ -26,7 +26,7 @@ pub async fn search_teams(query: Option) -> Value { let mut res = engine.search(&query); if res.is_empty() { - for team in &teams { + for team in &leaderboard { res.push(team.slug.clone()) } @@ -42,7 +42,7 @@ pub async fn search_teams(query: Option) -> Value { let mut suggestions: Vec = Vec::new(); for (_index, slug) in iter.enumerate() { - let team = teams.iter().find(|&p| p.slug == slug.clone()).cloned(); + let team = leaderboard.iter().find(|&p| p.slug == slug.clone()).cloned(); if let Some(team) = team { suggestions.push(team);