improved messages and general cleanup
This commit is contained in:
66
src/util.ts
66
src/util.ts
@@ -1,3 +1,4 @@
|
||||
import { CommandInteraction, GuildMember, TextChannel } from "discord.js";
|
||||
|
||||
/**
|
||||
* shuffles an array
|
||||
@@ -22,3 +23,68 @@ export function shuffle(array: any[]) {
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
|
||||
|
||||
export class errorMessage {
|
||||
public msg: string;
|
||||
public ephemeral: boolean;
|
||||
|
||||
constructor(msg: string, ephemeral: boolean = true) {
|
||||
this.msg = msg;
|
||||
this.ephemeral = ephemeral;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* a simple class to contain an error message and related data
|
||||
* @param msg error message
|
||||
* @param ephemeral (default=true)
|
||||
* @returns new errorMessage
|
||||
*/
|
||||
export const emsg = (msg: string, ephemeral: boolean = true) => new errorMessage(msg, ephemeral);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export type queueInfo = {
|
||||
players: GuildMember[],
|
||||
initiator: {
|
||||
interaction: CommandInteraction,
|
||||
member: GuildMember
|
||||
},
|
||||
teamsize: number,
|
||||
timeout: NodeJS.Timeout
|
||||
}
|
||||
|
||||
/**
|
||||
* get the GuildMember of an interaction
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it cannot be read
|
||||
* @returns member
|
||||
*/
|
||||
export function getMember(interaction: CommandInteraction): GuildMember {
|
||||
let member = interaction.member;
|
||||
|
||||
if (!(member instanceof GuildMember))
|
||||
throw emsg('Unable to retrieve guild member information, please try again');
|
||||
|
||||
return member;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the TextChannel of an interaction
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it cannot be read
|
||||
* @returns member
|
||||
*/
|
||||
export function getChannel(interaction: CommandInteraction): TextChannel {
|
||||
let channel = interaction.channel;
|
||||
|
||||
if (!(channel instanceof TextChannel))
|
||||
throw emsg('Unable to retrieve text channel information, please try again');
|
||||
|
||||
return channel;
|
||||
}
|
||||
Reference in New Issue
Block a user