import { GuildMember } from "discord.js"; import { DocumentationSet } from "./commands/command"; import { getRepository } from "typeorm"; import { KnownUser } from "./entity/KnownUser"; const VALID_EXTENSIONS = new Set([ "png", "jpg", "jpeg", "bmp", ]); export let documentation : DocumentationSet = {}; export function isDevelopment() { return process.env.NODE_ENV == "dev"; } export function isValidImage(fileName: string) { let extPosition = fileName.lastIndexOf("."); if(extPosition < 0) return false; let ext = fileName.substring(extPosition + 1).toLowerCase(); return VALID_EXTENSIONS.has(ext); } export async function isAuthorisedAsync(member : GuildMember) { let repo = getRepository(KnownUser); let user = await repo.findOne({ where: { userID: member.id }, select: [ "canModerate" ] }); if (user && user.canModerate) return true; let role = await repo.createQueryBuilder() .select(["userId"]) .where("userId in (:...ids)", {ids: member.roles.keyArray()}) .andWhere("canModerate = 1") .getOne(); if (role) return true; return false; } export type Dict = { [key: string]: TVal };