Skip to content

Commit

Permalink
chore: use standard js linter and semantic release
Browse files Browse the repository at this point in the history
Remove eslint and configuration and replace with standard lint.
Try using semantic release for release and tag in github.
  • Loading branch information
8Mobius8 committed Sep 26, 2020
1 parent a1597a8 commit afe28e2
Show file tree
Hide file tree
Showing 12 changed files with 7,690 additions and 530 deletions.
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

47 changes: 0 additions & 47 deletions .eslintrc.json

This file was deleted.

12 changes: 6 additions & 6 deletions commands/beep.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
name: 'beep',
description: 'Beep!',
execute(message, args) {
message.channel.send('Beep.');
}
}
name: 'beep',
description: 'Beep!',
execute (message, args) {
message.channel.send('Beep.')
}
}
88 changes: 44 additions & 44 deletions commands/help.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
const { prefix } = require('../config.js');
const { prefix } = require('../config.js')

module.exports = {
name: 'help',
description: 'List all of my command or info about a specific command.',
aliases: ['commands'],
usage: '[command name]',
cooldown: 5,
execute(message, args) {
const data = [];
const { commands } = message.client;

if (!args.length) {
data.push('Here\'s a list of all my commands:');
data.push(commands.map(command => command.name).join(', '));
data.push(`\nYou can send \`${prefix}help [command name]\` to get info on a specific command!`);

return message.author.send(data, { split: true })
.then(() => {
if (message.channel.type == 'dm') return;
message.reply('I\'ve sent you a DM with all my commands!');
})
.catch(error => {
console.error(`Could not send help DM to ${message.author.tag}.\n`, error);
message.reply('it seems like it can\'t DM you! Do you have DMs disabled?');
})
}

const name = args[0].toLowerCase();
const command = commands.get(name) || commands.find(c => c.aliases && c.aliases.includes(name));

if (!command) {
return message.reply('that\'s not a valid command!');
}

data.push(`**Name:** ${command.name}`);

if (command.aliases) data.push(`**Aliases:** ${command.aliases.join(', ')}`);
if (command.description) data.push(`**Description:** ${command.description}`);
if (command.usage) data.push(`**Usage:** \`${prefix}${command.name} ${command.usage}\``);

data.push(`**Cooldown:** ${command.cooldown || 3} second(s)`);

message.channel.send(data, { split: true });
},
};
name: 'help',
description: 'List all of my command or info about a specific command.',
aliases: ['commands'],
usage: '[command name]',
cooldown: 5,
execute (message, args) {
const data = []
const { commands } = message.client

if (!args.length) {
data.push('Here\'s a list of all my commands:')
data.push(commands.map(command => command.name).join(', '))
data.push(`\nYou can send \`${prefix}help [command name]\` to get info on a specific command!`)

return message.author.send(data, { split: true })
.then(() => {
if (message.channel.type === 'dm') return
message.reply('I\'ve sent you a DM with all my commands!')
})
.catch(error => {
console.error(`Could not send help DM to ${message.author.tag}.\n`, error)
message.reply('it seems like it can\'t DM you! Do you have DMs disabled?')
})
}

const name = args[0].toLowerCase()
const command = commands.get(name) || commands.find(c => c.aliases && c.aliases.includes(name))

if (!command) {
return message.reply('that\'s not a valid command!')
}

data.push(`**Name:** ${command.name}`)

if (command.aliases) data.push(`**Aliases:** ${command.aliases.join(', ')}`)
if (command.description) data.push(`**Description:** ${command.description}`)
if (command.usage) data.push(`**Usage:** \`${prefix}${command.name} ${command.usage}\``)

data.push(`**Cooldown:** ${command.cooldown || 3} second(s)`)

message.channel.send(data, { split: true })
}
}
133 changes: 66 additions & 67 deletions commands/petition.js
Original file line number Diff line number Diff line change
@@ -1,145 +1,144 @@
const { Permissions } = require('discord.js');
const { adjectives, pass_exclaimations, fail_exclaimations } = require('./phrases.json');
const { Permissions } = require('discord.js')
const { adjectives, passExclaimations, failExclaimations } = require('./phrases.json')
// Time to wait for a peition
const { waitTime } = require('../config.js');
const { waitTime } = require('../config.js')

module.exports = {
name: 'new-role',
description: 'Creates a petition for a new role. This will create a role without any permissions.',
aliases: ['nr', 'grovel-4-role', 'beg-4-role'],
usage: '<role-name> <user-mentions>',
args: true,
execute: newRoleForUsers,
};
cooldown: 90000,
execute: newRoleForUsers
}

function newRoleForUsers(message, args) {
const roleName = args.find(arg => !getUserFromArg(message.client.users.cache, arg));
const aGuild = message.guild;
const mentionedMembers = message.mentions.members;
function newRoleForUsers (message, args) {
const roleName = args.find(arg => !getUserFromArg(message.client.users.cache, arg))
const aGuild = message.guild
const mentionedMembers = message.mentions.members

const usageHelp = 'Use `!help nr` to see how to usage.';
const usageHelp = 'Use `!help nr` to see how to usage.'
if (mentionedMembers.size < 1) {
return message.channel.send(`<@${message.author.id}>, you didn't mention anyone to add a role to!\n${usageHelp}.`);
}
else if (!roleName) {
return message.channel.send(`<@${message.author.id}>, you didn't provided a role-name!\n${usageHelp}.`);
return message.channel.send(`<@${message.author.id}>, you didn't mention anyone to add a role to!\n${usageHelp}.`)
} else if (!roleName) {
return message.channel.send(`<@${message.author.id}>, you didn't provided a role-name!\n${usageHelp}.`)
}

sendPetitionMessage(message.channel, roleName, message.author, mentionedMembers)
.then((petitionMsg) => {
const roleAdminAppovedFilter = (reaction, user) => {
return reaction.emoji.name === '👍'
&& aGuild.members.resolve(user).hasPermission(Permissions.FLAGS.MANAGE_ROLES);
};
return reaction.emoji.name === '👍' &&
aGuild.members.resolve(user).hasPermission(Permissions.FLAGS.MANAGE_ROLES)
}

const collector = petitionMsg.createReactionCollector(roleAdminAppovedFilter,
{ time: waitTime });
{ time: waitTime })

collector.on('collect', () => collector.stop('role admin approved'));
collector.on('collect', () => collector.stop('role admin approved'))
collector.on('end', (collected, reason) => {
if (reason === 'role admin approved') {
approvedRoleCreation(aGuild, petitionMsg.channel, roleName, mentionedMembers);
}
else {
sendUnapprovedMessage(petitionMsg.channel, roleName);
approvedRoleCreation(aGuild, petitionMsg.channel, roleName, mentionedMembers)
} else {
sendUnapprovedMessage(petitionMsg.channel, roleName)
}
});
});
})
})
}

function sendPetitionMessage(channel, roleName, requestor, users) {
function sendPetitionMessage (channel, roleName, requestor, users) {
const usersLine = users.map(member => {
return `<@${member.id}>`;
}).join(' ');
return `<@${member.id}>`
}).join(' ')

const anAdjective = randomFrom(adjectives);
const anAdjective = randomFrom(adjectives)
return channel.send(
'**New Role Petition**:\n' +
`<@${requestor.id}> would like to create a new *${anAdjective}* role ${roleName} for ${usersLine}\n` +
'Members may show support however they like.\n' +
'A role admin please approve by reacting with a 👍 to approve this petition.\n',
{ allowedMentions: { parse: ['users'] } },
);
{ allowedMentions: { parse: ['users'] } }
)
}

function approvedRoleCreation(aGuild, channel, roleName, users) {
let roleId = '';
function approvedRoleCreation (aGuild, channel, roleName, users) {
let roleId = ''
createNewRole(aGuild, roleName)
.then((role) => {
console.log(`Created new role named ${role.name}`);
roleId = role.id;
return applyRole(role, users);
console.log(`Created new role named ${role.name}`)
roleId = role.id
return applyRole(role, users)
})
.then((mArray) => {
console.log(`Applied new role to users ${mArray}`);
sendSuccessMessage(channel, roleId, mArray);
console.log(`Applied new role to users ${mArray}`)
sendSuccessMessage(channel, roleId, mArray)
})
.catch((error) => {
console.error(error);
sendErrorMessage(error);
console.error(error)
sendErrorMessage(error)
})
.finally(() => {
console.log('Finished adding roles and appling to user.');
});
console.log('Finished adding roles and appling to user.')
})
}

function getUserFromArg(users, arg) {
if (!arg) return;
function getUserFromArg (users, arg) {
if (!arg) return

if (arg.startsWith('<@') && arg.endsWith('>')) {
arg = arg.slice(2, -1);
arg = arg.slice(2, -1)

if (arg.startsWith('!')) {
arg = arg.slice(1);
arg = arg.slice(1)
}

return users.get(arg);
return users.get(arg)
}
}

function createNewRole(aGuild, name) {
function createNewRole (aGuild, name) {
return aGuild.roles
.create({
data: {
name: name,
permissions: 0,
permissions: 0
},
reason: 'Petition for new role was approved.',
});
reason: 'Petition for new role was approved.'
})
}

function applyRole(role, members) {
function applyRole (role, members) {
return Promise.all(
members.each(member => member.roles.add(role.id)),
);
members.each(member => member.roles.add(role.id))
)
}

function sendSuccessMessage(channel, roleId, membersWithRole) {
function sendSuccessMessage (channel, roleId, membersWithRole) {
const usersLine = membersWithRole.map(member => {
return `<@${member[1].id}>`;
}).join(' ');
const anExclaimation = randomFrom(pass_exclaimations);
return `<@${member[1].id}>`
}).join(' ')
const anExclaimation = randomFrom(passExclaimations)
return channel.send(
'**Petition APPROVED**\n' +
`*${anExclaimation}*\n` +
`New role <@&${roleId}> has been create for ${usersLine}`,
{ allowedMentions: { parse: ['roles', 'users'] } },
);
{ allowedMentions: { parse: ['roles', 'users'] } }
)
}

function sendErrorMessage(channel, error) {
return channel.send(`There was a problem creating a new role: ${error}`);
function sendErrorMessage (channel, error) {
return channel.send(`There was a problem creating a new role: ${error}`)
}

function sendUnapprovedMessage(channel, roleName) {
const anExclaimation = randomFrom(fail_exclaimations);
function sendUnapprovedMessage (channel, roleName) {
const anExclaimation = randomFrom(failExclaimations)
return channel.send(
'**Petition FAILED!**\n' +
`*${anExclaimation}*\n` +
`${roleName} was not created because the petition did not pass.`,
{ allowedMentions: { parse: ['roles', 'users'] } });
{ allowedMentions: { parse: ['roles', 'users'] } })
}

function randomFrom(anArray) {
return anArray[Math.floor(Math.random() * anArray.length)];
function randomFrom (anArray) {
return anArray[Math.floor(Math.random() * anArray.length)]
}
9 changes: 7 additions & 2 deletions commands/phrases.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
"craven",
"gustatory"
],
"pass_exclaimations": [
"passExclaimations": [
"HUUZZZAH!",
"Olé!",
"Gee Wilkers Batman!"
],
"fail_exclaimations": [
"failExclaimations": [
"RU-Roh Raggy!",
"Zoinks!",
"Golly",
Expand All @@ -30,5 +30,10 @@
"Salutations!",
"Greetings Earthling!",
"Come and stay awhile!"
],
"pejoratives": [
"Dingus!",
"Pssh, dummy.",
"You're a dingle butt. Whatever that means"
]
}
Loading

0 comments on commit afe28e2

Please sign in to comment.