Add discord URL generation
This commit is contained in:
parent
2e9d3167cb
commit
e9bc791f7d
|
@ -37,3 +37,9 @@ export type LFGMember = {
|
||||||
name: string;
|
name: string;
|
||||||
joined?: boolean;
|
joined?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type UrlIds = {
|
||||||
|
guildId: bigint;
|
||||||
|
channelId: bigint;
|
||||||
|
messageId: bigint;
|
||||||
|
};
|
||||||
|
|
20
src/utils.ts
20
src/utils.ts
|
@ -1,9 +1,23 @@
|
||||||
import { Interaction, log, LT, Message } from '../deps.ts';
|
import { CreateMessage, Interaction, log, LT, Message } from '../deps.ts';
|
||||||
|
import { UrlIds } from './types/commandTypes.ts';
|
||||||
|
|
||||||
const jsonStringifyBig = (input: any) => {
|
const jsonStringifyBig = (input: any) => {
|
||||||
return JSON.stringify(input, (_key, value) => typeof value === 'bigint' ? value.toString() + 'n' : value);
|
return JSON.stringify(input, (_key, value) => typeof value === 'bigint' ? value.toString() + 'n' : value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Get/Generate Discord Message URL
|
||||||
|
const idsToMessageUrl = (ids: UrlIds) => `https://discord.com/channels/${ids.guildId}/${ids.channelId}/${ids.messageId}`;
|
||||||
|
const messageUrlToIds = (url: string): UrlIds => {
|
||||||
|
url = url.toLowerCase();
|
||||||
|
const [guildId, channelId, messageId] = (url.split('channels')[1] || '').split('/');
|
||||||
|
|
||||||
|
return {
|
||||||
|
guildId: BigInt(guildId || '0'),
|
||||||
|
channelId: BigInt(channelId || '0'),
|
||||||
|
messageId: BigInt(messageId || '0'),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const genericLogger = (level: LT, message: string) => log(level, message);
|
const genericLogger = (level: LT, message: string) => log(level, message);
|
||||||
const interactionSendError = (location: string, interaction: Interaction | string, err: Error) =>
|
const interactionSendError = (location: string, interaction: Interaction | string, err: Error) =>
|
||||||
genericLogger(LT.ERROR, `${location} | Failed to respond to interaction: ${jsonStringifyBig(interaction)} | Error: ${err.name} - ${err.message}`);
|
genericLogger(LT.ERROR, `${location} | Failed to respond to interaction: ${jsonStringifyBig(interaction)} | Error: ${err.name} - ${err.message}`);
|
||||||
|
@ -11,7 +25,7 @@ const messageEditError = (location: string, message: Message | string, err: Erro
|
||||||
genericLogger(LT.ERROR, `${location} | Failed to edit message: ${jsonStringifyBig(message)} | Error: ${err.name} - ${err.message}`);
|
genericLogger(LT.ERROR, `${location} | Failed to edit message: ${jsonStringifyBig(message)} | Error: ${err.name} - ${err.message}`);
|
||||||
const messageGetError = (location: string, message: Message | string, err: Error) =>
|
const messageGetError = (location: string, message: Message | string, err: Error) =>
|
||||||
genericLogger(LT.ERROR, `${location} | Failed to get message: ${jsonStringifyBig(message)} | Error: ${err.name} - ${err.message}`);
|
genericLogger(LT.ERROR, `${location} | Failed to get message: ${jsonStringifyBig(message)} | Error: ${err.name} - ${err.message}`);
|
||||||
const messageSendError = (location: string, message: Message | string, err: Error) =>
|
const messageSendError = (location: string, message: Message | CreateMessage | string, err: Error) =>
|
||||||
genericLogger(LT.ERROR, `${location} | Failed to send message: ${jsonStringifyBig(message)} | Error: ${err.name} - ${err.message}`);
|
genericLogger(LT.ERROR, `${location} | Failed to send message: ${jsonStringifyBig(message)} | Error: ${err.name} - ${err.message}`);
|
||||||
const messageDeleteError = (location: string, message: Message | string, err: Error) =>
|
const messageDeleteError = (location: string, message: Message | string, err: Error) =>
|
||||||
genericLogger(LT.ERROR, `${location} | Failed to delete message: ${jsonStringifyBig(message)} | Error: ${err.name} - ${err.message}`);
|
genericLogger(LT.ERROR, `${location} | Failed to delete message: ${jsonStringifyBig(message)} | Error: ${err.name} - ${err.message}`);
|
||||||
|
@ -36,4 +50,6 @@ export default {
|
||||||
reactionDeleteError,
|
reactionDeleteError,
|
||||||
},
|
},
|
||||||
jsonStringifyBig,
|
jsonStringifyBig,
|
||||||
|
messageUrlToIds,
|
||||||
|
idsToMessageUrl,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue