Skip to content

Commit

Permalink
Merge branch 'main' into long-batphones
Browse files Browse the repository at this point in the history
  • Loading branch information
schuyberg committed Jul 31, 2024
2 parents 7f7d159 + 528461b commit 3f85ce0
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const {
token,
clientId,
castleDkpTokenRO,
castleDkp2TokenRW,
castleDkpAuctionRaidId,
castleDkpBonusesCharId,
sharedCharactersGoogleSheetId,
Expand Down Expand Up @@ -88,6 +89,11 @@ export const {
*/
castleDkpTokenRO?: string;

/**
* castledkp.vercel.app read/write token
*/
castleDkp2TokenRW?: string;

/**
* CastleDKP.com Raid ID for DKP auctions.
*/
Expand Down
3 changes: 1 addition & 2 deletions src/features/bp/bp-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@ To change this message, use \`/bp unset ${key}\` and then \`/bp set\` to set a n
`
if (interaction.channel){
interaction.channel.send(replyMsg) // todo: send message in channel
interaction.deleteReply();
}
interaction.deleteReply() }

}

Expand Down
19 changes: 16 additions & 3 deletions src/services/castledkp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import axiosRetry from "axios-retry";
import { partition } from "lodash";
import LRUCache from "lru-cache";
import moment from "moment";
import { castleDkpTokenRO, dkpBonusesChannelId } from "../config";
import { castleDkpTokenRO } from "../config";
import {
AdjustmentData,
RaidTick,
UPLOAD_DATE_FORMAT,
} from "../features/dkp-records/raid-tick";
import { MINUTES, MONTHS } from "../shared/time";
import { castledkp2 } from "./castledkp2";

const route = (f: string) => `api.php?function=${f}`;

Expand Down Expand Up @@ -163,7 +164,10 @@ export const castledkp = {
raid_note: `${name} ${threadUrl}`,
};
console.log("Creating new raid:", payload);
const { data } = await client.post<{ raid_id: number }>(route("add_raid"), payload);
const { data } = await client.post<{ raid_id: number }>(
route("add_raid"),
payload
);

return {
eventUrlSlug: event.name
Expand Down Expand Up @@ -203,7 +207,10 @@ export const castledkp = {
raid_note: `${tick.name} ${threadUrl}`,
};
console.log("Creating raid tick", payload);
const { data } = await client.post<{ raid_id: number }>(route("add_raid"), payload);
const { data } = await client.post<{ raid_id: number }>(
route("add_raid"),
payload
);

// add items to raid
console.log("Adding items to raid", tick.data.loot);
Expand All @@ -219,6 +226,12 @@ export const castledkp = {
) || []
);

// Temporarily create data using the beta service as well; this is not async and is fault tolerant.
// Primarily, this is being used to test the beta service by ingesting real data.
castledkp2.createRaid(tick).catch((error) => {
console.log(`Failed to create raid in beta service: ${error}`);
});

return {
eventUrlSlug: tick.data.event.name
.toLowerCase()
Expand Down
62 changes: 62 additions & 0 deletions src/services/castledkp2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import axios from "axios";
import { castleDkp2TokenRW } from "../config";
import { RaidTick } from "../features/dkp-records/raid-tick";

const client = axios.create({
baseURL: "https://castledkp.vercel.app",
headers: {
"Content-Type": "application/json",
},
});

client.interceptors.request.use((config) => {
config.headers.Authorization = `Bearer ${castleDkp2TokenRW}`;
return config;
});

export const castledkp2 = {
createRaid: async (raidTick: RaidTick) => {
if (!castleDkp2TokenRW) {
console.error("Cannot query CastleDKP2 without an RW token.");
return;
}
try {
const response = await client.post("/api/v1/raid", {
activity: {
typeId: 1,
payout: raidTick.data.value,
note: raidTick.note,
},
attendees: raidTick.data.attendees.map((name) => ({
characterName: name,
pilotCharacterName: name,
})),
adjustments: raidTick.data.adjustments?.map(
({ player, value, reason }) => ({
characterName: player,
pilotCharacterName: player,
amount: value,
reason,
})
),
purchases: raidTick.data.loot.map(({ buyer, item, price }) => ({
characterName: buyer,
pilotCharacterName: buyer,
amount: price,
itemName: item,
})),
});
return response.data;
} catch (error) {
if (axios.isAxiosError(error)) {
console.error(
"Error creating raid:",
error.response?.data || error.message
);
} else {
console.error("Error creating raid:", error);
}
throw error;
}
},
};

0 comments on commit 3f85ce0

Please sign in to comment.