Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/features/odkp/odkp-addcharacter-subcommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import {
CacheType,
ApplicationCommandOptionChoiceData,
CommandInteraction,
GuildMemberRoleManager,
} from "discord.js";
import { Subcommand } from "../../shared/command/subcommand";
import { openDkpService } from "../../services/openDkpService";
import { raiderRoleId } from "../../config";

export class OdkpAddCharacterSubcommand extends Subcommand {
constructor(name: string, description: string) {
Expand All @@ -29,6 +31,10 @@ export class OdkpAddCharacterSubcommand extends Subcommand {
public async execute(
interaction: CommandInteraction<CacheType>
): Promise<void> {
const roles = interaction.member?.roles as GuildMemberRoleManager;
if (!(roles.cache.has(raiderRoleId))) {
throw new Error("Must be a raider to use this command");
}
try {
const characters = await openDkpService.getCharacters();
await interaction.editReply("Checking a few things...");
Expand Down
6 changes: 6 additions & 0 deletions src/features/odkp/odkp-character-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import {
CacheType,
ApplicationCommandOptionChoiceData,
CommandInteraction,
GuildMemberRoleManager,
} from "discord.js";
import { Subcommand } from "../../shared/command/subcommand";
import {
openDkpService,
odkpCharacterCache,
} from "../../services/openDkpService";
import { capitalize } from "../../shared/util";
import { raiderRoleId } from "../../config";

export class OdkpGetSubcommand extends Subcommand {
public async getOptionAutocomplete(
Expand Down Expand Up @@ -37,6 +39,10 @@ export class OdkpGetSubcommand extends Subcommand {
public async execute(
interaction: CommandInteraction<CacheType>
): Promise<void> {
const roles = interaction.member?.roles as GuildMemberRoleManager;
if (!(roles.cache.has(raiderRoleId))) {
throw new Error("Must be a raider to use this command");
}
try {
const character = this.getRequiredOptionValue<string>(
"character",
Expand Down
6 changes: 6 additions & 0 deletions src/features/odkp/odkp-get-subcommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import {
CacheType,
ApplicationCommandOptionChoiceData,
CommandInteraction,
GuildMemberRoleManager,
} from "discord.js";
import { Subcommand } from "../../shared/command/subcommand";
import {
openDkpService,
odkpCharacterCache,
} from "../../services/openDkpService";
import { capitalize } from "../../shared/util";
import { raiderRoleId } from "../../config";

export class OdkpGetSubcommand extends Subcommand {
public async getOptionAutocomplete(
Expand Down Expand Up @@ -37,6 +39,10 @@ export class OdkpGetSubcommand extends Subcommand {
public async execute(
interaction: CommandInteraction<CacheType>
): Promise<void> {
const roles = interaction.member?.roles as GuildMemberRoleManager;
if (!(roles.cache.has(raiderRoleId))) {
throw new Error("Must be a raider to use this command");
}
try {
const character = this.getRequiredOptionValue<string>(
"character",
Expand Down
8 changes: 7 additions & 1 deletion src/features/odkp/odkp-itemhistory-subcommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ApplicationCommandOptionChoiceData,
CommandInteraction,
EmbedBuilder,
GuildMemberRoleManager,
} from "discord.js";
import { Subcommand } from "../../shared/command/subcommand";
import {
Expand All @@ -12,6 +13,7 @@ import {
ODKPItemHistoryEntry,
} from "../../services/openDkpService";
import moment from "moment";
import { raiderRoleId } from "../../config";

export class OdkpItemHistorySubcommand extends Subcommand {
public async getOptionAutocomplete(
Expand All @@ -35,6 +37,10 @@ export class OdkpItemHistorySubcommand extends Subcommand {
public async execute(
interaction: CommandInteraction<CacheType>
): Promise<void> {
const roles = interaction.member?.roles as GuildMemberRoleManager;
if (!(roles.cache.has(raiderRoleId))) {
throw new Error("Must be a raider to use this command");
}
try {
const itemName = this.getRequiredOptionValue<string>("item", interaction);
await interaction.editReply({
Expand Down Expand Up @@ -128,5 +134,5 @@ export class OdkpItemHistorySubcommand extends Subcommand {
export const odkpItemHistorySubcommand = new OdkpItemHistorySubcommand(
"itemhistory",
"View DKP purchase history and statistics for an item",
false
true
);
6 changes: 6 additions & 0 deletions src/features/odkp/odkp-top-subcommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import {
ApplicationCommandOptionChoiceData,
CommandInteraction,
EmbedBuilder,
GuildMemberRoleManager,
} from "discord.js";
import { Subcommand } from "../../shared/command/subcommand";
import { openDkpService } from "../../services/openDkpService";
import { raiderRoleId } from "../../config";

export class OdkpTopSubcommand extends Subcommand {
public async getOptionAutocomplete(
Expand All @@ -19,6 +21,10 @@ export class OdkpTopSubcommand extends Subcommand {
public async execute(
interaction: CommandInteraction<CacheType>
): Promise<void> {
const roles = interaction.member?.roles as GuildMemberRoleManager;
if (!(roles.cache.has(raiderRoleId))) {
throw new Error("Must be a raider to use this command");
}
try {
const count = this.getOptionValue<number>("count", interaction) ?? 15;
const summary = await openDkpService.getDkpSummary();
Expand Down
77 changes: 73 additions & 4 deletions src/services/openDkpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,28 @@ export interface ODKPDkpSummaryEntry {
CharacterRank: string;
}

export interface ODKPCharacterDkpSummary {
CurrentDKP: number;
CharacterId: number;
CharacterName: string;
CharacterClass: string;
CharacterRank: string;
CharacterLevel: number;
CharacterStatus: string;
AttendedTicks_30: number;
TotalTicks_30: number;
Calculated_30: number;
AttendedTicks_60: number;
TotalTicks_60: number;
Calculated_60: number;
AttendedTicks_90: number;
TotalTicks_90: number;
Calculated_90: number;
AttendedTicks_Life: number;
TotalTicks_Life: number;
Calculated_Life: number;
}

interface ODKPCharacterData {
ClientId: string;
CharacterId: number;
Expand Down Expand Up @@ -331,6 +353,10 @@ export const openDkpService = {
getCharacterSummary: async (character: string): Promise<string> => {
const characterInfo = await openDkpService.getCharacter(character);
if (!characterInfo) throw new Error(`Character ${character} not found`);
const allCharactersSummary = await openDkpService.getDkpSummary();
const characterDkpSummary = allCharactersSummary.find(
(c) => c.CharacterId === characterInfo.CharacterId
);
const config = {
method: "get",
url: `https://api.opendkp.com/clients/${openDkpClientName}/characters/${characterInfo.CharacterId}/dkp`,
Expand All @@ -341,7 +367,10 @@ export const openDkpService = {
try {
const response = await axios(config);
if (response.data[0]) {
return openDkpService.formatForDiscord(response.data);
return openDkpService.formatSummaryForDiscord(
response.data,
characterDkpSummary
);
}
return "Error";
} catch (error) {
Expand Down Expand Up @@ -377,7 +406,10 @@ export const openDkpService = {
);
},

formatForDiscord: (data: any[]) => {
formatSummaryForDiscord: (
data: any[],
characterDkpSummary?: ODKPCharacterDkpSummary
) => {
const summary = openDkpService.summarizeByCharacter(data);

const COL = { name: 20, raid: 8, adj: 8, items: 8, total: 8 };
Expand Down Expand Up @@ -421,11 +453,48 @@ export const openDkpService = {
foot.Total.toFixed(1).padStart(COL.total),
].join(" ");

let overview = "";
if (characterDkpSummary) {
const ATT_COL = { label: 12, col: 12 };

const attHeader = [
"".padEnd(ATT_COL.label),
"30d".padStart(ATT_COL.col),
"60d".padStart(ATT_COL.col),
"90d".padStart(ATT_COL.col),
"Lifetime".padStart(ATT_COL.col),
].join(" ");

const attDivider = "─".repeat(attHeader.length);

const attendanceRow = [
"Attendance".padEnd(ATT_COL.label),
`${(characterDkpSummary.Calculated_30 * 100).toFixed(1)}%`.padStart(ATT_COL.col),
`${(characterDkpSummary.Calculated_60 * 100).toFixed(1)}%`.padStart(ATT_COL.col),
`${(characterDkpSummary.Calculated_90 * 100).toFixed(1)}%`.padStart(ATT_COL.col),
`${(characterDkpSummary.Calculated_Life * 100).toFixed(1)}%`.padStart(ATT_COL.col),
].join(" ");

const ticksRow = [
"Ticks".padEnd(ATT_COL.label),
`${characterDkpSummary.AttendedTicks_30}/${characterDkpSummary.TotalTicks_30}`.padStart(ATT_COL.col),
`${characterDkpSummary.AttendedTicks_60}/${characterDkpSummary.TotalTicks_60}`.padStart(ATT_COL.col),
`${characterDkpSummary.AttendedTicks_90}/${characterDkpSummary.TotalTicks_90}`.padStart(ATT_COL.col),
`${characterDkpSummary.AttendedTicks_Life}/${characterDkpSummary.TotalTicks_Life}`.padStart(ATT_COL.col),
].join(" ");

overview =
"```\n" +
[attHeader, attDivider, attendanceRow, ticksRow].join("\n") +
"\n```\n";
}

return (
"```\n" + [header, divider, ...rows, divider, footer].join("\n") + "\n```"
"```\n" + [header, divider, ...rows, divider, footer].join("\n") + "\n```" +
overview
);
},
getDkpSummary: async (): Promise<ODKPDkpSummaryEntry[]> => {
getDkpSummary: async (): Promise<ODKPCharacterDkpSummary[]> => {
const config = {
method: "get",
url: `https://api.opendkp.com/clients/${openDkpClientName}/dkp`,
Expand Down
Loading