2023-04-08 01:28:42 -07:00
import { ApplicationCommandFlags , Bot , CreateMessage , Interaction , InteractionResponseTypes } from '../deps.ts' ;
2023-01-11 15:06:20 -08:00
import config from '../config.ts' ;
2023-01-28 17:58:24 -08:00
import { lfgChannelSettings } from './db.ts' ;
import utils from './utils.ts' ;
2023-01-11 15:06:20 -08:00
export const failColor = 0xe71212 ;
export const warnColor = 0xe38f28 ;
export const successColor = 0x0f8108 ;
export const infoColor1 = 0x313bf9 ;
export const infoColor2 = 0x6805e9 ;
2023-03-26 18:37:47 -07:00
export const safelyDismissMsg = 'You may safely dismiss this message.' ;
2023-02-02 18:33:27 -08:00
2023-01-11 15:06:20 -08:00
export const getRandomStatus = ( guildCount : number ) : string = > {
2023-01-11 18:21:43 -08:00
const statuses = [
` Running V ${ config . version } ` ,
` ${ config . prefix } info to learn more ` ,
` Running LFGs in ${ guildCount } servers ` ,
] ;
2023-01-28 22:51:49 -08:00
return statuses [ Math . floor ( Math . random ( ) * statuses . length ) ] ;
2023-01-11 18:21:43 -08:00
} ;
2023-01-11 15:06:20 -08:00
2023-01-28 17:58:24 -08:00
export const isLFGChannel = ( guildId : bigint , channelId : bigint ) = > {
return ( lfgChannelSettings . has ( ` ${ guildId } - ${ channelId } ` ) || channelId === 0 n || guildId === 0 n ) ? ApplicationCommandFlags.Ephemeral : undefined ;
2023-01-11 15:06:20 -08:00
} ;
2023-01-11 19:23:27 -08:00
2023-04-08 00:42:22 -07:00
export const somethingWentWrong = async ( bot : Bot , interaction : Interaction , errorCode : string ) = >
2023-01-28 17:58:24 -08:00
bot . helpers . sendInteractionResponse ( interaction . id , interaction . token , {
type : InteractionResponseTypes . ChannelMessageWithSource ,
data : {
flags : ApplicationCommandFlags.Ephemeral ,
embeds : [ {
color : failColor ,
title : 'Something went wrong...' ,
description : 'You should not be able to get here. Please try again and if the issue continues, `/report` this issue to the developers with the error code below.' ,
fields : [ {
name : 'Error Code:' ,
value : errorCode ,
} ] ,
} ] ,
} ,
} ) . catch ( ( e : Error ) = > utils . commonLoggers . interactionSendError ( 'commandUtils.ts' , interaction , e ) ) ;
2023-04-08 01:28:42 -07:00
// Send DM to User
export const sendDirectMessage = async ( bot : Bot , userId : bigint , message : CreateMessage ) = >
bot . helpers . getDmChannel ( userId ) . then ( ( userDmChannel ) = > {
// Actually send the DM
bot . helpers . sendMessage ( userDmChannel . id , message ) . catch ( ( e : Error ) = > utils . commonLoggers . messageSendError ( 'commandUtils.ts' , message , e ) ) ;
} ) . catch ( ( e : Error ) = > {
// Edit failed, try to notify user
utils . commonLoggers . messageGetError ( 'commandUtils.ts' , 'get userDmChannel' , e ) ;
} ) ;