Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfixes, QOL, info logging, reading squad robustness #20

Open
wants to merge 8 commits into
base: feature/documentation-and-qol
Choose a base branch
from
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
24 changes: 12 additions & 12 deletions package-lock.json

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

85 changes: 32 additions & 53 deletions setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,29 +111,29 @@ function addPrivateLogChannel() {
});
}

// get and set the public log channel id
function addPublicLogChannel() {
// get and set the info log channel id
function addInfoLogChannel() {
return new Promise((resolve, reject) => {
rl.question('What is the ID of the public log channel? ', (publicLogChannel) => {
addSetting('public_log_channel', publicLogChannel).then(() => {
rl.write('Public log channel ID stored\n');
rl.question('What is the ID of the info log channel? ', (infoLogChannel) => {
addSetting('info_log_channel', infoLogChannel).then(() => {
rl.write('Info log channel ID stored\n');
resolve();
}).then((err) => {
reject(`There was an error when trying to store the public log channel ID: ${err}`);
}).catch((err) => {
reject(`There was an error when trying to store the info log channel: ${err}\n`);
});
});
});
}

// get and set the warn role id
function addWarnRole() {
// get and set the public log channel id
function addPublicLogChannel() {
return new Promise((resolve, reject) => {
rl.question('What is the ID of the warn role? ', (warnRoleId) => {
addSetting('warn_role_id', warnRoleId).then(() => {
rl.write('Warn role ID stored\n');
rl.question('What is the ID of the public log channel? ', (publicLogChannel) => {
addSetting('public_log_channel', publicLogChannel).then(() => {
rl.write('Public log channel ID stored\n');
resolve();
}).catch((err) => {
reject(`There was an error trying to store the warned role ID: ${err}`);
}).then((err) => {
reject(`There was an error when trying to store the public log channel ID: ${err}`);
});
});
});
Expand All @@ -142,8 +142,8 @@ function addWarnRole() {
// get and set the muted role id
function addMutedRole() {
return new Promise((resolve, reject) => {
rl.question('What is the ID of the muted role? ', (mutedRoleId) => {
addSetting('muted_role_id', mutedRoleId).then(() => {
rl.question('What is the ID of the muted role? ', (muteRoleId) => {
addSetting('mute_role_id', muteRoleId).then(() => {
rl.write('Muted role ID stored\n');
resolve();
}).catch((err) => {
Expand All @@ -153,51 +153,30 @@ function addMutedRole() {
});
}

// get and set the reading squad role id
function addReadingRole() {
return new Promise((resolve, reject) => {
rl.question('What is the ID of the reading squad role? ', (squadRoleId) => {
addSetting('reading_squad_role_id', squadRoleId).then(() => {
rl.write('Reading squad role ID stored\n');
resolve();
}).catch((err) => {
reject(`There was an error trying to store the reading squad role ID: ${err}`);
});
});
});
}

// get and set the reading squad reports channel id
function addreadingChannel() {
// get and set the ontopic role id
function adOntopicRole() {
return new Promise((resolve, reject) => {
rl.question('What is the ID of the reading reports channel? ', (reportsChannelId) => {
addSetting('reading_reports_channel', reportsChannelId).then(() => {
rl.write('Reading reports channel ID stored\n');
rl.question('What is the ID of the On-topic role? ', (ontopRoleId) => {
addSetting('ontop_role_id', ontopRoleId).then(() => {
rl.write('On-topic role ID stored\n');
resolve();
}).catch((err) => {
reject(`There was an error trying to store the reading reports channel ID: ${err}`);
reject(`There was an error trying to store the On-topic role ID: ${err}`);
});
});
});
}

addHome().then(() => {
addPrivateLogChannel().then(() => {
addPublicLogChannel().then(() => {
addWarnRole().then(() => {
addMutedRole().then(() => {
Promise.all([addHighPerm(), addLowPerm()]).then(() => {
addReadingRole().then(() => {
addreadingChannel().then(() => {
rl.close();
});
});
});
});
});
});
});
});
(async function() {
await addHome();
await addPrivateLogChannel();
await addPublicLogChannel();
await addInfoLogChannel();
await addMutedRole();
await adOntopicRole();
await Promise.all([addHighPerm(), addLowPerm()]);
rl.close();
})();

// graceful close message
rl.on('close', () => {
Expand Down
50 changes: 50 additions & 0 deletions src/commands/ban.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use strict';
const Command = require('../structures/Command');

//command to ban
module.exports = function command(requires) {
return new Command({
name: 'Ban',
inline: true,
alias: ['b'],
blurb: 'Bans people.',
longDescription: 'Bans a user from the server',
usages: ['`%prefixb {user} {reason}`'],
permission: 'high',
action: async function(details) {
const bot = requires.bot;
const info = requires.info;
const wholeTest = /^(?:<@!*)?([a-zA-Z0-9]+)(?:>)?\s*\w.+/g;
const idPattern = /^(?:<@!*)?([a-zA-Z0-9]+)(?:>)?\s/g;
//processes input
let userTest;
if(details.input === ''
|| !wholeTest.test(details.input)
|| !(userTest = info.utility.stripUID(details.args[1]))
) {
await bot.createMessage(details.channelID, {
embed: {
description: 'Failed to parse command. Please try again',
color: info.utility.red,
}
});
} else {
const reason = details.input.replace(idPattern, '');
await bot.banGuildMember(details.serverID, userTest, 7, reason);
await info.db.addInfraction(userTest, 'ban', new Date, reason);
await bot.createMessage(details.channelID, {content: 'User was banned'});
await bot.createMessage(info.settings.private_log_channel, {
embed: {
title: 'Log', fields: [
{name: 'User', value: `<@${userTest}>`},
{name: 'Action', value: 'ban'},
{name: 'Reason', value: reason},
{name: 'Message Link', value: details.link},
{name: 'Responsible Mod', value: `<@${details.userID}>`}
]
}
});
}
}
}, requires);
};
5 changes: 2 additions & 3 deletions src/commands/eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = function command(requires) {
action: function(details) {
let bot = requires.bot;

// eslint-disable-next-line no-unused-vars
const echo = function(str) {
bot.createMessage(details.channelID, {content: str});
};
Expand All @@ -23,9 +24,7 @@ module.exports = function command(requires) {
try {
bot.createMessage(details.channelID, {content: eval(details.input)});
} catch(err) {
bot.createMessage(details.channelID, {
content: err
});
bot.createMessage(details.channelID, {content: err});
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = function command(requires) {
emb.description = utility.filter('You can DM the bot :heart:\nUse `%prefixhelp {command}` to get more detailed information about a command.');

const listCommands = function(userLevel) {
Object.keys(info.commands).forEach((commandName,index) => {
Object.keys(info.commands).forEach((commandName) => {
let command = info.commands[commandName];
let commandLevel = command.getPerm();
if(!utility.hasPermission(commandLevel, userLevel)) {
Expand Down
11 changes: 5 additions & 6 deletions src/commands/jisho.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = function command(requires) {
longDescription: 'Searches [Jisho](jisho.org) API for word definitions. Can search with both English and Japanese input, the interpretation of the input is left for jisho. \nBy default this returns the first result only, which may not always be what you want. You can grab results further down the list by adding a number after the word. You can get a list of results by adding `--list`. \nThis is especially useful when searching English words, as often the top result may not be what you actually want',
usages: ['`%prefixjisho {word}` ― Returns top result for this word in the dictionary', '`%prefixjisho {word} --list` ― Returns a list of results from this lookup', '`%prefixjisho {word} {number}` ― Return {number}th result for this word'],
permission: 'public',
action: function(details) {
action: async function(details) {
let bot = requires.bot;
let info = requires.info;
let jisho = info.utility.useSource('jishoAPI');
Expand Down Expand Up @@ -54,19 +54,18 @@ module.exports = function command(requires) {
};
//processes the command
//to better understand this part, take a look at the parameters at the top of the page
if(details.input === '') {
if(details.input === '')
return;
} else if(details.input.search(/.+\s(--list)/g) != -1) {

await bot.sendChannelTyping(details.channelID);
if(details.input.search(/.+\s(--list)/g) != -1) {
listJisho(details.input.replace(' --list', ''));
return;
} else if(details.input.search(/^.+\s[1-9][0-9]*$/g) != -1) {
let patt = /[1-9][0-9]*$/g;
let num = parseInt(patt.exec(details.input),10);
searchJisho(details.input.replace(/\s[1-9][0-9]*/g, ''),num - 1);
return;
} else {
searchJisho(details.input, 0);
return;
}
}
}, requires);
Expand Down
50 changes: 0 additions & 50 deletions src/commands/kanji.js

This file was deleted.

Loading