Finished up things

This commit is contained in:
ahoZiorce
2018-07-04 00:56:37 +02:00
parent 597cdbc0e0
commit c83ca0a089
7 changed files with 94 additions and 30 deletions

View File

@@ -24,7 +24,7 @@ bot.on('ready', () => {
logger.log('Done !');
});
bot.on("messageCreate", (msg) => {
bot.on('messageCreate', (msg) => {
let content = msg.content.replace(new RegExp(`^(?:<@${bot.user.id}> +|\\*)\\b`), '');
if (content === msg.content) return;
if (msg.author.bot) return;

8
package-lock.json generated
View File

@@ -617,6 +617,14 @@
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz",
"integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68="
},
"zlib-sync": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/zlib-sync/-/zlib-sync-0.1.4.tgz",
"integrity": "sha512-DRy+RONKzy/J6skNmq8ZBXtVAIoB4qbun+FCChlSlEvF7s9LJ0wzUXjVwl4tQ/jYT8V+LPzCg/sTcRj4E0g0fQ==",
"requires": {
"nan": "2.10.0"
}
}
}
}

View File

@@ -13,6 +13,7 @@
"eris": "^0.8.6",
"level": "^4.0.0",
"snekfetch": "^4.0.4",
"uws": "^10.148.1"
"uws": "^10.148.1",
"zlib-sync": "^0.1.4"
}
}

View File

@@ -15,4 +15,16 @@ exports.loadModule = function loadModule () {
bot.createMessage(msg.channel.id, ms + ' ms');
});
});
commandH.endpoint('^debug$', async (match, message) => {
let debugMessage = '```\n';
debugMessage += 'Logori v1.0.1\n\n';
debugMessage += 'Shard id ' + message.channel.guild.shard.id + ' on ' + bot.shards.size + '\n';
debugMessage += 'Uptime : ' + bot.uptime / 1000 + ' seconds\n';
debugMessage += 'Memory Usage : ' + Math.floor(process.memoryUsage().rss / 1048576) + ' MiB\n';
debugMessage += '```';
bot.createMessage(message.channel.id, debugMessage);
});
commandH.endpoint('^uptime$', async (match, message) => {
bot.createMessage(message.channel.id, 'The bot has been running for ' + bot.uptime / 1000 + ' seconds');
});
};

View File

@@ -1,37 +1,69 @@
const commandH = require('../commandHandler');
const bot = require('../botClient').bot;
const dbEI = require('../dbEventInterface');
const hastebin = require('../hastebin');
const configM = require('../configManager');
exports.loadModule = function loadModule () {
function legitChannel(message, channelId) {
let c = message.channel.guild.channels.find((ch) => {
if (ch.id === channelId) {
return true;
}
});
if (c) {
return true;
}
else {
return false;
}
}
exports.loadModule = function loadModule() {
commandH.endpoint('^(?:init|set)serv$', async (match, message) => {
if (!message.member.permission.has('administrator')) return;
if (!message.member.permission.has('manageGuild') && message.author.id !== configM.config.owner) return;
try {
await dbEI.initServer(message.channel.guild.id, message.channel.id);
bot.createMessage(message.channel.id, 'Server successfully set');
bot.createMessage(message.channel.id, 'Server **successfully** initted ! The fallback event channel has been set to this channel, you can modify it with the command `set-fallback-channel` in the target channel. See `help` command to get some help with the commands');
}
catch(e) {
catch (e) {
console.log(e);
bot.createMessage(message.channel.id, 'An error happened');
}
});
commandH.endpoint('^debugserv$', async (match, message) => {
dbEI.debugServer(message.channel.guild.id);
commandH.endpoint('^state(?: (.*))?$', async (match, message) => {
if (!message.member.permission.has('manageGuild') && message.author.id !== configM.config.owner) return;
if (match[1]) {
let text = JSON.stringify(await dbEI.getEvent(message.channel.guild.id, match[1]), null, 4);
bot.createMessage(message.channel.id, await hastebin(configM.config.hastebinServer, text));
}
else {
let text = JSON.stringify(await dbEI.getAllServer(message.channel.guild.id), null, 4);
bot.createMessage(message.channel.id, await hastebin(configM.config.hastebinServer, text));
}
});
commandH.endpoint('^set-fallback(?: <#(.+?)>)?$', async (match, message) => {
commandH.endpoint('^set-fallback-channel(?: <#(.+?)>)?$', async (match, message) => {
if (!message.member.permission.has('manageGuild') && message.author.id !== configM.config.owner) return;
let channelId = message.channel.id;
if (match[1]) {
channelId = match[1];
}
// TODO: Check if the set channel is in this guild
dbEI.setFallbackChannel(message.channel.guild.id, channelId);
bot.createMessage(message.channel.id, 'Fallback set to that channel, all the event logging will be done there by default. A message will be sent in that channel to make sure it is correct.');
bot.createMessage(channelId, `<@${message.author.id}>, this is now the fallback channel for all the events.`);
if (legitChannel(message, channelId)) {
dbEI.setFallbackChannel(message.channel.guild.id, channelId);
bot.createMessage(message.channel.id, `Fallback **set** to the channel <#${channelId}>, all the event logging will be done there by default. A message will be sent in that channel to make sure it is correct.`);
bot.createMessage(channelId, `<@${message.author.id}>, this is now the fallback channel for all the events. That means if some event doesn't have some particular channel set, it will default to this channel`);
}
else {
bot.createMessage(message.channel.id, 'That channel is not in this guild. Don\'t try to prank me.');
}
});
commandH.endpoint('^event(?:-set)? (.+) msg (.+)$', async (match, message) => {
commandH.endpoint('^event (.+) msg (.+)$', async (match, message) => {
if (!message.member.permission.has('manageGuild') && message.author.id !== configM.config.owner) return;
dbEI.setEventMsg(message.channel.guild.id, match[1], match[2]);
bot.createMessage(message.channel.id, 'Event message set');
});
commandH.endpoint('^event(?:-set)? (.+) channel(?: (?:<#(.+?)>|(fallback|f)))?$', async (match, message) => {
commandH.endpoint('^event (.+) channel(?: (?:<#(.+?)>|(fallback|f)))?$', async (match, message) => {
if (!message.member.permission.has('manageGuild') && message.author.id !== configM.config.owner) return;
let channelId = message.channel.id;
if (match[2]) {
channelId = match[2];
@@ -39,35 +71,40 @@ exports.loadModule = function loadModule () {
else if (match[3]) {
channelId = 'f';
}
dbEI.setEventChannel(message.channel.guild.id, match[1], channelId);
if (channelId === 'f') {
bot.createMessage(message.channel.id, 'This event\'s channel has been set to the **fallback channel**');
if (legitChannel(message, channelId) || channelId === 'f') {
dbEI.setEventChannel(message.channel.guild.id, match[1], channelId);
if (channelId === 'f') {
bot.createMessage(message.channel.id, `This event\'s channel has been set back to the **fallback channel**, the logging for ${match[1]} will be done there.`);
}
else {
bot.createMessage(message.channel.id, `Event channel **set** to <#${channelId}>. The fallback channel for the event ${match[1]} has been overriden. To bind again the event to the fallback channel, execute \`event ${match[1]} channel fallback\``);
}
}
else {
bot.createMessage(message.channel.id, `Event channel set to <#${channelId}>. The fallback channel for that even has been overriden. To bind again the event to the fallback channel, execute \`event ${match[1]} channel fallback\``);
bot.createMessage(message.channel.id, 'That channel is not in this guild. Don\'t try to prank me.');
}
});
// Change the endpoint below, put something that couldn't interfere with the other
commandH.endpoint('^event(-set)? (.+) (.+)$', async (match, message) => {
commandH.endpoint('^event (.+) state (.+)$', async (match, message) => {
if (!message.member.permission.has('manageGuild') && message.author.id !== configM.config.owner) return;
let newState = true;
if (match[3]) {
if (match[3] === 'enable' || match[3] === 'true') {
if (match[2]) {
if (match[2] === 'enable' || match[2] === 'true') {
newState = true;
}
else if (match[3] === 'disable' || match[3] === 'false') {
else if (match[2] === 'disable' || match[2] === 'false') {
newState = false;
}
else {
bot.createMessage(message.channel.id, `Invalid option, the possibilities are : \`event${match[1] ? match[1] : ''} ${match[2]} (enable|true|disable|false)\``);
bot.createMessage(message.channel.id, `Invalid option, the possibilities are : \`event ${match[1]} (enable|true|disable|false)\``);
return;
}
}
dbEI.setEventEnable(message.channel.guild.id, match[2], newState);
dbEI.setEventEnable(message.channel.guild.id, match[1], newState);
if (newState) {
bot.createMessage(message.channel.id, `Event ${match[2]} has been **enabled**`);
bot.createMessage(message.channel.id, `Event ${match[1]} has been **enabled**`);
}
else {
bot.createMessage(message.channel.id, `Event ${match[2]} has been **disabled**`);
bot.createMessage(message.channel.id, `Event ${match[1]} has been **disabled**`);
}
});
};

View File

@@ -10,9 +10,10 @@ module.exports.loadConfig = function loadConfig(configPath) {
}
else {
let builder = {
token: "YOUR BOT TOKEN HERE",
game: "BOT GAME HERE",
hastebinServer: "https://hastebin.com",
token: 'YOUR BOT TOKEN HERE',
game: 'BOT GAME HERE',
owner: 'BOT OWNER ID HERE',
hastebinServer: 'https://hastebin.com',
};
fs.appendFileSync(configPath, JSON.stringify(builder));
return false;

View File

@@ -227,6 +227,11 @@ exports.debugServer = async function debugServer (id) {
console.log(inflateObj(await get(id)));
}
exports.getAllServer = async function getAllServer(id) {
let serverEvents = await get(id);
return inflateObj(serverEvents);
}
exports.getEvent = async function getEvent(id, eventName) {
let serverEvents = await get(id);
let obj = inflateObj(serverEvents);