2023-04-20 23:27:29 -07:00
import { ApplicationCommandFlags , Bot , CreateMessage , Embed , Interaction , InteractionResponseTypes } from '../deps.ts' ;
2023-01-11 15:06:20 -08:00
import config from '../config.ts' ;
2024-05-18 15:05:40 -07:00
import { generateGuildSettingKey , lfgChannelSettings } from './db/common.ts' ;
2023-01-28 17:58:24 -08:00
import utils from './utils.ts' ;
2023-04-29 00:18:06 -07:00
import { helpSlashName , infoSlashName , reportSlashName } from './commands/slashCommandNames.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 } ` ,
2023-04-29 00:18:06 -07:00
` ${ config . prefix } ${ infoSlashName } to learn more ` ,
` ${ config . prefix } ${ helpSlashName } to learn more ` ,
2023-01-11 18:21:43 -08:00
` 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 ) = > {
2023-04-09 01:12:53 -07:00
return ( lfgChannelSettings . has ( generateGuildSettingKey ( 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-15 02:04:38 -07:00
// Tell user to try again or report issue
2024-05-21 01:42:12 -07:00
export const somethingWentWrong = ( bot : Bot , interaction : Interaction , errorCode : string , possibleFix = 'No fix provided.' ) = >
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...' ,
2024-05-21 01:42:12 -07:00
description :
` You should not be able to get here. If ${ config . name } has seen this error before, the developer may have a possible fix for you to try. If one is provided, please attempt it before \` / ${ reportSlashName } \` ing it. If the issue continues, please \` / ${ reportSlashName } \` this issue to the developer with the error code below. ` ,
2023-01-28 17:58:24 -08:00
fields : [ {
name : 'Error Code:' ,
2023-04-28 20:27:42 -07:00
value : ` \` ${ errorCode } \` ` ,
2024-05-21 01:42:12 -07:00
} , {
name : 'Possible Fix:' ,
value : possibleFix ,
2023-01-28 17:58:24 -08:00
} ] ,
} ] ,
} ,
2023-04-15 02:04:38 -07:00
} ) . catch ( ( e : Error ) = > utils . commonLoggers . interactionSendError ( 'commandUtils.ts@somethingWentWrong' , interaction , e ) ) ;
2024-05-21 01:42:12 -07:00
// Possible fixes for the user to try before reporting.
export const commonFixes = {
CANT_SEND_MESSAGE : ` Please verify ${ config . name } has permission to send messages in this channel. ` ,
} ;
2023-04-15 02:04:38 -07:00
// Smack the user for trying to modify an event that isn't theirs
2024-05-18 15:05:40 -07:00
export const stopThat = ( bot : Bot , interaction : Interaction , stopWhat : string ) = >
2023-04-15 02:04:38 -07:00
bot . helpers . sendInteractionResponse ( interaction . id , interaction . token , {
type : InteractionResponseTypes . ChannelMessageWithSource ,
data : {
flags : ApplicationCommandFlags.Ephemeral ,
embeds : [ {
color : warnColor ,
title : 'Hey! Stop that!' ,
description : ` You are neither the owner of this event nor a ${ config . name } manager in this guild, meaning you are not allowed to ${ stopWhat } this event.
$ { safelyDismissMsg } ` ,
} ] ,
} ,
} ) . catch ( ( e : Error ) = > utils . commonLoggers . interactionSendError ( 'commandUtils.ts@stopThat' , interaction , e ) ) ;
2023-04-08 01:28:42 -07:00
// Send DM to User
2023-04-09 01:12:53 -07:00
export const sendDirectMessage = async ( bot : Bot , userId : bigint , message : CreateMessage ) = > {
const userDmChannel = await bot . helpers . getDmChannel ( userId ) . catch ( ( e : Error ) = > utils . commonLoggers . messageGetError ( 'commandUtils.ts' , 'get userDmChannel' , e ) ) ;
// Actually send the DM
return bot . helpers . sendMessage ( userDmChannel ? . id || 0 n , message ) ;
} ;
2023-04-20 23:27:29 -07:00
// Info Embed Object (for info command and @mention command)
export const infoEmbed : Embed = {
color : infoColor2 ,
title : ` ${ config . name } , the LFG bot ` ,
description : ` ${ config . name } is developed by Ean AKA Burn_E99.
Want to check out my source code ? Check it out [ here ] ( $ { config . links . sourceCode } ) .
Need help with this bot ? Join my support server [ here ] ( $ { config . links . supportServer } ) .
2023-04-29 00:18:06 -07:00
Ran into a bug ? Report it to my developers using \ ` / ${ reportSlashName } [issue description] \` . ` ,
2023-05-01 00:07:12 -07:00
fields : [ {
name : 'Privacy Policy and Terms of Service:' ,
value : ` ** ${ config . name } does not automatically track or collect user information via Discord.**
$ { config . name } stores data relating to events , event channels , and text from the \ ` / ${ reportSlashName } \` command.
For more details , please check out the Privacy Policy on my GitHub [ here ] ( $ { config . links . sourceCode } / blob / master / PRIVACY . md )
Terms of Service can also be found on my GitHub [ here ] ( $ { config . links . sourceCode } / blob / master / TERMS . md ) . ` ,
} ] ,
2023-04-20 23:27:29 -07:00
footer : {
text : ` Current Version: ${ config . version } ` ,
} ,
} ;
2023-04-29 01:29:15 -07:00
export const dmTestMessage : CreateMessage = {
embeds : [ {
color : infoColor2 ,
title : 'Heyo! Just making sure I can reach you.' ,
description : 'This message is just to make sure I can DM you any Join Requests to your event. If you are reading this message, it means you have everything set up correctly.' ,
} ] ,
} ;