Skip to content

Commit 37f6392

Browse files
committed
chore: formatting
1 parent 5a043ad commit 37f6392

File tree

16 files changed

+1253
-1426
lines changed

16 files changed

+1253
-1426
lines changed

backend/src/data/FishFish.ts

Lines changed: 110 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ const API_ROOT = "https://api.fishfish.gg/v1";
77
const zDomainCategory = z.literal(["safe", "malware", "phishing"]);
88

99
const zDomain = z.object({
10-
name: z.string(),
11-
category: zDomainCategory,
12-
description: z.string(),
13-
added: z.number(),
14-
checked: z.number(),
10+
name: z.string(),
11+
category: zDomainCategory,
12+
description: z.string(),
13+
added: z.number(),
14+
checked: z.number(),
1515
});
1616
export type FishFishDomain = z.output<typeof zDomain>;
1717

@@ -26,143 +26,123 @@ let sessionTokenPromise: Promise<string> | null = null;
2626
export class FishFishError extends Error {}
2727

2828
const zTokenResponse = z.object({
29-
expires: z.number(),
30-
token: z.string(),
29+
expires: z.number(),
30+
token: z.string(),
3131
});
3232

3333
async function getSessionToken(): Promise<string> {
34-
if (sessionTokenPromise) {
35-
return sessionTokenPromise;
36-
}
37-
38-
const apiKey = env.FISHFISH_API_KEY;
39-
if (!apiKey) {
40-
throw new FishFishError("FISHFISH_API_KEY is missing");
41-
}
42-
43-
sessionTokenPromise = (async () => {
44-
const response = await fetch(`${API_ROOT}/users/@me/tokens`, {
45-
method: "POST",
46-
headers: {
47-
Authorization: apiKey,
48-
"Content-Type": "application/json",
49-
},
50-
});
51-
52-
if (!response.ok) {
53-
throw new FishFishError(
54-
`Failed to get session token: ${response.status} ${response.statusText}`,
55-
);
56-
}
57-
58-
const parseResult = zTokenResponse.safeParse(await response.json());
59-
if (!parseResult.success) {
60-
throw new FishFishError(
61-
`Parse error when fetching session token: ${parseResult.error.message}`,
62-
);
63-
}
64-
65-
const timeUntilExpiry = parseResult.data.expires * 1000 - Date.now();
66-
setTimeout(
67-
() => {
68-
sessionTokenPromise = null;
69-
},
70-
timeUntilExpiry - 1 * MINUTES,
71-
); // Subtract a minute to ensure we refresh before expiry
72-
73-
return parseResult.data.token;
74-
})();
75-
sessionTokenPromise.catch((err) => {
76-
sessionTokenPromise = null;
77-
throw err;
78-
});
79-
80-
return sessionTokenPromise;
34+
if (sessionTokenPromise) {
35+
return sessionTokenPromise;
36+
}
37+
38+
const apiKey = env.FISHFISH_API_KEY;
39+
if (!apiKey) {
40+
throw new FishFishError("FISHFISH_API_KEY is missing");
41+
}
42+
43+
sessionTokenPromise = (async () => {
44+
const response = await fetch(`${API_ROOT}/users/@me/tokens`, {
45+
method: "POST",
46+
headers: {
47+
Authorization: apiKey,
48+
"Content-Type": "application/json",
49+
},
50+
});
51+
52+
if (!response.ok) {
53+
throw new FishFishError(`Failed to get session token: ${response.status} ${response.statusText}`);
54+
}
55+
56+
const parseResult = zTokenResponse.safeParse(await response.json());
57+
if (!parseResult.success) {
58+
throw new FishFishError(`Parse error when fetching session token: ${parseResult.error.message}`);
59+
}
60+
61+
const timeUntilExpiry = parseResult.data.expires * 1000 - Date.now();
62+
setTimeout(
63+
() => {
64+
sessionTokenPromise = null;
65+
},
66+
timeUntilExpiry - 1 * MINUTES,
67+
); // Subtract a minute to ensure we refresh before expiry
68+
69+
return parseResult.data.token;
70+
})();
71+
sessionTokenPromise.catch((err) => {
72+
sessionTokenPromise = null;
73+
throw err;
74+
});
75+
76+
return sessionTokenPromise;
8177
}
8278

83-
async function fishFishApiCall(
84-
method: string,
85-
path: string,
86-
query: Record<string, string> = {},
87-
): Promise<unknown> {
88-
const sessionToken = await getSessionToken();
89-
const queryParams = new URLSearchParams(query);
90-
const response = await fetch(
91-
`https://api.fishfish.gg/v1/${path}?${queryParams}`,
92-
{
93-
method,
94-
headers: {
95-
Authorization: sessionToken,
96-
"Content-Type": "application/json",
97-
},
98-
},
99-
);
100-
101-
if (!response.ok) {
102-
throw new FishFishError(
103-
`FishFish API call failed: ${response.status} ${response.statusText}`,
104-
);
105-
}
106-
107-
return response.json();
79+
async function fishFishApiCall(method: string, path: string, query: Record<string, string> = {}): Promise<unknown> {
80+
const sessionToken = await getSessionToken();
81+
const queryParams = new URLSearchParams(query);
82+
const response = await fetch(`https://api.fishfish.gg/v1/${path}?${queryParams}`, {
83+
method,
84+
headers: {
85+
Authorization: sessionToken,
86+
"Content-Type": "application/json",
87+
},
88+
});
89+
90+
if (!response.ok) {
91+
throw new FishFishError(`FishFish API call failed: ${response.status} ${response.statusText}`);
92+
}
93+
94+
return response.json();
10895
}
10996

11097
async function refreshFishFishDomains() {
111-
const rawData = await fishFishApiCall("GET", "domains", { full: "true" });
112-
const parseResult = z.array(zDomain).safeParse(rawData);
113-
if (!parseResult.success) {
114-
throw new FishFishError(
115-
`Parse error when refreshing domains: ${parseResult.error.message}`,
116-
);
117-
}
118-
119-
domains.clear();
120-
for (const domain of parseResult.data) {
121-
domains.set(domain.name, domain);
122-
}
123-
124-
domains.set("malware-link.test.zeppelin.gg", {
125-
name: "malware-link.test.zeppelin.gg",
126-
category: "malware",
127-
description: "",
128-
added: Date.now(),
129-
checked: Date.now(),
130-
});
131-
domains.set("phishing-link.test.zeppelin.gg", {
132-
name: "phishing-link.test.zeppelin.gg",
133-
category: "phishing",
134-
description: "",
135-
added: Date.now(),
136-
checked: Date.now(),
137-
});
138-
domains.set("safe-link.test.zeppelin.gg", {
139-
name: "safe-link.test.zeppelin.gg",
140-
category: "safe",
141-
description: "",
142-
added: Date.now(),
143-
checked: Date.now(),
144-
});
145-
146-
console.log(
147-
"[FISHFISH] Refreshed FishFish domains, total count:",
148-
domains.size,
149-
);
98+
const rawData = await fishFishApiCall("GET", "domains", { full: "true" });
99+
const parseResult = z.array(zDomain).safeParse(rawData);
100+
if (!parseResult.success) {
101+
throw new FishFishError(`Parse error when refreshing domains: ${parseResult.error.message}`);
102+
}
103+
104+
domains.clear();
105+
for (const domain of parseResult.data) {
106+
domains.set(domain.name, domain);
107+
}
108+
109+
domains.set("malware-link.test.zeppelin.gg", {
110+
name: "malware-link.test.zeppelin.gg",
111+
category: "malware",
112+
description: "",
113+
added: Date.now(),
114+
checked: Date.now(),
115+
});
116+
domains.set("phishing-link.test.zeppelin.gg", {
117+
name: "phishing-link.test.zeppelin.gg",
118+
category: "phishing",
119+
description: "",
120+
added: Date.now(),
121+
checked: Date.now(),
122+
});
123+
domains.set("safe-link.test.zeppelin.gg", {
124+
name: "safe-link.test.zeppelin.gg",
125+
category: "safe",
126+
description: "",
127+
added: Date.now(),
128+
checked: Date.now(),
129+
});
130+
131+
console.log("[FISHFISH] Refreshed FishFish domains, total count:", domains.size);
150132
}
151133

152134
export async function initFishFish() {
153-
if (!env.FISHFISH_API_KEY) {
154-
console.warn(
155-
"[FISHFISH] FISHFISH_API_KEY is not set, FishFish functionality will be disabled.",
156-
);
157-
return;
158-
}
159-
160-
await refreshFishFishDomains();
161-
// Real-time updates disabled until we switch to a WebSocket lib that supports authorization headers
162-
// void subscribeToFishFishUpdates();
163-
setInterval(() => refreshFishFishDomains(), FULL_REFRESH_INTERVAL);
135+
if (!env.FISHFISH_API_KEY) {
136+
console.warn("[FISHFISH] FISHFISH_API_KEY is not set, FishFish functionality will be disabled.");
137+
return;
138+
}
139+
140+
await refreshFishFishDomains();
141+
// Real-time updates disabled until we switch to a WebSocket lib that supports authorization headers
142+
// void subscribeToFishFishUpdates();
143+
setInterval(() => refreshFishFishDomains(), FULL_REFRESH_INTERVAL);
164144
}
165145

166146
export function getFishFishDomain(domain: string): FishFishDomain | undefined {
167-
return domains.get(domain.toLowerCase());
147+
return domains.get(domain.toLowerCase());
168148
}

backend/src/plugins/Automod/events/runAutomodOnMessage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export async function runAutomodOnMessage(
1717
isEdit: boolean,
1818
) {
1919
incrementDebugCounter("automod:runAutomodOnMessage");
20-
20+
2121
const member = await getOrFetchGuildMember(pluginData.guild, message.user_id);
2222
const user = await getOrFetchUser(pluginData.client, message.user_id);
2323

backend/src/plugins/CommandAliases/docs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ With this setup:
2727
- \`!c\` runs \`!cases\`
2828
- \`!b2 @User\` runs \`!ban -d 2 @User\`
2929
- \`!ownerinfo\` runs \`!info 754421392988045383\`
30-
`
30+
`,
3131
};

backend/src/plugins/Logs/logFunctions/logMessageDeleteAuto.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ export interface LogMessageDeleteAutoData {
2121
messageDate: string;
2222
}
2323

24-
export async function logMessageDeleteAuto(pluginData: GuildPluginData<LogsPluginType>, data: LogMessageDeleteAutoData) {
24+
export async function logMessageDeleteAuto(
25+
pluginData: GuildPluginData<LogsPluginType>,
26+
data: LogMessageDeleteAutoData,
27+
) {
2528
if (data.message.data.attachments) {
2629
for (const attachment of data.message.data.attachments as ISavedMessageAttachmentData[]) {
2730
attachment.url = useMediaUrls(attachment.url);

backend/src/plugins/Logs/util/getMessageReplyLogInfo.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { GuildPluginData } from "vety";
22
import { ISavedMessageAttachmentData, SavedMessage } from "../../../data/entities/SavedMessage.js";
33
import { messageLink, messageSummary, useMediaUrls } from "../../../utils.js";
44
import { TemplateSafeValueContainer } from "../../../templateFormatter.js";
5-
import { savedMessageToTemplateSafeSavedMessage, TemplateSafeSavedMessage } from "../../../utils/templateSafeObjects.js";
5+
import {
6+
savedMessageToTemplateSafeSavedMessage,
7+
TemplateSafeSavedMessage,
8+
} from "../../../utils/templateSafeObjects.js";
69
import { LogsPluginType } from "../types.js";
710

811
export interface MessageReplyLogInfo {

backend/src/plugins/ModActions/commands/cases/actualCasesCmd.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ export async function actualCasesCmd(
235235
show: boolean | null,
236236
) {
237237
const mod = modId
238-
? (await resolveMember(pluginData.client, pluginData.guild, modId)) || (await resolveUser(pluginData.client, modId, "ModActions:actualCasesCmd"))
238+
? (await resolveMember(pluginData.client, pluginData.guild, modId)) ||
239+
(await resolveUser(pluginData.client, modId, "ModActions:actualCasesCmd"))
239240
: null;
240241
const modName = modId ? (mod instanceof UnknownUser ? modId : renderUsername(mod!)) : renderUsername(author);
241242

backend/src/plugins/ModActions/events/CreateKickCaseOnManualKickEvt.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ export const CreateKickCaseOnManualKickEvt = modActionsEvt({
3636
`Tried to create duplicate case for audit log entry ${kickAuditLogEntry.id}, existing case id ${createdCase.id}`,
3737
);
3838
} else {
39-
mod = await resolveUser(pluginData.client, kickAuditLogEntry.executor!.id, "ModActions:CreateKickCaseOnManualKickEvt");
39+
mod = await resolveUser(
40+
pluginData.client,
41+
kickAuditLogEntry.executor!.id,
42+
"ModActions:CreateKickCaseOnManualKickEvt",
43+
);
4044

4145
const config = mod instanceof UnknownUser ? pluginData.config.get() : await pluginData.config.getForUser(mod);
4246

backend/src/plugins/ModActions/functions/banUserId.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ export async function banUserId(
6161
guildName: pluginData.guild.name,
6262
reason: reasonWithAttachments,
6363
moderator: banOptions.caseArgs?.modId
64-
? userToTemplateSafeUser(await resolveUser(pluginData.client, banOptions.caseArgs.modId, "ModActions:banUserId"))
64+
? userToTemplateSafeUser(
65+
await resolveUser(pluginData.client, banOptions.caseArgs.modId, "ModActions:banUserId"),
66+
)
6567
: null,
6668
}),
6769
);
@@ -85,7 +87,9 @@ export async function banUserId(
8587
guildName: pluginData.guild.name,
8688
reason: reasonWithAttachments,
8789
moderator: banOptions.caseArgs?.modId
88-
? userToTemplateSafeUser(await resolveUser(pluginData.client, banOptions.caseArgs.modId, "ModActions:banUserId"))
90+
? userToTemplateSafeUser(
91+
await resolveUser(pluginData.client, banOptions.caseArgs.modId, "ModActions:banUserId"),
92+
)
8993
: null,
9094
banTime: humanizeDuration(banTime),
9195
}),

backend/src/plugins/ModActions/functions/kickMember.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ export async function kickMember(
4646
guildName: pluginData.guild.name,
4747
reason: reasonWithAttachments,
4848
moderator: kickOptions.caseArgs?.modId
49-
? userToTemplateSafeUser(await resolveUser(pluginData.client, kickOptions.caseArgs.modId, "ModActions:kickMember"))
49+
? userToTemplateSafeUser(
50+
await resolveUser(pluginData.client, kickOptions.caseArgs.modId, "ModActions:kickMember"),
51+
)
5052
: null,
5153
}),
5254
);

backend/src/plugins/ModActions/functions/warnMember.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ export async function warnMember(
3535
guildName: pluginData.guild.name,
3636
reason: reasonWithAttachments,
3737
moderator: warnOptions.caseArgs?.modId
38-
? userToTemplateSafeUser(await resolveUser(pluginData.client, warnOptions.caseArgs.modId, "ModActions:warnMember"))
38+
? userToTemplateSafeUser(
39+
await resolveUser(pluginData.client, warnOptions.caseArgs.modId, "ModActions:warnMember"),
40+
)
3941
: null,
4042
}),
4143
);

0 commit comments

Comments
 (0)