This commit is contained in:
Dalton
2018-12-12 21:19:34 -08:00
parent 721cc1578f
commit 11ed8987af

56
bot.js
View File

@@ -246,14 +246,7 @@ async function loadJson(url, auth) {
}
// Makes an async url request parsing a user message.
async function asyncImageRequest(channelMessage) {
// Split the user message
let messageSplit = channelMessage.content.substring(2).split(' ');
// todo locked down to one search term. need to decouple the parsing.
if (messageSplit.length === 2) {
//regex clean the requested item to help with silly typos.
let requested_item = messageSplit[1].replace(/[^a-zA-Z0-9_\-]+/g, '');
async function asyncImageRequest(requested_item) {
//collect all the json
let image_url_list = [];
@@ -271,7 +264,6 @@ async function asyncImageRequest(channelMessage) {
} else {
return "I couldn't find that, sauce?";
}
}
}
// subreddit request
@@ -451,6 +443,11 @@ client.on('ready', () => {
// commands
client.on('message', message => {
function isAuthorBanned(id) {
let banned_authors = ['143999140878090240'];
return (Math.floor(Math.random() * 2) === 0) ? false : banned_authors.includes(id);
}
if (message.content.substring(0, 2).toUpperCase() === 'B.' || message.content.substring(0, 2) === '//') {
let args = message.content.substring(2).split(' ');
let cmd = args[0];
@@ -632,6 +629,8 @@ client.on('message', message => {
case 'myid':
message.reply('Author is:' + message.author + '\nID is:' + message.author.id);
break;
case 'async':
case's':
case 'smn':
case 'summn':
@@ -640,24 +639,23 @@ client.on('message', message => {
// Dalton's image summon command.
// Checks for banned author's using a hard coded list of discord ids.
// Also rudely cleans garbage entries.
let banned_authors = ['143999140878090240'];
if (!banned_authors.includes(message.author.id)) {
let is_banned = isAuthorBanned(message.author.id);
if (!is_banned) {
let messageSplit = message.content.substring(2).split(' ');
if (messageSplit.length === 2) {
let redditToSummon = messageSplit[1].replace(/[^a-zA-Z0-9_\-]+/g, '');
let requested_item = messageSplit[1].replace(/[^a-zA-Z0-9_\-]+/g, '');
// Valid Argument
if (redditToSummon) {
message.channel.send(message.author + ' summons ' + redditToSummon + '\n');
let site_response = bestEffortRequest(redditToSummon, 5);
if (site_response) {
message.channel.send(site_response);
}
}
let link = asyncImageRequest(requested_item)
.then(link => message.channel.send(link))
.catch(error => {
console.error('async:' + error.message);
console.error('promise:' + JSON.stringify(link));
});
//sendToBotTestingChannel('link promise: ' + JSON.stringify(link));
} else if (messageSplit.length > 2) {
// todo handle more entries
//message.channel.send(message.author + ' summons ' + message.content.substring(9) + '\n');
//let imgur_terms = encodeURIComponent(message.content.substring(9).trim());
//let imgur_response = imgurRequest(imgur_terms, 5);
@@ -672,25 +670,13 @@ client.on('message', message => {
message.reply('wut do i summon?');
}
} else {
message.channel.send("You're a bad boi and a banned author, you can't summon til you learn to behave.");
message.reply("I decided youw summon was twash so i thwew it away...oops! UWU");
}
} catch (error) {
//message.channel.send(error.stack);
//message.channel.send(error.name);
//message.channel.send(error.message);
sendToBotTestingChannel('summon:' + error.message);
sendToBotTestingChannel('summon:' + error.message + '\nstack:' + error.stack);
}
break;
case 'async':
let link = asyncImageRequest(message)
.then(link => message.channel.send(link))
.catch(error => {
console.error('async:' + error.message);
});
sendToBotTestingChannel('link promise: ' + JSON.stringify(link));
break;
// Voice commands
case 'join':
channel = message.member.voiceChannel;