Servers now have server spesific prefixes

This commit is contained in:
plane000
2018-05-22 18:49:07 +01:00
parent c0529d5dab
commit 825e1611f5
6 changed files with 30 additions and 15 deletions

View File

@@ -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);
}

View File

@@ -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) {

View File

View File

@@ -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');

View File

@@ -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']
};
}

10
main.js
View File

@@ -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*/