Skip to content

Commit

Permalink
update dependencies; fix weather issue progdisc#114; update deprecati…
Browse files Browse the repository at this point in the history
…on usage (.sendMessage -> .send); bot now runs if help-directory is missing instead of crashing
  • Loading branch information
devoidfury committed May 14, 2018
1 parent 85b58ab commit d6877a3
Show file tree
Hide file tree
Showing 13 changed files with 260 additions and 202 deletions.
14 changes: 9 additions & 5 deletions TheAwesomeBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class TheAwesomeBot {
return;
}

// don't respond to dm
if (message.channel.type === 'dm') {
return;
}

// check if message is a command
const cmdMatch = message.cleanContent.match(this.cmd_re);

Expand All @@ -44,7 +49,7 @@ class TheAwesomeBot {
let helpText = 'maybe try these valid commands? *kthnxbye!*\n\n```';
helpText += this.usageList;
helpText += '```';
message.channel.sendMessage(helpText);
message.channel.send(helpText);
}
return;
}
Expand All @@ -58,7 +63,7 @@ class TheAwesomeBot {
try {
showUsage = this.commands[cmd].run(this, message, cmdArgs);
} catch (err) {
message.channel.sendMessage('There was an error running the command:\n' +
message.channel.send('There was an error running the command:\n' +
'```\n' + err.toString() + '\n```');
console.error(err);
console.error(err.stack);
Expand All @@ -69,7 +74,7 @@ class TheAwesomeBot {
if (typeof usage !== 'string') {
usage = usage.join('\n');
}
message.channel.sendMessage('```\n' + usage + '\n```');
message.channel.send('```\n' + usage + '\n```');
}
};
}
Expand All @@ -86,7 +91,7 @@ class TheAwesomeBot {
}

serverNewMember() {
return ((server, user) => this.client.sendMessage(user, this.usageList));
return ((server, user) => this.client.send(user, this.usageList));
}

onDisconnected() {
Expand Down Expand Up @@ -156,4 +161,3 @@ class TheAwesomeBot {
}

module.exports = TheAwesomeBot;

2 changes: 1 addition & 1 deletion commands/eval/eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ module.exports = {
80,
lang, gentoken(apiToken));

message.channel.sendMessage('⏲ evaluating...')
message.channel.send('⏲ evaluating...')
.then((evalMsg) => {
let newContent = '';
repl.evaluateOnce(
Expand Down
2 changes: 1 addition & 1 deletion commands/help/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
run: (bot, message) => {
let r = 'This command is deprecated.\n';
r += 'See https://github.com/progdisc/resources for our new and improved resource list.';
message.channel.sendMessage(r);
message.channel.send(r);
},

init: () => {
Expand Down
8 changes: 4 additions & 4 deletions commands/pbf/pbf.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ function parsePbfLink(pbfLink, message) {

if (htmlBody('#topimg')) {
const img = htmlBody('#topimg');
message.channel.sendMessage('```diff\n' +
message.channel.send('```diff\n' +
`Title: ${img.attr('alt')}\n` +
'```\n' +
`http://pbfcomics.com${img.attr('src')}`);
} else {
message.channel.sendMessage(`I'm sorry ${message.author}, i couldn't find a PBF Comic.`);
message.channel.send(`I'm sorry ${message.author}, i couldn't find a PBF Comic.`);
}
}
});
Expand Down Expand Up @@ -48,12 +48,12 @@ module.exports = {
}
});
} catch (e) {
message.channel.sendMessage('There was a problem with DuckDuckGo query.');
message.channel.send('There was a problem with DuckDuckGo query.');
}
// we are done with finding a link
if (!pbfLink) {
// link is either empty (this should NOT happen) or we don't have a link
message.channel.sendMessage(`I'm sorry ${message.author}, i couldn't find a PBF Comic.`);
message.channel.send(`I'm sorry ${message.author}, i couldn't find a PBF Comic.`);
} else {
parsePbfLink(pbfLink, message);
}
Expand Down
21 changes: 14 additions & 7 deletions commands/pro/pro.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ function loadAndMatchPros(bot) {
updateProsMatcher();
const helpChannel = bot.client.channels.find('name', 'help-directory');

if (!helpChannel) {
const err = new Error('help-directory channel not found');
err.intentional = true;
return Promise.reject(err);
}

return helpChannel.fetchMessages({ limit: 100 })
.then((messages) => {
messages.forEach((messageObj) => {
Expand Down Expand Up @@ -83,9 +89,9 @@ module.exports = {
if (memberId in proHelpText) {
let response = `**Help Directory entry for user ${message.mentions.users.first().username}:**\n`;
response += proHelpText[memberId];
message.channel.sendMessage(response);
message.channel.send(response);
} else {
message.channel.sendMessage(`Could not find user ${message.mentions.users.first().username} in directory`);
message.channel.send(`Could not find user ${message.mentions.users.first().username} in directory`);
}
return false;
}
Expand All @@ -94,7 +100,7 @@ module.exports = {

if (lang === 'reset' && bot.isAdminOrMod(message.member)) {
loadAndMatchPros(bot).then(() => {
message.channel.sendMessage('Pros list refreshed.');
message.channel.send('Pros list refreshed.');
return false;
})
.catch((err) => {
Expand All @@ -109,7 +115,7 @@ module.exports = {
lang = ((match && match[1]) || lang).toLowerCase();

const foundPros = getPros(bot, lang);
message.channel.sendMessage(foundPros ?
message.channel.send(foundPros ?
`Here are some pros online that can help with **${pros[lang].original}**: \n${foundPros}` :
`No pros found for ${cmdArgs} :(`);
return false;
Expand All @@ -122,9 +128,10 @@ module.exports = {
console.log('Done reading in pros from #helpdirectory!');
})
.catch((err) => {
console.error(err);
console.error(err.stack);
console.error('[error]', err.message);
if (!err.intentional) {
console.error(err.stack);
}
});
},
};

6 changes: 3 additions & 3 deletions commands/quickref/quickref.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ module.exports = {
const response = references[cmdArgs.toLowerCase()];

if (response) {
message.channel.sendMessage(
message.channel.send(
`${response}`);
} else {
message.channel.sendMessage('I don\'t have any references for that. If you have a suggestion, let us know!');
message.channel.send('I don\'t have any references for that. If you have a suggestion, let us know!');
}
} else {
let r = '\nreferences I have ready to go:';
r += '\n```';
r += Object.keys(references).map(t => `\n - ${t}`).join('');
r += '\n```';
message.channel.sendMessage(r);
message.channel.send(r);
}
},
init: () => {
Expand Down
36 changes: 19 additions & 17 deletions commands/stream/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ const commands = {
let [, topic, link, user] = args.split(' '); // eslint-disable-line prefer-const

if (!topic || !link) {
return message.channel.sendMessage('err, please provide topic and link!');
return message.channel.send('err, please provide topic and link!');
}

if (link.indexOf('http://') === -1 && link.indexOf('https://') === -1) {
return message.channel.sendMessage('a valid link must be supplied (starting with http/https)!');
return message.channel.send('a valid link must be supplied (starting with http/https)!');
}

user = message.mentions.users.first();
Expand All @@ -93,14 +93,14 @@ const commands = {
streams[topic][user.id].link = link;

existingChannel.setTopic(link).catch(err =>
existingChannel.sendMessage('There was an error setting the existings channel topic!'));
existingChannel.send('There was an error setting the existings channel topic!'));

return message.channel.sendMessage('Channel already exists.. Updated stream link!');
return message.channel.send('Channel already exists.. Updated stream link!');
}
return createChannel(channelFormat, bot, message, topic, user.id)
.then(createdChannel => setTopicToLink(createdChannel, link, bot, topic, user.id))
.then(channelWithTopic => message.channel.sendMessage(`Created ${channelWithTopic}!`))
.catch(err => message.channel.sendMessage(`Sorry, could not create channel (${err})`));
.then(channelWithTopic => message.channel.send(`Created ${channelWithTopic}!`))
.catch(err => message.channel.send(`Sorry, could not create channel (${err})`));
},

remove: function handleRemoveStream(bot, message) {
Expand All @@ -110,7 +110,7 @@ const commands = {
const id = user ? user.id : message.author.id;

if (!bot.isAdminOrMod(message.member) && id !== message.author.id) {
message.channel.sendMessage('Only admins or mods can remove others\' streams.');
message.channel.send('Only admins or mods can remove others\' streams.');
return;
}

Expand All @@ -121,13 +121,13 @@ const commands = {
deleteStreamInObject(topic, id);

channelToDelete.delete().catch(err =>
message.channel.sendMessage('Sorry, could not delete channel'));
message.channel.send('Sorry, could not delete channel'));

message.channel.sendMessage(
message.channel.send(
`Removed ${user || message.author} from active streamers list and deleted #${channelToDelete.name}`);
} else {
// user has no stream in this topic
// return message.channel.sendMessage(`Could not find ${user}`);
// return message.channel.send(`Could not find ${user}`);
}
});
},
Expand All @@ -138,7 +138,7 @@ const commands = {
const topics = Object.keys(streams);

if (topics.length === 0) {
return message.channel.sendMessage('No streams! :frowning:');
return message.channel.send('No streams! :frowning:');
}

topics.forEach((topic) => {
Expand All @@ -151,19 +151,22 @@ const commands = {
});
});

return message.channel.sendMessage(buildMessage);
return message.channel.send(buildMessage);
},

removeall: function removeAllStreams(bot, message) {
if (message && !bot.isAdminOrMod(message.member)) {
message.channel.sendMessage('Only Admins or Mods can delete all stream channels');
message.channel.send('Only Admins or Mods can delete all stream channels');
return;
}

console.log('Removing all stream channels..');
bot.client.guilds.first().channels.filter(channel =>
channel && channel.name !== undefined && channel.name.startsWith('stream'))
.forEach(channel => channel.delete());

bot.client.guilds.array().forEach((guild) => {
guild.channels.filter(channel =>
channel && channel.name !== undefined && channel.name.startsWith('stream'))
.forEach(channel => channel.delete());
});

Object.keys(streams).forEach(topic => delete streams[topic]);
},
Expand All @@ -188,4 +191,3 @@ module.exports = {
commands.removeall(bot);
},
};

2 changes: 1 addition & 1 deletion commands/uptime/uptime.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const time = require('../../lib/utils.js').time;
module.exports = {
usage: 'uptime - prints my uptime',
run: (bot, message) => {
message.channel.sendMessage(
message.channel.send(
`Uptime: ${time.timeElapsed(bot.bootTime, new Date())}`);
},
};
14 changes: 7 additions & 7 deletions commands/vote/vote.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function processVote(type, bot, message, guild, member) {
if (!voting) {
// sets a timeout for this voting
const timeoutClj = () => {
message.channel.sendMessage(`Vote to ${type} ${member} has timed out. Phew!`);
message.channel.send(`Vote to ${type} ${member} has timed out. Phew!`);
delete currentVotes[type][member.user.username];
};
const timeoutObj = setTimeout(timeoutClj, bot.settings.voting.timeout_in_minutes * 1000 * 60);
Expand All @@ -62,13 +62,13 @@ function processVote(type, bot, message, guild, member) {
voting.votes.push(message.author.username);
if (voting.votes.length >= bot.settings.voting.voteThreshold) {
clearTimeout(voting.timeout);
message.channel.sendMessage(`Sorry, ${member}, but their wish is my command!`);
message.channel.send(`Sorry, ${member}, but their wish is my command!`);
voteTypes[type](bot, member, guild);
delete currentVotes[type][member.user.username];
} else {
let msg = `[${voting.votes.length}/${bot.settings.voting.voteThreshold}]`;
msg += ` votes to ${type} ${member}!`;
message.channel.sendMessage(msg);
message.channel.send(msg);
}
}

Expand All @@ -86,25 +86,25 @@ module.exports = {

const user = message.mentions.users.first();
if (!user) {
message.channel.sendMessage('You need to specify a valid member!');
message.channel.send('You need to specify a valid member!');
return false;
}
const member = guild.members.get(user.id);

// user validation
// warning: assume bot is in one guild only
if (user === message.author) {
message.channel.sendMessage('You can\'t start a vote against yourself, silly.');
message.channel.send('You can\'t start a vote against yourself, silly.');
return false;
} else if (user === bot.client.user) {
message.channel.sendMessage(`I'm sorry ${message.author}, I'm afraid I can't let you do that.,`);
message.channel.send(`I'm sorry ${message.author}, I'm afraid I can't let you do that.,`);
return false;
}

// roles validation
const userRoles = new Set(member.roles.array().map(r => r.name));
if (setIntersection(userRoles, new Set(bot.settings.voting.immuneRoles)).size > 0) {
message.channel.sendMessage('try.is(\'nice\') === true');
message.channel.send('try.is(\'nice\') === true');
return false;
}

Expand Down
5 changes: 2 additions & 3 deletions commands/weather/weather.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ function getWeatherData(location) {

const offset = weatherData.offset;
const utcTime = weatherData.currently.time;
// datetime is weird in javascript, please do change this part if you can
const localTime = new Date(utcTime * 1000);
localTime.setHours(localTime.getHours() + offset);
const localTime = new Date(1000 * (utcTime + (offset * 60 * 60)));

let dateString;
// toGMTString prints out timezone of host so we slice it off
if (offset > 0) {
Expand Down
4 changes: 2 additions & 2 deletions commands/xkcd/xkcd.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ module.exports = {
}

findXkcdFromKeywords(cmdArgs).then((data) => {
message.channel.sendMessage(data);
message.channel.send(data);
})
.catch((err) => {
message.channel.sendMessage(err);
message.channel.send(err);
});

return false;
Expand Down
Loading

0 comments on commit d6877a3

Please sign in to comment.