From 825e1611f5ca9b89b5034b702a6b2e4a15b35b47 Mon Sep 17 00:00:00 2001 From: plane000 Date: Tue, 22 May 2018 18:49:07 +0100 Subject: [PATCH] Servers now have server spesific prefixes --- commandmanager.js | 3 ++- commands/admincommands.js | 19 ++++++++++++++++--- commands/convertcommands.js | 0 commands/multiservercommands.js | 10 +++------- config.js | 3 ++- main.js | 10 +++++++--- 6 files changed, 30 insertions(+), 15 deletions(-) create mode 100644 commands/convertcommands.js diff --git a/commandmanager.js b/commandmanager.js index 018b339..d78bd5a 100644 --- a/commandmanager.js +++ b/commandmanager.js @@ -25,6 +25,7 @@ function addCommand(name, command, alt, usage, desc, requrePerms, functionRefere } /*command name, command, alt, usage, description, require permission, reference*/ + module.exports.loadCommands = function() { //general commands addCommand('Help', 'help', undefined, 'help [command] or [help]', 'Returns a usage chart for the command requested, or returns a link to a command list', false, Commands.help); @@ -49,6 +50,6 @@ module.exports.loadCommands = function() { //admin commands addCommand('Shutdown', 'stop', undefined, 'stop', 'Shutsdown JefferyBot', true, AdminCommands.stop); addCommand('Reload', 'reload', undefined, 'reload', 'Reloads the server config and the misc config', false, AdminCommands.reload); - addCommand('Set Prefix', 'setprefix', undefined, 'setprefix [new prefix]', 'Changes Jeffery\'s prefix to the new prefix', true, AdminCommands.setprefix); + addCommand('Set Prefix', 'setprefix', undefined, 'setprefix [new prefix]', 'Changes Jeffery\'s prefix in the server it was issued in to the new prefix', true, AdminCommands.setprefix); addCommand('Set Game', 'setgame', undefined, 'setgame [new game]', 'Changes Jeffery\'s game to the new game', true, AdminCommands.setgame); } diff --git a/commands/admincommands.js b/commands/admincommands.js index 0081f6f..58580c2 100644 --- a/commands/admincommands.js +++ b/commands/admincommands.js @@ -7,6 +7,10 @@ const Helper = require('../helper.js'); /*message object, messaage full, message args, discord client*/ +module.exports.addadminrole = function(message, msg, args, discordclient) { + +} + module.exports.stop = async function(message, msg, args, discordclient) { message.channel.send(':white_check_mark: \`Disconnected...\`'); Logger.failed('Disconnected'); @@ -15,14 +19,23 @@ module.exports.stop = async function(message, msg, args, discordclient) { module.exports.reload = async function(message, msg, args, discordclient) { try { - + Config.loadFromFile(); + message.channel.send(':white_check_mark: \`Configuration reloaded...\`'); } catch (e) { - + message.channel.send(`:no_entry_sign: \`Could not load the config: ${e.message}\``); } } module.exports.setprefix = async function(message, msg, args, discordclient) { - + if (args[1]) { + var servers = Config.getservers() + servers[message.guild.id].prefix = args[1] + Config.setservers(servers); + Config.writeToFile(); + message.channel.send(`:white_check_mark: \`The prefix for ${message.guild.name} is now ${args[1]} \``); + } else { + message.channel.send(':no_entry_sign: \`No new prefix specified\`') + } } module.exports.setgame = async function(message, msg, args, discordclient) { diff --git a/commands/convertcommands.js b/commands/convertcommands.js new file mode 100644 index 0000000..e69de29 diff --git a/commands/multiservercommands.js b/commands/multiservercommands.js index e49050e..79ab4ca 100644 --- a/commands/multiservercommands.js +++ b/commands/multiservercommands.js @@ -226,8 +226,8 @@ module.exports.vote = async function(message, msg, args, discordclient) { } async function startPoll(messageObj, args) { - var parsedOptions = await parseOptions(args); - var parsedVotes = await getVotes(parsedOptions) + var parsedOptions =args.slice(2).join(" ").match(/(\\.|[^/])+/g) + var parsedVotes = await getStartingVotes(parsedOptions) polls[messageObj.guild.id] = { options: parsedOptions, votes: parsedVotes, @@ -235,11 +235,7 @@ async function startPoll(messageObj, args) { } } -async function parseOptions(args) { - return args.slice(2).join(" ").match(/(\\.|[^/])+/g) -} - -async function getVotes(options) { +async function getStartingVotes(options) { var votes = []; for (i in options) { votes.push('0'); diff --git a/config.js b/config.js index 9b744ea..5c9492d 100644 --- a/config.js +++ b/config.js @@ -23,6 +23,7 @@ module.exports.addServer = function(guild) { servers[guild.id] = { name: guild.name, rules: ["Oh yeah, arrays start at 0"], + prefix: '+', adminroles: [] } } @@ -31,13 +32,13 @@ module.exports.loadDefaults = function() { config = { Token: 'DISCORD_TOKEN', NowPlaying: 'RealLife.exe', - Prefix: '+', Version: '2.0.1', }; servers['SERVER ID'] = { name: 'SERVER NAME', rules: ['RULE 0', 'RULE 1'], + prefix: '+', adminroles: ['123456789101112', '123456789101112'] }; } diff --git a/main.js b/main.js index e53e15f..b5747dc 100644 --- a/main.js +++ b/main.js @@ -86,10 +86,14 @@ client.on('ready', () => { /*on message event*/ client.on('message', async (message) => { /*if it starts with prefix loaded from config*/ - if (message.content.startsWith(Config.getconfig().Prefix)) { + if (message.content.startsWith(Config.getservers()[message.guild.id].prefix)) { + if (message.content.startsWith(';-;') || message.content.startsWith(';_;')) { + return; + } + Logger.logMSG(message); - var msg = message.content.toLowerCase().substring(Config.getconfig().Prefix.length); - var args = message.content.substring(Config.getconfig().Prefix.length).split(' '); + var msg = message.content.toLowerCase().substring(Config.getservers()[message.guild.id].prefix.length); + var args = message.content.substring(Config.getservers()[message.guild.id].prefix.length).split(' '); args[0] = args[0].toLowerCase(); /*command manager checks if command exists*/