Done event channelCreate
This commit is contained in:
5
package-lock.json
generated
5
package-lock.json
generated
@@ -486,6 +486,11 @@
|
||||
"simple-concat": "1.0.0"
|
||||
}
|
||||
},
|
||||
"snekfetch": {
|
||||
"version": "4.0.4",
|
||||
"resolved": "https://registry.npmjs.org/snekfetch/-/snekfetch-4.0.4.tgz",
|
||||
"integrity": "sha512-dyycG9fvwtSJqKPfMVOpXt+60qvMGe7vWLwOJDiSJaiAx+hs2EnFChG2bXCWn7ulz+zGzrHdN9/yeEb0YqEPww=="
|
||||
},
|
||||
"string-width": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
"bufferutil": "^3.0.5",
|
||||
"eris": "^0.8.6",
|
||||
"level": "^4.0.0",
|
||||
"snekfetch": "^4.0.4",
|
||||
"uws": "^10.148.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,37 @@
|
||||
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 () {
|
||||
|
||||
bot.on('channelCreate', async channel => {
|
||||
if (channel.type !== 0 && channel.type !== 2) return;
|
||||
// Add support for categories
|
||||
// Also, add independent support for each type of channels
|
||||
// Also, parse json with circular object support
|
||||
try {
|
||||
let a = await dbEI.getEvent(channel.guild.id, 'channelCreate');
|
||||
if (a.event.d === true) {
|
||||
let type = "";
|
||||
if (channel.type === 0) {
|
||||
type = "text";
|
||||
}
|
||||
else {
|
||||
type = "voice";
|
||||
}
|
||||
let mention = channel.mention;
|
||||
if (channel.type === 2) mention.shift();
|
||||
let hb = "";
|
||||
if (a.event.msg.includes("$hastebin")) {
|
||||
hb = await hastebin(configM.config.hastebinServer, 'Channel ' + channel.name + ' data as JSON\n\n------------------\n\n' + JSON.stringify(channel));
|
||||
}
|
||||
let finalMessage = a.event.msg.replace('$type', type).replace('$mention', mention).replace('$id', channel.id).replace('$timestamp', channel.createdAt).replace('$hastebin', hb).replace('$name', channel.name);
|
||||
bot.createMessage(a.event.c === 'f' ? a.fallbackChannelId : a.event.c, finalMessage);
|
||||
}
|
||||
}
|
||||
catch(e) {
|
||||
console.log(e);
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -47,6 +47,7 @@ exports.loadModule = function loadModule () {
|
||||
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\``);
|
||||
}
|
||||
});
|
||||
// Change the endpoint below, put something that couldn't interfere with the other
|
||||
commandH.endpoint('^event(-set)? (.+) (.+)$', async (match, message) => {
|
||||
let newState = true;
|
||||
if (match[3]) {
|
||||
|
||||
@@ -12,6 +12,7 @@ module.exports.loadConfig = function loadConfig(configPath) {
|
||||
let builder = {
|
||||
token: "YOUR BOT TOKEN HERE",
|
||||
game: "BOT GAME HERE",
|
||||
hastebinServer: "https://hastebin.com",
|
||||
};
|
||||
fs.appendFileSync(configPath, JSON.stringify(builder));
|
||||
return false;
|
||||
|
||||
16
src/hastebin.js
Normal file
16
src/hastebin.js
Normal file
@@ -0,0 +1,16 @@
|
||||
const snekfetch = require('snekfetch');
|
||||
|
||||
module.exports = async function hastebin(hastebin, msg) {
|
||||
try {
|
||||
let res = await snekfetch.post(hastebin + '/documents').send(msg);
|
||||
if (res.body.key) {
|
||||
return `${hastebin}/${res.body.key}`;
|
||||
}
|
||||
else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user