Skip to content

Commit 374fd74

Browse files
authored
Added bp logging (#163)
1 parent fc4f77a commit 374fd74

File tree

2 files changed

+80
-63
lines changed

2 files changed

+80
-63
lines changed

src/features/bp/bp-command.ts

+79-62
Original file line numberDiff line numberDiff line change
@@ -14,83 +14,66 @@ import { batphoneChannelId, raiderRoleId, wakeupChannelId } from "../../config";
1414
import { authorizeByMemberRoles } from "../../shared/command/util";
1515
import { officerRoleId, modRoleId, knightRoleId } from "../../config";
1616
import { error } from "console";
17-
import { redisClient } from "../../redis/client";
18-
import { isObject } from "lodash";
1917
import { container } from "tsyringe";
2018
import { WakeupService } from "../wakeup/wakeup.service";
2119
import { truncate } from "lodash";
2220
import { RequestBotButtonCommand } from "./request-bot-button-command";
2321
import { PublicAccountsFactory } from "../../services/bot/bot-factory";
2422
import { LocationService } from "../../services/location";
25-
import { PrismaClient } from "@prisma/client";
2623

2724
class sendBp extends Subcommand {
2825
public async execute(interaction: CommandInteraction<CacheType>) {
29-
// authorize
30-
authorizeByMemberRoles(
31-
[officerRoleId, modRoleId, knightRoleId],
32-
interaction
33-
);
26+
try {
27+
// authorize
28+
authorizeByMemberRoles(
29+
[officerRoleId, modRoleId, knightRoleId],
30+
interaction
31+
);
3432

35-
const bpChannel = await getTextChannel(batphoneChannelId);
36-
const val = this.getOption("message", interaction)?.value as string;
37-
// const savedMsg = await redisClient.hGet("bp", String(val));
38-
const savedBp = await prismaClient.batphone.findFirst({
39-
where: {
40-
key: val,
41-
},
42-
});
43-
const message = savedBp?.message || val;
44-
if (typeof message === "string") {
45-
const formattedMessage = message.replace(
46-
/\\n/g,
47-
`
33+
const bpChannel = await getTextChannel(batphoneChannelId);
34+
const val = this.getOption("message", interaction)?.value as string;
35+
// const savedMsg = await redisClient.hGet("bp", String(val));
36+
const savedBp = await prismaClient.batphone.findFirst({
37+
where: {
38+
key: val,
39+
},
40+
});
41+
savedBp
42+
? console.log(
43+
`Found saved batphone ${savedBp.key} for ${savedBp.location}`
44+
)
45+
: console.log(`No key found for ${val}`);
46+
const message = savedBp?.message || val;
47+
if (typeof message === "string") {
48+
const formattedMessage = message.replace(
49+
/\\n/g,
50+
`
4851
`
49-
);
50-
const components: ActionRowBuilder<MessageActionRowComponentBuilder>[] =
51-
await this.getBotButtonComponents(savedBp?.location || "");
52-
await bpChannel.send({
53-
content:
54-
`[${interaction.user}] <@&${raiderRoleId}>
52+
);
53+
const components: ActionRowBuilder<MessageActionRowComponentBuilder>[] =
54+
await getBotButtonComponents(savedBp?.location || "");
55+
await bpChannel.send({
56+
content:
57+
`[${interaction.user}] <@&${raiderRoleId}>
5558
` + formattedMessage,
56-
components: savedBp?.location ? components : undefined,
57-
});
59+
components: savedBp?.location ? components : undefined,
60+
});
5861

59-
interaction.editReply("Batphone posted: " + message);
62+
interaction.editReply("Batphone posted: " + message);
6063

61-
// Wakeup
62-
if (wakeupChannelId) {
63-
const wakeupService = container.resolve(WakeupService);
64-
wakeupService.runWakeup(
65-
`Batphone. ${interaction.user} sent ${message}`
66-
);
67-
}
68-
} else {
69-
interaction.editReply("Failed to post batphone.");
70-
}
71-
}
72-
73-
private async getBotButtonComponents(location: string) {
74-
const bots = await PublicAccountsFactory.getService().getBotsForBatphone(
75-
location
76-
);
77-
const components: ActionRowBuilder<MessageActionRowComponentBuilder>[] = [];
78-
let row;
79-
for (let i = 0; i < bots.length; i++) {
80-
if (i % 5 === 0) {
81-
row = new ActionRowBuilder<MessageActionRowComponentBuilder>({
82-
type: ComponentType.ActionRow,
83-
components: [],
84-
});
85-
components.push(row);
64+
// Wakeup
65+
if (wakeupChannelId) {
66+
const wakeupService = container.resolve(WakeupService);
67+
wakeupService.runWakeup(
68+
`Batphone. ${interaction.user} sent ${message}`
69+
);
70+
}
71+
} else {
72+
interaction.editReply("Failed to post batphone.");
8673
}
87-
row?.addComponents(
88-
new RequestBotButtonCommand(
89-
`requestbot_${bots[i].name}`
90-
).getButtonBuilder(bots[i])
91-
);
74+
} catch (error: unknown) {
75+
console.log("Failed to post batphone: " + error);
9276
}
93-
return components;
9477
}
9578

9679
public async getOptionAutocomplete(
@@ -117,6 +100,30 @@ class sendBp extends Subcommand {
117100
}
118101
}
119102

103+
export const getBotButtonComponents = async (location: string) => {
104+
const bots = await PublicAccountsFactory.getService().getBotsForBatphone(
105+
location
106+
);
107+
const components: ActionRowBuilder<MessageActionRowComponentBuilder>[] = [];
108+
let row;
109+
for (let i = 0; i < bots.length; i++) {
110+
if (i % 5 === 0) {
111+
row = new ActionRowBuilder<MessageActionRowComponentBuilder>({
112+
type: ComponentType.ActionRow,
113+
components: [],
114+
});
115+
components.push(row);
116+
}
117+
console.log(`adding button for ${bots[i].name}`);
118+
row?.addComponents(
119+
new RequestBotButtonCommand(
120+
`requestbot_${bots[i].name}`
121+
).getButtonBuilder(bots[i])
122+
);
123+
}
124+
return components;
125+
};
126+
120127
class setBp extends Subcommand {
121128
public async execute(interaction: CommandInteraction<CacheType>) {
122129
// authorize
@@ -279,8 +286,18 @@ ${formattedMessage}
279286
Location: ${savedMsg?.location || "NO LOCATION SET"}
280287
To change this message, use \`/bp unset ${key}\` and then \`/bp set\` to set a new message.
281288
`;
289+
savedMsg
290+
? console.log(
291+
`Found saved batphone ${savedMsg.key} for ${savedMsg.location}`
292+
)
293+
: console.log(`No key found for ${val}`);
294+
const components: ActionRowBuilder<MessageActionRowComponentBuilder>[] =
295+
await getBotButtonComponents(savedMsg?.location || "");
282296
if (interaction.channel) {
283-
interaction.channel.send(replyMsg); // todo: send message in channel
297+
interaction.channel.send({
298+
content: replyMsg,
299+
components: savedMsg?.location ? components : undefined,
300+
}); // todo: send message in channel
284301
interaction.deleteReply();
285302
}
286303
}

src/features/raider-enlistment/update-raider-action.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class UpdateRaiderInfoAction extends InstructionsReadyAction {
2727
title: `Join the Raid Force`,
2828
description: `📜 **Raider Requirements**
2929
- Read and understand the Castle DKP rules (https://tinyurl.com/rules-castle-dkp)
30-
- Understand raid level requirements (https://discord.com/channels/539189546630381579/995406820950675558/1251567586773045318)
30+
- Understand raid level requirements in the DKP rules and pinned announcement: https://discord.com/channels/539189546630381579/995406820950675558/1251567586773045318
3131
- Not raiding with any other guilds
3232
- Not PvP flagged
3333

0 commit comments

Comments
 (0)