Skip to content

Commit

Permalink
Stops made up !Pb commands
Browse files Browse the repository at this point in the history
  • Loading branch information
fatfingers23 committed Apr 22, 2024
1 parent 023861a commit 860593c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ services:
DISCORD_TOKEN: '${DISCORD_TOKEN}'
TRACKSCAPE_API_BASE: '${TRACKSCAPE_API_BASE}'
REDIS_ADDR: '${REDIS_ADDR}'
WOM_API_KEY: '${WOM_API_KEY}'
depends_on:
- mongo
- redis
Expand Down Expand Up @@ -86,4 +87,3 @@ volumes:
networks:
trackscape-network:
driver: bridge

23 changes: 15 additions & 8 deletions trackscape-discord-shared/src/jobs/runelite_commands/pb_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{database::clan_mates::ClanMates, jobs::job_helpers::get_mongodb};
use super::get_runelite_api_url;
use anyhow::{anyhow, Ok};
use capitalize::Capitalize;
use reqwest::StatusCode;
use tokio::time::sleep;

pub async fn get_pb(message: String, player: String, guild_id: u64) -> Result<(), anyhow::Error> {
Expand All @@ -17,8 +18,19 @@ pub async fn get_pb(message: String, player: String, guild_id: u64) -> Result<()

let runelite_api_url = get_runelite_api_url().await?;
let full_url = format!("{}/chat/pb?name={}&boss={}", runelite_api_url, player, boss);
let pb = reqwest::get(full_url).await?.text().await?;
println!("PB: {}", pb);
let pb_request: reqwest::Response = reqwest::get(full_url).await?;
if pb_request.status() != StatusCode::OK {
println!(
"Failed to get pb from runelite api: {}",
pb_request.status()
);
return Err(anyhow!(
"Failed to get pb from runelite api: {}",
pb_request.status()
));
}
let pb_time = pb_request.text().await?.parse::<f64>()?;
println!("PB: {}", pb_time);

let db = get_mongodb().await;
let activity = db.pb_activities.create_or_get_activity(boss).await?;
Expand All @@ -28,12 +40,7 @@ pub async fn get_pb(message: String, player: String, guild_id: u64) -> Result<()
.await;
let _ = db
.pb_records
.create_or_update_pb_record(
clan_mate.unwrap().id,
activity.id,
guild_id,
pb.parse::<f64>()?,
)
.create_or_update_pb_record(clan_mate.unwrap().id, activity.id, guild_id, pb_time)
.await?;

Ok(())
Expand Down
3 changes: 2 additions & 1 deletion trackscape-discord-ui/src/components/General/DataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
});
let searchedTerm = ref<string>("");
let leaderBoardTitle = ref<string>(props.title);
let filteredData = computed(() => {
Expand Down Expand Up @@ -72,7 +73,7 @@
<div class="flex justify-between items-center pb-2">
<div class="flex flex-col md:w-1/2 w-full pb-2">
<h3 v-if="props.title !== ''"
class="text-lg font-medium text-neutral-content pb-1">{{props.title}}</h3>
class="text-lg font-medium text-neutral-content pb-1">{{leaderBoardTitle}}</h3>
<p v-if="props.description !== ''"
class="text-sm">{{props.description}}</p>
<input
Expand Down
3 changes: 3 additions & 0 deletions trackscape-discord-ui/src/stores/PbStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export const usePbStore = defineStore('pb', {
getSelectedActivity: (state) =>{
return state.selectedActivity;
},
getSelectedActivityName: (state) =>{
return state.selectedActivityName;
},
getRecords: (state) =>{
return state.records;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const osrsTimeDisplay = (timeInSeconds: number) => {

<DataTable
v-else
:title="`${store.$state.selectedActivityName} Leaderboard`"

:columns="columns"
:data="store.getRecords"
search-field="clan_mate.player_name"
Expand Down

0 comments on commit 860593c

Please sign in to comment.