Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,7 @@ typings/
.next

# Project files
src/config.json
src/config.json

# Generated data files
data/versions\.json
59 changes: 55 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@
"eslint-plugin-prettier": "^3.1.0",
"eslint-plugin-vue": "^5.2.3",
"esm": "^3.2.25",
"github-api": "^3.3.0",
"fuse.js": "^3.4.6",
"github-api": "^3.3.0",
"hjson": "^3.1.2",
"prettier": "^1.18.2"
"prettier": "^1.18.2",
"semver": "^7.1.1"
},
"devDependencies": {
"jest": "^24.9.0",
Expand Down
4 changes: 4 additions & 0 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ for (const file of jobFiles) {
https://discord.js.org/#/docs/commando/master/class/CommandoRegistry?scrollTo=registerGroups
*/
client.registry.registerGroups([
{
id: 'announcements',
name: 'Announcements',
},
{
id: 'documentation',
name: 'Documentation',
Expand Down
71 changes: 71 additions & 0 deletions src/commands/announcements/notify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { Command } from 'discord.js-commando'
import { inlineCode } from '../../utils/string'
import { cleanupInvocation } from '../../utils/messages'
import { createDefaultEmbed } from '../../utils/embed'
import { NOTIFICATION_ROLE } from '../../services/version-checker'

module.exports = class AnnouncementsNotifyCommand extends Command {
constructor(client) {
super(client, {
name: 'notify',
examples: [inlineCode('!notify')],
group: 'announcements',
guildOnly: true,
memberName: 'notify',
description: 'Sign yourself up for automated release notifications.',
clientPermissions: ['MANAGE_ROLES'],
})
}

hasPermission() {
return true
}

async run(msg) {
const notifyRole = msg.guild.roles.find(
role => role.name.toLowerCase() === NOTIFICATION_ROLE.toLowerCase()
)

try {
if (!notifyRole) {
throw new Error(`Unable to find role ${inlineCode(NOTIFICATION_ROLE)}!`)
}

const embed = createDefaultEmbed(msg).setTitle(
'Automated Release Notifications'
)

if (msg.member.roles.get(notifyRole.id)) {
msg.member.removeRole(notifyRole)

embed
.setDescription(
`Okay, you've been removed from the ${notifyRole} role and will no longer be informed of new releases.`
)
.setColor('RED')
} else {
msg.member.addRole(notifyRole)

embed
.setDescription(
`Okay, you've been added to the ${notifyRole} role and will be informed of any new releases.`
)
.setColor('GREEN')
}

msg.channel.send(embed)
cleanupInvocation(msg)
} catch (error) {
console.error(error)
msg.channel.send(this.buildErrorEmbed(msg, error))
cleanupInvocation(msg)
}
}

buildErrorEmbed(msg, error) {
return createDefaultEmbed(msg)
.setTitle('Sorry, an error occured.')
.setDescription(error.message ? error.message : error)
.setColor('ORANGE')
}
}
Loading