Skip to content

Commit

Permalink
(1.2.0) Error handling
Browse files Browse the repository at this point in the history
Added error handling for exec command, should prevent most crashes. Crashes from other commands should be fixed through code.

Also added semicolons for consistency
  • Loading branch information
cyckl committed Apr 12, 2020
1 parent b1c80d5 commit e6fea3c
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
// Call in dependencies / set up global variables
const { Client, MessageEmbed } = require('discord.js');
const client = new Client();
const version = '1.1.9';
const version = '1.2.0';
var token = process.argv[2];

// Bootup sequence
client.on('ready', () => {
console.log('╔════════════════════════════════════╗')
console.log('║ ║')
console.log('║ Tweeter by cyckl ║')
console.log('║ Running version ' + version + ' ║')
console.log('║ RIP 3-inch-largest ║')
console.log('║ ║')
console.log('╚════════════════════════════════════╝\n')
console.log('╔════════════════════════════════════╗');
console.log('║ ║');
console.log('║ Tweeter by cyckl ║');
console.log('║ Running version ' + version + ' ║');
console.log('║ RIP 3-inch-largest ║');
console.log('║ ║');
console.log('╚════════════════════════════════════╝\n');
client.user.setActivity('.t msg');
});

Expand All @@ -33,20 +33,16 @@ function getRandomInt(x) {
// Commands
function tweet(message) {
// Handles removing nickname if no nickname
if (message.member.nickname == null) {
var tweetUserString = message.author.username
}
else {
var tweetUserString = message.member.nickname + ' (@' + message.author.username + ')'
}
if (message.member.nickname == null) tweetUserString = message.author.username;
else tweetUserString = message.member.nickname + ' (@' + message.author.username + ')';

var content = message.content.replace('.t ', '')
var content = message.content.replace('.t ', '');
var embed = new MessageEmbed()
.setAuthor(tweetUserString, message.author.displayAvatarURL(), 'https://www.youtube.com/watch?v=dQw4w9WgXcQ')
.setColor(0x1DA1F2)
.setDescription(content)
.addField('Retweets', getRandomInt(10000), true)
.addField('Likes', getRandomInt(5000000), true)
.addField('Retweets', getRandomInt(50000), true)
.addField('Likes', getRandomInt(1000000), true)
.setFooter('Twitter', 'https://abs.twimg.com/icons/apple-touch-icon-192x192.png');
// Send tweet and log
message.channel.send(embed);
Expand All @@ -56,13 +52,22 @@ function tweet(message) {
function exec(message) {
// User ID hardcode
if (message.author.id != '248948821881520138' && message.author.id != '249052912762880000') return;
var runCode = message.content.replace('.run ', '');
var result = '';
result = eval(runCode);
// Send result and log
message.channel.send('**Result:** ```js\n' + result + '```');
console.log('[Exec] (' + message.author.tag + ') ' + runCode);
console.log('[Exec Result] ' + result);

// Try code, if broken, move to catch()
try {
var runCode = message.content.replace('.run ', '');
var result = eval(runCode);
// Send result and log
message.channel.send('**Result:** ```js\n' + result + '```');
console.log('[Exec] (' + message.author.tag + ') ' + runCode);
console.log('[Exec Result] ' + result);
}

// If error, handle it instead of crashing.
catch (e) {
console.log('[Exec Error] ' + e);
message.channel.send('**Error:** ```js\n' + e + '```');
}
}

function about(message) {
Expand All @@ -74,7 +79,7 @@ function about(message) {
.addField('Version', version, true)
.addField('Build date', '2020-04-11', true)
.setFooter('This is alpha software. Please be patient!')
.setThumbnail('https://github.com/cyckl/tweeter/raw/master/img/tweeter.png')
.setThumbnail('https://github.com/cyckl/tweeter/raw/master/img/tweeter.png');
// Send tweet and log
message.channel.send(embed);
console.log('[About] (' + message.author.tag + ') ' + 'About dialogue triggered.');
Expand Down

0 comments on commit e6fea3c

Please sign in to comment.