-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Old Role Selction System
- Loading branch information
Showing
6 changed files
with
179 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { GuildMember, MessageReaction, TextChannel } from 'discord.js' | ||
import { colors } from '../types/colors' | ||
import { DiscordClient } from '../types/customTypes' | ||
|
||
/** | ||
* All four course module selection channels | ||
*/ | ||
const ROLE_REACTION_CHANNELS = [ | ||
'830837597587767306', | ||
'830884627051839488', | ||
'831572233301524501', | ||
'831636138808311878', | ||
'833349893963776030', | ||
'783449991355170836', | ||
] | ||
/** | ||
* Channel to send message to, if course module role does not yet exist | ||
*/ | ||
const SDADISDIGEN = '827171746364784671' | ||
|
||
exports.run = async (client: DiscordClient, reaction: MessageReaction, user: GuildMember) => { | ||
const USER = await reaction.message.guild.members.fetch(user.id) | ||
|
||
if (ROLE_REACTION_CHANNELS.indexOf(reaction.message.channel.id) > -1) { | ||
try { | ||
/** | ||
* Message on wich a reaction was added | ||
*/ | ||
const REACRT_MESSAGE = await reaction.message.channel.messages.fetch(reaction.message.id) | ||
/** | ||
* Fetch first role that is mentioned in that message | ||
*/ | ||
const role = REACRT_MESSAGE.mentions.roles.first() | ||
/** | ||
* If no role is mentioned, send info message | ||
*/ | ||
if (role === undefined) { | ||
const infoChannel = reaction.message.guild.channels.cache.get(SDADISDIGEN) as TextChannel | ||
infoChannel.send( | ||
`👤✅ <@!${user.id}> hat in <#${reaction.message.channel.id}> **${reaction.message.content}** ausgewählt.`, | ||
) | ||
} else if (!USER.roles.cache.has(role.name)) { | ||
/** | ||
* If user does not yet have the role selected, add it | ||
*/ | ||
await USER.roles.add(role, 'Requested by user.') | ||
console.log( | ||
// eslint-disable-next-line max-len | ||
`User update: ${colors.fg.Green}Added${colors.special.Reset} role ${colors.special.Bright}${role.name}${colors.special.Reset} to ${USER.displayName}.`, | ||
) | ||
} | ||
} catch (error) { | ||
/** | ||
* Error handling | ||
*/ | ||
console.log(error) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { GuildMember, MessageReaction, TextChannel } from 'discord.js' | ||
import { colors } from '../types/colors' | ||
import { DiscordClient } from '../types/customTypes' | ||
|
||
/** | ||
* All four course module selection channels | ||
*/ | ||
const ROLE_REACTION_CHANNELS = [ | ||
'830837597587767306', | ||
'830884627051839488', | ||
'831572233301524501', | ||
'831636138808311878', | ||
'833349893963776030', | ||
'783449991355170836', | ||
] | ||
/** | ||
* Channel to send message to, if course module role does not yet exist | ||
*/ | ||
const SDADISDIGEN = '827171746364784671' | ||
|
||
exports.run = async (client: DiscordClient, reaction: MessageReaction, user: GuildMember) => { | ||
const USER = await reaction.message.guild.members.fetch(user.id) | ||
if (ROLE_REACTION_CHANNELS.indexOf(reaction.message.channel.id) > -1) { | ||
try { | ||
/** | ||
* Message on wich a reaction was added | ||
*/ | ||
const REACRT_MESSAGE = await reaction.message.channel.messages.fetch(reaction.message.id) | ||
/** | ||
* Fetch first role that is mentioned in that message | ||
*/ | ||
const role = REACRT_MESSAGE.mentions.roles.first() | ||
/** | ||
* If no role is mentioned, send info message | ||
*/ | ||
if (role === undefined) { | ||
const infoChannel = reaction.message.guild.channels.cache.get(SDADISDIGEN) as TextChannel | ||
infoChannel.send( | ||
`👤❌ <@!${user.id}> hat in <#${reaction.message.channel.id}> **${reaction.message.content}** abgewählt.`, | ||
) | ||
} else if (!USER.roles.cache.has(role.name)) { | ||
/** | ||
* If user does have the role selected, remove it | ||
*/ | ||
await USER.roles.remove(role, 'Requested by user.') | ||
console.log( | ||
// eslint-disable-next-line max-len | ||
`User update: ${colors.fg.Red}Removed${colors.special.Reset} role ${colors.special.Bright}${role.name}${colors.special.Reset} from ${USER.displayName}`, | ||
) | ||
} | ||
} catch (error) { | ||
/** | ||
* Error handling | ||
*/ | ||
console.log(error) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// eslint-disable-next-line no-shadow | ||
enum special { | ||
Reset = '\x1b[0m', | ||
Bright = '\x1b[1m', | ||
Dim = '\x1b[2m', | ||
Underscore = '\x1b[4m', | ||
Blink = '\x1b[5m', | ||
Reverse = '\x1b[7m', | ||
Hidden = '\x1b[8m', | ||
} | ||
|
||
// eslint-disable-next-line no-shadow | ||
enum fg { | ||
Black = '\x1b[30m', | ||
Red = '\x1b[31m', | ||
Green = '\x1b[32m', | ||
Yellow = '\x1b[33m', | ||
Blue = '\x1b[34m', | ||
Magenta = '\x1b[35m', | ||
Cyan = '\x1b[36m', | ||
White = '\x1b[37m', | ||
} | ||
|
||
// eslint-disable-next-line no-shadow | ||
enum bg { | ||
Black = '\x1b[40m', | ||
Red = '\x1b[41m', | ||
Green = '\x1b[42m', | ||
Yellow = '\x1b[43m', | ||
Blue = '\x1b[44m', | ||
Magenta = '\x1b[45m', | ||
Cyan = '\x1b[46m', | ||
White = '\x1b[47m', | ||
} | ||
|
||
export const colors = { | ||
special, | ||
fg, | ||
bg, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters