Made a lot of things

This commit is contained in:
ahoZiorce
2018-07-02 17:44:37 +02:00
parent 6ecb727ff3
commit 4caefcdfd7
9 changed files with 436 additions and 28 deletions

View File

@@ -7,5 +7,12 @@ exports.loadModule = function loadModule () {
});
commandH.endpoint('^ping (.*)$', (match, message) => {
bot.createMessage(message.channel.id, 'Pong : ' + match[1]);
let time = new Date();
bot.once('messageCreate', (msg) => {
let ms = new Date().getTime() - time.getTime();
if (msg.channel !== message.channel) return;
if (msg.author !== bot.user) return;
bot.createMessage(msg.channel.id, ms + ' ms');
});
});
}
};

6
src/cmd/events.js Normal file
View File

@@ -0,0 +1,6 @@
const commandH = require('../commandHandler');
const bot = require('../botClient').bot;
exports.loadModule = function loadModule () {
};

72
src/cmd/main.js Normal file
View File

@@ -0,0 +1,72 @@
const commandH = require('../commandHandler');
const bot = require('../botClient').bot;
const dbEI = require('../dbEventInterface');
exports.loadModule = function loadModule () {
commandH.endpoint('^(?:init|set)serv$', async (match, message) => {
if (!message.member.permission.has('administrator')) return;
try {
await dbEI.initServer(message.channel.guild.id, message.channel.id);
bot.createMessage(message.channel.id, 'Server successfully set');
}
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('^set-channel(?: <#(.+?)>)?$', async (match, message) => {
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.`);
});
commandH.endpoint('^event(?:-set)? (.+) msg (.+)$', async (match, message) => {
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) => {
let channelId = message.channel.id;
if (match[2]) {
channelId = match[2];
}
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**');
}
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\``);
}
});
commandH.endpoint('^event(-set)? (.+) (.+)$', async (match, message) => {
let newState = true;
if (match[3]) {
if (match[3] === 'enable' || match[3] === 'true') {
newState = true;
}
else if (match[3] === 'disable' || match[3] === '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)\``);
return;
}
}
dbEI.setEventEnable(message.channel.guild.id, match[2], newState);
if (newState) {
bot.createMessage(message.channel.id, `Event ${match[2]} has been **enabled**`);
}
else {
bot.createMessage(message.channel.id, `Event ${match[2]} has been **disabled**`);
}
});
};