Skip to content

Commit

Permalink
Add Old Role Selction System
Browse files Browse the repository at this point in the history
Add Old Role Selction System
  • Loading branch information
Chr1s70ph authored Jan 21, 2022
2 parents ee1892b + 7691f26 commit 54b1ad5
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 23 deletions.
9 changes: 4 additions & 5 deletions events/interactionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import {
DiscordButtonInteraction,
DiscordClient,
DiscordCommandInteraction,
DiscordMessageContextMenuCommandInteraction,
DiscordSelectMenuInteraction,
DiscordUserContextMenuCommandInteraction,
DiscordMessageContextMenuInteraction,
} from '../types/customTypes'

exports.run = (client: DiscordClient, interaction: any) => {
Expand Down Expand Up @@ -38,13 +37,13 @@ exports.run = (client: DiscordClient, interaction: any) => {
const DiscordInteraction = interaction as DiscordCommandInteraction
commandfile.Command(client, DiscordInteraction)
} else if (interaction.isMessageContextMenu()) {
const DiscordInteraction = interaction as DiscordMessageContextMenuCommandInteraction
const DiscordInteraction = interaction as DiscordMessageContextMenuInteraction
commandfile.MessageContextMenu(client, DiscordInteraction)
} else if (interaction.isSelectMenu()) {
const DiscordInteraction = interaction as DiscordSelectMenuInteraction
commandfile.SelectMenu(client, DiscordInteraction)
} else if (interaction.isUserContextMenu()) {
const DiscordInteraction = interaction as DiscordUserContextMenuCommandInteraction
commandfile.UserContextMenu(client, DiscordInteraction)
// const DiscordInteraction = interaction as DiscordUserContextMenuCommandInteraction
// commandfile.UserContextMenu(client, DiscordInteraction)
}
}
59 changes: 59 additions & 0 deletions events/messageReactionAdd.ts
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)
}
}
}
58 changes: 58 additions & 0 deletions events/messageReactionRemove.ts
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)
}
}
}
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@
"homepage": "https://github.com/Chr1s70ph/ETIT-Master-JS#readme",
"author": "Christoph Bluem",
"dependencies": {
"@discordjs/builders": "^0.11.0",
"@discordjs/rest": "^0.2.0-canary.0",
"discord-api-types": "^0.26.0",
"discord.js": "^14.0.0-dev.1641945998.1479e40",
"discord-api-types": "^0.26.1",
"discord.js": "^13.6.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-prettier": "^4.0.0",
"fs": "^0.0.1-security",
"github-create-issue": "^1.0.1",
"i18next": "^21.6.4",
"i18next": "^21.6.6",
"i18next-fs-backend": "^1.1.4",
"luxon": "^2.2.0",
"luxon": "^2.3.0",
"moment": "^2.29.1",
"moment-timezone": "^0.5.34",
"node-ical": "^0.14.1",
Expand All @@ -33,8 +34,8 @@
"valid-url": "^1.0.9"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.8.1",
"@typescript-eslint/parser": "^5.8.1",
"eslint": "^8.5.0"
"@typescript-eslint/eslint-plugin": "^5.10.0",
"@typescript-eslint/parser": "^5.10.0",
"eslint": "^8.7.0"
}
}
}
40 changes: 40 additions & 0 deletions types/colors.ts
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,
}
17 changes: 8 additions & 9 deletions types/customTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import {
ButtonInteraction,
SelectMenuInteraction,
ApplicationCommand,
MessageContextMenuCommandInteraction,
UserContextMenuCommandInteraction,
MessageContextMenuInteraction,
} from 'discord.js'
import i18next from 'i18next'

Expand Down Expand Up @@ -208,7 +207,7 @@ export interface DiscordCommandInteraction extends CommandInteraction {
/**
* Extended {@link MessageContextMenuInteraction} to hold {@link DiscordUser}
*/
export interface DiscordMessageContextMenuCommandInteraction extends MessageContextMenuCommandInteraction {
export interface DiscordMessageContextMenuInteraction extends MessageContextMenuInteraction {
user: DiscordUser
}

Expand All @@ -219,12 +218,12 @@ export interface DiscordSelectMenuInteraction extends SelectMenuInteraction {
user: DiscordUser
}

/**
* Extended {@link UserContextMenuInteraction} to hold {@link DiscordUser}
*/
export interface DiscordUserContextMenuCommandInteraction extends UserContextMenuCommandInteraction {
user: DiscordUser
}
// /**
// * Extended {@link UserContextMenuInteraction} to hold {@link DiscordUser}
// */
// export interface DiscordUserContextMenuCommandInteraction extends UserContextMenuCommandInteraction {
// user: DiscordUser
// }

/**
* Extended User to hold language.
Expand Down

0 comments on commit 54b1ad5

Please sign in to comment.