mirror of
https://github.com/LBRYFoundation/lbry-wunderbot.git
synced 2025-08-23 17:47:27 +00:00
Merge pull request #120 from nikooo777/crash-fixes
Crash fixes and cleanup
This commit is contained in:
commit
ebf304c0fb
7 changed files with 120 additions and 95 deletions
|
@ -1,19 +1,19 @@
|
||||||
let config = require("config");
|
let config = require('config');
|
||||||
let permRanks = config.get("moderation");
|
let permRanks = config.get('moderation');
|
||||||
let speechBotChannels = config.get("speechbot");
|
let speechBotChannels = config.get('speechbot');
|
||||||
let priceBotChannels = config.get("pricebot");
|
let priceBotChannels = config.get('pricebot');
|
||||||
let ExcludedSpam = config.get("spamdetection");
|
let ExcludedSpam = config.get('spamdetection');
|
||||||
let hashBotChannels = config.get("hashbot");
|
let hashBotChannels = config.get('hashbot');
|
||||||
let statsBotChannels = config.get("statsbot");
|
let statsBotChannels = config.get('statsbot');
|
||||||
|
|
||||||
// Checks if user is allowed to use a command only for mods/team members
|
// Checks if user is allowed to use a command only for mods/team members
|
||||||
exports.hasPerms = function(msg) {
|
exports.hasPerms = function(msg) {
|
||||||
return msg.member.roles.some(r => permRanks.perms.includes(r.name));
|
return msg.member.roles !== null && msg.member.roles.some(r => permRanks.perms.includes(r.name));
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check if command was sent in dm
|
// Check if command was sent in dm
|
||||||
exports.inPrivate = function(msg) {
|
exports.inPrivate = function(msg) {
|
||||||
return msg.channel.type == "dm";
|
return msg.channel.type == 'dm';
|
||||||
};
|
};
|
||||||
|
|
||||||
// Checks if Message was sent from a channel in speechBot Channels list
|
// Checks if Message was sent from a channel in speechBot Channels list
|
||||||
|
|
|
@ -105,7 +105,7 @@ function announceClaimsLoop(block, lastBlock, currentHeight) {
|
||||||
claimsFound = claims.length;
|
claimsFound = claims.length;
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
claims.map(function(claim) {
|
claims.map(function(claim) {
|
||||||
//slack has a rate limit. to avoid hitting it we must have a small delay between each message
|
//the API has a rate limit. to avoid hitting it we must have a small delay between each message
|
||||||
//if claims were found in this block, then we wait, otherwise we don't
|
//if claims were found in this block, then we wait, otherwise we don't
|
||||||
if (claimsFound > 0 && claim.hasOwnProperty("claimId"))
|
if (claimsFound > 0 && claim.hasOwnProperty("claimId"))
|
||||||
sleep.msleep(300);
|
sleep.msleep(300);
|
||||||
|
@ -127,6 +127,12 @@ function announceClaimsLoop(block, lastBlock, currentHeight) {
|
||||||
function announceClaim(claim, claimBlockHeight, currentHeight) {
|
function announceClaim(claim, claimBlockHeight, currentHeight) {
|
||||||
console.log("" + claimBlockHeight + ": New claim for " + claim["name"]);
|
console.log("" + claimBlockHeight + ": New claim for " + claim["name"]);
|
||||||
console.log(claim);
|
console.log(claim);
|
||||||
|
|
||||||
|
//ignore supports for now
|
||||||
|
//the issue with supports is that they should be treated completely differently
|
||||||
|
//they are not new claims...
|
||||||
|
if (claim.hasOwnProperty("supported claimId")) return;
|
||||||
|
|
||||||
let options = {
|
let options = {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
url: "http://127.0.0.1:5000/claim_decode/" + claim["name"]
|
url: "http://127.0.0.1:5000/claim_decode/" + claim["name"]
|
||||||
|
@ -170,10 +176,12 @@ function announceClaim(claim, claimBlockHeight, currentHeight) {
|
||||||
const text = [];
|
const text = [];
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
/*if (channelName) {
|
/*
|
||||||
text.push("Channel: lbry://" + channelName);
|
if (channelName) {
|
||||||
}
|
text.push("Channel: lbry://" + channelName);
|
||||||
else*/
|
}
|
||||||
|
else
|
||||||
|
*/
|
||||||
console.log(value);
|
console.log(value);
|
||||||
if (value["author"]) {
|
if (value["author"]) {
|
||||||
text.push("author: " + value["author"]);
|
text.push("author: " + value["author"]);
|
||||||
|
|
|
@ -13,25 +13,25 @@ exports.lbrylink = function(bot, msg, suffix) {
|
||||||
if (link != -1) {
|
if (link != -1) {
|
||||||
var text = msg.content.replace("lbry://", "https://open.lbry.io/");
|
var text = msg.content.replace("lbry://", "https://open.lbry.io/");
|
||||||
var message = GetWordByPos(text, link);
|
var message = GetWordByPos(text, link);
|
||||||
if (ResponseDebug == "true") {
|
if (ResponseDebug == "true") {
|
||||||
console.log("text = " + text);
|
console.log("text = " + text);
|
||||||
console.log("message = " + message);
|
console.log("message = " + message);
|
||||||
}
|
}
|
||||||
if (message === "https://open.lbry.io/") {
|
if (message === "https://open.lbry.io/") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (message.search(">") != -1) {
|
if (message.search(">") != -1) {
|
||||||
parsename = message.split(">").pop();
|
parsename = message.split(">").pop();
|
||||||
if (parsename.search("/") == -1){
|
if (parsename.search("/") == -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
newname = message.split("/").pop();
|
newname = message.split("/").pop();
|
||||||
message = "https://open.lbry.io/" + newname;
|
message = "https://open.lbry.io/" + newname;
|
||||||
if (ResponseDebug == "true") {
|
if (ResponseDebug == "true") {
|
||||||
console.log("Username Provided!");
|
console.log("Username Provided!");
|
||||||
console.log("parsename = " + parsename);
|
console.log("parsename = " + parsename);
|
||||||
console.log("newname = " + newname);
|
console.log("newname = " + newname);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var newname = message.replace("https://open.lbry.io/", "");
|
var newname = message.replace("https://open.lbry.io/", "");
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,8 @@ exports.releasenotes = {
|
||||||
timestamp: releasedate,
|
timestamp: releasedate,
|
||||||
author: {
|
author: {
|
||||||
name: "Lbry-app Release Notes for " + releasename,
|
name: "Lbry-app Release Notes for " + releasename,
|
||||||
icon_url: "http://www.pngall.com/wp-content/uploads/2016/04/Github-PNG-Image.png"
|
icon_url:
|
||||||
|
"http://www.pngall.com/wp-content/uploads/2016/04/Github-PNG-Image.png"
|
||||||
},
|
},
|
||||||
footer: {
|
footer: {
|
||||||
icon_url: "https://i.imgur.com/yWf5USu.png",
|
icon_url: "https://i.imgur.com/yWf5USu.png",
|
||||||
|
@ -58,9 +59,12 @@ exports.releasenotes = {
|
||||||
msg.author.send(message);
|
msg.author.send(message);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
message = releasemessage.trim().split("###").filter(function(n) {
|
message = releasemessage
|
||||||
return n !== "";
|
.trim()
|
||||||
});
|
.split("###")
|
||||||
|
.filter(function(n) {
|
||||||
|
return n !== "";
|
||||||
|
});
|
||||||
releasemessage1 = message[0];
|
releasemessage1 = message[0];
|
||||||
releasemessage2 = message[1];
|
releasemessage2 = message[1];
|
||||||
releasemessage3 = message[2];
|
releasemessage3 = message[2];
|
||||||
|
@ -75,7 +79,8 @@ exports.releasenotes = {
|
||||||
timestamp: releasedate,
|
timestamp: releasedate,
|
||||||
author: {
|
author: {
|
||||||
name: "Lbry-app Release Notes for " + releasename,
|
name: "Lbry-app Release Notes for " + releasename,
|
||||||
icon_url: "http://www.pngall.com/wp-content/uploads/2016/04/Github-PNG-Image.png"
|
icon_url:
|
||||||
|
"http://www.pngall.com/wp-content/uploads/2016/04/Github-PNG-Image.png"
|
||||||
},
|
},
|
||||||
footer: {
|
footer: {
|
||||||
icon_url: "https://i.imgur.com/yWf5USu.png",
|
icon_url: "https://i.imgur.com/yWf5USu.png",
|
||||||
|
@ -89,7 +94,8 @@ exports.releasenotes = {
|
||||||
color: 7976557,
|
color: 7976557,
|
||||||
timestamp: releasedate,
|
timestamp: releasedate,
|
||||||
author: {
|
author: {
|
||||||
icon_url: "http://www.pngall.com/wp-content/uploads/2016/04/Github-PNG-Image.png"
|
icon_url:
|
||||||
|
"http://www.pngall.com/wp-content/uploads/2016/04/Github-PNG-Image.png"
|
||||||
},
|
},
|
||||||
footer: {
|
footer: {
|
||||||
icon_url: "https://i.imgur.com/yWf5USu.png",
|
icon_url: "https://i.imgur.com/yWf5USu.png",
|
||||||
|
@ -103,7 +109,8 @@ exports.releasenotes = {
|
||||||
color: 7976557,
|
color: 7976557,
|
||||||
timestamp: releasedate,
|
timestamp: releasedate,
|
||||||
author: {
|
author: {
|
||||||
icon_url: "http://www.pngall.com/wp-content/uploads/2016/04/Github-PNG-Image.png"
|
icon_url:
|
||||||
|
"http://www.pngall.com/wp-content/uploads/2016/04/Github-PNG-Image.png"
|
||||||
},
|
},
|
||||||
footer: {
|
footer: {
|
||||||
icon_url: "https://i.imgur.com/yWf5USu.png",
|
icon_url: "https://i.imgur.com/yWf5USu.png",
|
||||||
|
@ -117,7 +124,8 @@ exports.releasenotes = {
|
||||||
color: 7976557,
|
color: 7976557,
|
||||||
timestamp: releasedate,
|
timestamp: releasedate,
|
||||||
author: {
|
author: {
|
||||||
icon_url: "http://www.pngall.com/wp-content/uploads/2016/04/Github-PNG-Image.png"
|
icon_url:
|
||||||
|
"http://www.pngall.com/wp-content/uploads/2016/04/Github-PNG-Image.png"
|
||||||
},
|
},
|
||||||
footer: {
|
footer: {
|
||||||
icon_url: "https://i.imgur.com/yWf5USu.png",
|
icon_url: "https://i.imgur.com/yWf5USu.png",
|
||||||
|
@ -131,7 +139,8 @@ exports.releasenotes = {
|
||||||
color: 7976557,
|
color: 7976557,
|
||||||
timestamp: releasedate,
|
timestamp: releasedate,
|
||||||
author: {
|
author: {
|
||||||
icon_url: "http://www.pngall.com/wp-content/uploads/2016/04/Github-PNG-Image.png"
|
icon_url:
|
||||||
|
"http://www.pngall.com/wp-content/uploads/2016/04/Github-PNG-Image.png"
|
||||||
},
|
},
|
||||||
footer: {
|
footer: {
|
||||||
icon_url: "https://i.imgur.com/yWf5USu.png",
|
icon_url: "https://i.imgur.com/yWf5USu.png",
|
||||||
|
|
|
@ -23,33 +23,39 @@ exports.addrole = {
|
||||||
//console.log(rolelist.allowedroles);
|
//console.log(rolelist.allowedroles);
|
||||||
//console.log(config.get('allowedroles'));
|
//console.log(config.get('allowedroles'));
|
||||||
if (suffix) {
|
if (suffix) {
|
||||||
if (rolelist.allowedroles.includes(suffix)) {
|
if (rolelist.allowedroles.includes(suffix)) {
|
||||||
//console.log('Role is in allowed roles.');
|
//console.log('Role is in allowed roles.');
|
||||||
//console.log('Role to add: ' + newrole);
|
//console.log('Role to add: ' + newrole);
|
||||||
if (!msg.member.roles.find("name", suffix)) {
|
if (!msg.member.roles.find("name", suffix)) {
|
||||||
msg.member
|
msg.member
|
||||||
.addRole(newrole)
|
.addRole(newrole)
|
||||||
.then(
|
.then(
|
||||||
msg.channel.send(
|
msg.channel.send(
|
||||||
msg.member + " has been added to the " + suffix + " role!"
|
msg.member + " has been added to the " + suffix + " role!"
|
||||||
)
|
)
|
||||||
);
|
|
||||||
//console.log('Added role')
|
|
||||||
//msg.channel.send(msg.member + ' has been added to the ' + suffix + ' role!');
|
|
||||||
} else {
|
|
||||||
msg.channel.send(
|
|
||||||
"It seems that you already have that role! Try removing it first with the " + botconfig.prefix + "delrole command!"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
msg.channel.send(
|
|
||||||
"That role isn't one you can add yourself too! Please run the " + botconfig.prefix + "roles command to find out which ones are allowed."
|
|
||||||
);
|
);
|
||||||
|
//console.log('Added role')
|
||||||
|
//msg.channel.send(msg.member + ' has been added to the ' + suffix + ' role!');
|
||||||
|
} else {
|
||||||
|
msg.channel.send(
|
||||||
|
"It seems that you already have that role! Try removing it first with the " +
|
||||||
|
botconfig.prefix +
|
||||||
|
"delrole command!"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
msg.channel.send(
|
||||||
|
"That role isn't one you can add yourself too! Please run the " +
|
||||||
|
botconfig.prefix +
|
||||||
|
"roles command to find out which ones are allowed."
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
msg.channel.send (
|
msg.channel.send(
|
||||||
"Please specify a role. Type " + botconfig.prefix + "roles to see which you may add!"
|
"Please specify a role. Type " +
|
||||||
)
|
botconfig.prefix +
|
||||||
|
"roles to see which you may add!"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -64,29 +70,35 @@ exports.delrole = {
|
||||||
//console.log(msg);
|
//console.log(msg);
|
||||||
//console.log('Printing Suffix! ' + suffix);
|
//console.log('Printing Suffix! ' + suffix);
|
||||||
if (suffix) {
|
if (suffix) {
|
||||||
if (rolelist.allowedroles.includes(suffix)) {
|
if (rolelist.allowedroles.includes(suffix)) {
|
||||||
if (msg.member.roles.find("name", suffix)) {
|
if (msg.member.roles.find("name", suffix)) {
|
||||||
msg.member
|
msg.member
|
||||||
.removeRole(oldrole)
|
.removeRole(oldrole)
|
||||||
.then(
|
.then(
|
||||||
msg.channel.send(
|
msg.channel.send(
|
||||||
msg.member + " has been removed from the " + suffix + " role!"
|
msg.member + " has been removed from the " + suffix + " role!"
|
||||||
)
|
)
|
||||||
);
|
|
||||||
} else {
|
|
||||||
msg.channel.send(
|
|
||||||
"You don't seem to have that role! Try adding it first with the " + botconfig.prefix + "addrole command!"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
msg.channel.send(
|
|
||||||
"That role isn't one you can add yourself too! Please run the " + botconfig.prefix + "roles command to find out which ones are allowed."
|
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
msg.channel.send(
|
||||||
|
"You don't seem to have that role! Try adding it first with the " +
|
||||||
|
botconfig.prefix +
|
||||||
|
"addrole command!"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
msg.channel.send(
|
msg.channel.send(
|
||||||
"Please specify a role. Type " + botconfig.prefix + "roles to see which you may add!"
|
"That role isn't one you can add yourself too! Please run the " +
|
||||||
)
|
botconfig.prefix +
|
||||||
|
"roles command to find out which ones are allowed."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
msg.channel.send(
|
||||||
|
"Please specify a role. Type " +
|
||||||
|
botconfig.prefix +
|
||||||
|
"roles to see which you may add!"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -39,7 +39,7 @@ exports.antiSpam = function(bot) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (msg.author.id != bot.user.id) {
|
if (msg.author.id != bot.user.id) {
|
||||||
var now = Math.floor(Date.now());
|
let now = Math.floor(Date.now());
|
||||||
authors.push({
|
authors.push({
|
||||||
time: now,
|
time: now,
|
||||||
author: msg.author.id
|
author: msg.author.id
|
||||||
|
@ -50,8 +50,8 @@ exports.antiSpam = function(bot) {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check how many times the same message has been sent.
|
// Check how many times the same message has been sent.
|
||||||
var msgMatch = 0;
|
let msgMatch = 0;
|
||||||
for (var i = 0; i < messagelog.length; i++) {
|
for (let i = 0; i < messagelog.length; i++) {
|
||||||
if (
|
if (
|
||||||
messagelog[i].message == msg.content &&
|
messagelog[i].message == msg.content &&
|
||||||
messagelog[i].author == msg.author.id &&
|
messagelog[i].author == msg.author.id &&
|
||||||
|
@ -70,7 +70,7 @@ exports.antiSpam = function(bot) {
|
||||||
|
|
||||||
matched = 0;
|
matched = 0;
|
||||||
|
|
||||||
for (var i = 0; i < authors.length; i++) {
|
for (let i = 0; i < authors.length; i++) {
|
||||||
if (authors[i].time > now - interval) {
|
if (authors[i].time > now - interval) {
|
||||||
matched++;
|
matched++;
|
||||||
if (matched == warnBuffer && !warned.includes(msg.author.id)) {
|
if (matched == warnBuffer && !warned.includes(msg.author.id)) {
|
||||||
|
@ -109,7 +109,7 @@ exports.antiSpam = function(bot) {
|
||||||
* @return {boolean} True or False
|
* @return {boolean} True or False
|
||||||
*/
|
*/
|
||||||
function ban(msg, userid) {
|
function ban(msg, userid) {
|
||||||
for (var i = 0; i < messagelog.length; i++) {
|
for (let i = 0; i < messagelog.length; i++) {
|
||||||
if (messagelog[i].author == msg.author.id) {
|
if (messagelog[i].author == msg.author.id) {
|
||||||
messagelog.splice(i);
|
messagelog.splice(i);
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ exports.antiSpam = function(bot) {
|
||||||
|
|
||||||
banned.push(msg.author.id);
|
banned.push(msg.author.id);
|
||||||
|
|
||||||
var user = msg.channel.guild.members.find(
|
let user = msg.channel.guild.members.find(
|
||||||
member => member.user.id === msg.author.id
|
member => member.user.id === msg.author.id
|
||||||
);
|
);
|
||||||
if (user) {
|
if (user) {
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
"use strict";
|
'use strict';
|
||||||
|
|
||||||
const fs = require("fs"),
|
const fs = require('fs'),
|
||||||
path = require("path");
|
path = require('path');
|
||||||
|
|
||||||
function getPlugins(srcpath) {
|
function getPlugins(srcpath) {
|
||||||
return fs.readdirSync(srcpath);
|
return fs.readdirSync(srcpath);
|
||||||
}
|
}
|
||||||
let plugin_directory = path.join(__dirname, "modules");
|
let plugin_directory = path.join(__dirname, 'modules');
|
||||||
let plugins = getPlugins(plugin_directory);
|
let plugins = getPlugins(plugin_directory);
|
||||||
|
|
||||||
exports.init = function init() {
|
exports.init = function init() {
|
||||||
|
@ -14,7 +14,7 @@ exports.init = function init() {
|
||||||
};
|
};
|
||||||
|
|
||||||
function load_plugins() {
|
function load_plugins() {
|
||||||
const dbot = require("./bot.js");
|
const dbot = require('./bot.js');
|
||||||
let commandCount = 0;
|
let commandCount = 0;
|
||||||
let otherFunc = 0;
|
let otherFunc = 0;
|
||||||
for (let i = 0; i < plugins.length; i++) {
|
for (let i = 0; i < plugins.length; i++) {
|
||||||
|
@ -25,7 +25,7 @@ function load_plugins() {
|
||||||
console.log(`Improper setup of the '${plugins[i]}' plugin. : ${err}`);
|
console.log(`Improper setup of the '${plugins[i]}' plugin. : ${err}`);
|
||||||
}
|
}
|
||||||
if (plugin) {
|
if (plugin) {
|
||||||
if ("commands" in plugin) {
|
if ('commands' in plugin) {
|
||||||
for (let j = 0; j < plugin.commands.length; j++) {
|
for (let j = 0; j < plugin.commands.length; j++) {
|
||||||
if (plugin.commands[j] in plugin) {
|
if (plugin.commands[j] in plugin) {
|
||||||
dbot.addCommand(plugin.commands[j], plugin[plugin.commands[j]]);
|
dbot.addCommand(plugin.commands[j], plugin[plugin.commands[j]]);
|
||||||
|
@ -33,7 +33,7 @@ function load_plugins() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ("custom" in plugin) {
|
if ('custom' in plugin) {
|
||||||
for (let j = 0; j < plugin.custom.length; j++) {
|
for (let j = 0; j < plugin.custom.length; j++) {
|
||||||
if (plugin.custom[j] in plugin) {
|
if (plugin.custom[j] in plugin) {
|
||||||
dbot.addCustomFunc(plugin[plugin.custom[j]]);
|
dbot.addCustomFunc(plugin[plugin.custom[j]]);
|
||||||
|
@ -43,9 +43,5 @@ function load_plugins() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(
|
console.log(`Loaded ${dbot.commandCount()} chat commands and ${otherFunc} custom functions.`);
|
||||||
`Loaded ${dbot.commandCount()} chat commands and ${
|
|
||||||
otherFunc
|
|
||||||
} custom functions.`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue