Merge pull request #44 from MSFTserver/patch-15

fix speech bot crashing issue [done]
This commit is contained in:
filipnyquist 2017-10-30 15:42:40 +01:00 committed by GitHub
commit 7ae5c09f40
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 27 deletions

View file

@ -1,11 +1,22 @@
let config = require('config');
let permRanks = config.get('moderation');
let speechChannels = config.get('speechbot');
// Checks if user is allowed to use a command only for mods/team members
exports.hasPerms = function(msg){
if(message.member.roles.some(r=>permRanks.perms.includes(r.name)) ) {
if(msg.member.roles.some(r=>permRanks.perms.includes(r.name)) ) {
return true;
} else {
return false;
}
}
}
exports.hasSpeechChannels = function(msg){
console.log(msg.channel.id)
console.log(msg)
if(speechChannels.channelsIDs.includes(msg.channel.id) ) {
return true;
} else {
return false;
}
}

View file

@ -1,12 +1,13 @@
var request = require('request');
var wget = require('wget');
var fs = require('fs')
let hasSpeechChannels = require('../helpers.js').hasSpeechChannels;
//debug output "true/false" outputs same error as slack message in console if set to true
//if set to false console will be left blank like normal
//some have more info on file details of error
var FullDebug = "true"
//outputs response from speech, very bulk reply
var ResponseDebug = "true"
var ResponseDebug = "false"
exports.commands = [
@ -17,17 +18,18 @@ exports.speech = {
usage: "<name>",
description: "gets top claim from spee.ch, coming soon post to spee.ch",
process: function(bot,msg,suffix){
var ChannelID = "373251793498406912"
if(!hasSpeechChannels(msg) && !inPrivate(msg)){
msg.channel.send('Please use <#' + ChannelID + '> or DMs to talk to speech bot.');
return;
}
var ChannelID = "363085078403874823"
var command = "!speech"
words = suffix.trim().split(' ').filter( function(n){return n !== "";} );
var imagename = words[0];
if(!inPrivateOrBotSandbox(msg)){
msg.channel.send('Please use <#' + ChannelID + '> or DMs to talk to speech bot.');
return;
}
//check if image name is help, if it is then do help message
if (imagename == "help") {
@ -80,12 +82,10 @@ exports.speech = {
var message = '`error not a valid url, please start with http or https`'
console.log('invalid url provided: ' + filepath);
msg.channel.send(message);
doHelp(bot,msg,suffix);
return
} else {
var message = '`error not a valid url, please start with http or https`'
msg.channel.send(message);
doHelp(bot,msg,suffix);
return;
}}
@ -113,13 +113,11 @@ if (isUriImage(url) === false) {
var message = '`error not a valid image url, be sure the link includes a file type`'
console.log('invalid url provided: ' + url);
msg.channel.send(message);
doHelp(bot,msg,suffix);
return;
return
} else {
var message = '`error not a valid image url, be sure the link includes a file type`'
msg.channel.send(message);
doHelp(bot,msg,suffix);
return;
return
}
}
//set third word to nsfw, with it being an optional functionality
@ -173,7 +171,7 @@ function doHelp(bot,msg,suffix) {
"description": '**!speech `<Name>`** : *displays top claim on speech* \n\n\n' +
"**COMING SOON POSTING TO SPEECH** \n\n" +
'**!speech `<Name> <URL> <NSFW>`** : *Uploads Image URL to Spee.ch* \n' +
'**NOTE : dont include spaces in name (NSFW is optional true/false, if left blank will default to false)** \n' +
'**NOTE : dont include spaces in name (NSFW is optional true/false, if left blank will defualt to false)** \n' +
'EXAMPLE : `!speech my-image-name https://url/to/image.png false`',
"color": 7976557,
"author": {
@ -206,11 +204,11 @@ request.post(
if (body.message === "no files found in request") {
if (FullDebug === "true") {
console.log("no file found: " + fullpath);
var message = '`Failed to upload file internally!!`\n please contact @MSFTserver#2901 or another moderator if the issue persists';
var message = '`Failed to upload file internally!!`\n please contact <@244245498746241025> or another moderator if the issue persists';
msg.channel.send(message);
return
} else {
var message = '`Failed to upload file internally!!`\n please contact @MSFTserver#2901 or another moderator if the issue persists';
var message = '`Failed to upload file internally!!`\n please contact <@244245498746241025> or another moderator if the issue persists';
msg.channel.send(message);
return
}
@ -220,11 +218,11 @@ request.post(
if (body.message === "no name field found in request") {
if (FullDebug === "true") {
console.log("no name field found: " + imagename);
var message = '`Failed to upload file internally!!`\n please contact @MSFTserver#2901 or another moderator if the issue persists';
var message = '`Failed to upload file internally!!`\n please contact <#244245498746241025> or another moderator if the issue persists';
msg.channel.send(message);
return
} else {
var message = '`Failed to upload file internally!!`\n please contact @MSFTserver#2901 or another moderator if the issue persists';
var message = '`Failed to upload file internally!!`\n please contact <#244245498746241025> or another moderator if the issue persists';
msg.channel.send(message);
return
}
@ -241,14 +239,6 @@ request.post(
}
);
};
function inPrivateOrBotSandbox(msg){
if((msg.channel.type == 'dm') || (msg.channel.id === ChannelID)){
return true;
}else{
return false;
}
}
}
}

View file

@ -17,6 +17,9 @@
"perms": ["LBRY MODS","LBRY TEAM"], // Roles that have access to all commands.
"logchannel": "371620338263523328" // Channel to log the bots moderation..
},
"speechbot":{
"channelIDs": ["363085078403874823","363086945976320010","363088045366312962","363084262028607488","369896313082478594","363084227518136322"]
},
"rolelist":{
"allowedroles": ["Role1","Role2"]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB