Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into 1.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
4lch4 committed Jul 24, 2018
2 parents 47862e1 + 36566dd commit 2eaf6f9
Show file tree
Hide file tree
Showing 1,804 changed files with 4,501 additions and 4,520 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ logs/
data/coverage/

util/Jest_Cheatsheet\.md

images/
8 changes: 8 additions & 0 deletions .snyk
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,11 @@ patch:
'npm:request:20160119':
- redwrap > request:
patched: '2018-05-08T09:56:44.120Z'
'npm:lodash:20180130':
- json2csv > cli-table2 > lodash:
patched: '2018-07-02T22:10:57.075Z'
'npm:mime:20170907':
- redwrap > request > mime:
patched: '2018-07-16T15:41:27.226Z'
- redwrap > request > form-data > mime:
patched: '2018-07-16T15:41:27.226Z'
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
language: node_js
node_js:
- "9.6.1"
install:
- npm install -g codecov
- npm install -g jest
- npm install
script:
- jest --config ./util/jest.config.js && codecov
before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq libgif-dev
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

[![ForTheBadge](https://forthebadge.com/images/badges/fuck-it-ship-it.svg)](https://forthebadge.com)

[![Greenkeeper badge](https://badges.greenkeeper.io/HF-Solutions/Tron.svg)](https://greenkeeper.io/)

# Tron

## Purpose
Expand All @@ -31,4 +33,5 @@ before cloning the repo, running `npm i -y; npm start`, and hoping for the best:
1. If on Windows, refer to [this guide](https://github.com/Automattic/node-canvas/wiki/Installation---Windows) available on the [node-canvas](https://github.com/Automattic/node-canvas) repo, before installing all of the dependencies.

1. After completing the above, attempt to run `npm i` and if it installs everything successfully, try `npm start`, which will run Tron in the development/beta environment.
- If you want to run the production version, simply use `npm run start-prod`.
- If you want to run the production version, simply use `npm run start-prod`.

43 changes: 18 additions & 25 deletions Tron.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const tools = new (require('./util/Tools'))()
const CommandHelper = require('./util/db/CommandHelper')

const config = require('./util/config.json')
const logger = new (require('./util/logger'))()

const Raven = require('raven')
Raven.config(config.ravenUrl).install()
const timber = require('timber')
const transport = new timber.transports.HTTPS(process.env.TIMBER_KEY)
timber.install(transport)

const client = new CommandoClient({
commandPrefix: process.env.CMD_PREFIX,
Expand Down Expand Up @@ -56,60 +56,53 @@ client.on('ready', () => {
let random = tools.getRandom(0, activities.length)
let activity = activities[random]

logger.log(`Updating activity to ${activity}`, false)
console.log(`Updating activity to ${activity}`, false)

client.user.setActivity(activity)
}, 120000)

logger.log(`Tron has come online > ${readyTime}`)
console.log(`Tron ${process.env.NODE_ENV.toUpperCase()} has come online > ${readyTime}`)
})

/* client.on('message', msg => {
if (msg.mentions.users.get(client.user.id) !== undefined &&
!msg.content.startsWith(client.commandPrefix)) {
// logger.log(`Tron mentioned.`) For future integration into cleverbot or something similar
}
}) */

client.on('commandRun', (cmd, promise, msg) => {
logger.log(`Running ${cmd.name}...`)
console.log(`Running ${cmd.name}...`)
const command = new CommandHelper(msg, cmd)

command.updateUsage(cmd.name).catch(err => logger.error(err))
command.updateUsage(cmd.name).catch(err => console.error(err))
})

client.on('warn', info => {
logger.log('warn info = ...')
logger.log(info)
console.log('warn info = ...')
console.log(info)
})

client.on('commandBlocked', (msg, str) => {
logger.log('Command Blocked...')
logger.log(msg)
console.log('Command Blocked...')
console.log(msg)
})

client.on('unknownCommand', msg => {
if (msg.channel.id !== config.testChannel) { // Default testing channel, don't respond.
let query = msg.content.substring(client.commandPrefix.length)
tools.queryGiphy(query, client.user.username, client.user.displayAvatarURL())
.then(res => { if (res !== null) msg.channel.send(res) })
.catch(err => logger.error(err))
.catch(err => console.error(err))
}
})

client.on('commandError', (cmd, err) => logger.error(err))
client.on('commandError', (cmd, err) => console.error(err))

client.on('error', err => logger.error(err))
client.on('error', err => console.error(err))

let zenCount = 0

client.on('message', msg => {
if (msg.mentions.users.get(client.user.id) !== undefined) {
logger.log('Tron mentioned.')
logger.log(msg.content)
console.log('Tron mentioned.')
console.log(msg.content)
} else if (msg.content.startsWith(client.commandPrefix)) {
logger.log(`Command used.`)
logger.log(msg.content)
console.log(`Command used.`)
console.log(msg.content)
}

if (msg.author.id === '150319175326236672') {
Expand Down
42 changes: 42 additions & 0 deletions __tests__/IOTools.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const ioTools = new (require('../util/IOTools'))()
const path = require('path')

describe('The getImagePath(path) method works as expected.', () => {
it('should return a path to the correct directory and file.', () => {
expect(ioTools.getImagePath(path.join('alcha', 'Jerry-1.gif'))).toEqual(path.join('images', 'alcha', 'Jerry-1.gif'))
expect(ioTools.getImagePath('null')).toBe('Invalid file path provided.')
expect(ioTools.getImagePath('undefined')).toHaveLength(27)
})

it('should return a message if the file is too large.', () => {
expect(ioTools.getImagePath(path.join('test', 'LargeFile.png'))).toEqual('Provided file is too large to send over Discord.')
})

it('should return an error message if an invalid file path is provided.', () => {
expect(ioTools.getImagePath(path.join('test', 'asdfk.xml'))).toEqual('Invalid file path provided.')
})
})

describe('The saveToFile(data, filename) method works as expected.', () => {
it('should return the path and name of the saved file.', () => {
return ioTools.saveToFile('TestData', 'test.log').then(res => {
expect(res).toBe(path.join('data', 'filesSaved', 'test.log'))
})
})

it('Should do return an error when the filename is anything other than a String.', async () => {
try {
const r = await ioTools.saveToFile('FileData', null)
} catch (err) {
expect(err.message).toBe("The \"path\" argument must be of type string")
}
})

it('Should throw an error when null is passed as the file data.', async () => {
try {
const r = await ioTools.saveToFile(null, null)
} catch (err) {
expect(err.message).toBe("Test")
}
})
})
75 changes: 75 additions & 0 deletions __tests__/Tools.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const { Client } = require('discord.js')
const Tools = require('../util/Tools')
const tools = new Tools()

const testDateFormat = 'MM_YYYY_DD.HH:mm:ss'
const formatTimeRegex = /[0-2]?[0-9]_\d{4}_[0-9]{2}.[0-2][0-9]:[0-6][0-9]:[0-6][0-9]/

describe('Unit testing of the Tools.js class and it\'s functions.', () => {
test('The formatTime(format) function returns a properly formatted time.', () => {
expect(tools.formatTime(testDateFormat)).toEqual(expect.stringMatching(formatTimeRegex))
})

test('The shortLogDate property getter returns a proper short date for logging.', () => {
let logDate = tools.shortLogDate

expect(logDate).toMatch(/\d{4}-[0-1][0-9]-[0-2][0-9]/)
expect(logDate).toHaveLength(10)
})

test('The shortUTCTime property getter returns a properly formatted UTC time.', () => {
let utcTime = tools.shortUTCTime // moment.tz(UTC).format('HH:mm:ss.SS')

expect(utcTime).toMatch(/[0-2][0-9]:[0-6][0-9]:[0-6][0-9].[0-9][0-9]/);
expect(utcTime).toHaveLength(11)
})

test('The formattedTime property getter returns a properly formatted date.', () => {
expect(tools.formattedTime).toMatch(/[0-2]?.[0-9]{2}.\d{4} @ [0-2][0-9]:[0-6][0-9]:[0-6][0-9]/)
})

test('The utcTime property getter returns the correct UTC time.', () => {
let toolTime = tools.utcTime
let nodeTime = new Date().toISOString()
let toolTimeStr = toolTime.substring(0, toolTime.indexOf('Z'))
let nodeTimeStr = nodeTime.substring(0, nodeTime.indexOf('.'))

expect(toolTimeStr).toMatch(nodeTimeStr)
})

test('The formattedUTCTime getter returns a properly formatted UTC time.', () => {
expect(tools.formattedUTCTime).toMatch(/[0-1][0-9].[0-9]{2}.\d{4} @ [0-2][0-9]:[0-6][0-9]:[0-6][0-9]/)
})

test('The safeFormattedTime getter returns a safely formatted time.', () => {
expect(tools.safeFormattedTime).toMatch(/[0-1][0-9].[0-9]{2}.\d{4}_[0-2][0-9]:[0-6][0-9]:[0-6][0-9]/)
})

test('The upperFirstC funcion capitalizes the first letter of the given string.', () => {
expect(tools.upperFirstC("apollo")).toBe("Apollo")
});

test('The numberWithCommas function converts a number larger than 1,000 to contain commas.', () => {
expect(tools.numberWithCommas(999888777666555)).toBe("999,888,777,666,555")
})

test('The getRandom(min, max) function gets a random number in the correct range.', () => {
let random = tools.getRandom(0, 100)
expect(random).toBeGreaterThanOrEqual(0)
expect(random).toBeLessThan(100)
})

// tools#formatUnixInput

test('The formatUnixInput(timestamp) function properly formats a unix timestamp.', () => {
let utcTime = new Date().toUTCString()
expect(tools.formatUnixInput(utcTime)).toMatch(/[0-1][0-9]\/[0-2][0-9]\/[0-9]{4} [0-2][0-9]:[0-5][0-9]:[0-5][0-9]/)
expect(tools.formatUnixInput(utcTime)).toHaveLength(19)
})

// tools#formatUTCTime

// tools#pickImage

//tools.sendOwnerMessage("Haaiii", new Client())
})
1 change: 0 additions & 1 deletion cmds/actions/Bite.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = class Bite extends Command {
group: 'actions',
memberName: 'bite',
guildOnly: true,
throttling: { usages: 1, duration: 10 },
aliases: ['bites', 'nom', 'noms', 'nomnom', 'omnom'],
description: 'Returns a random bite gif and includes the mentioned users username.',
examples: ['+bite @Alcha#2625', '+nom', '+noms @Alcha#2625'],
Expand Down
1 change: 0 additions & 1 deletion cmds/actions/Hugs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module.exports = class Hug extends Command {
memberName: 'hug',
guildOnly: true,
aliases: ['hugs', 'cuddle', 'cuddles'],
throttling: { usages: 1, duration: 10 },
description: 'Returns a random love gif and if a user is mentioned, includes their name.',
examples: ['+hugs @Alcha#2625'],
argsType: 'multiple'
Expand Down
1 change: 0 additions & 1 deletion cmds/actions/Kick.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = class Kick extends Command {
group: 'actions',
memberName: 'kick',
guildOnly: true,
throttling: { usages: 1, duration: 10 },
description: 'Returns a random kick gif and includes the mentioned users username.',
examples: ['+kick @Alcha#2625'],
argsType: 'multiple'
Expand Down
1 change: 0 additions & 1 deletion cmds/actions/Kill.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = class Kill extends Command {
group: 'actions',
memberName: 'kill',
guildOnly: true,
throttling: { usages: 1, duration: 10 },
description: 'Returns a random kill gif and includes the mentioned users username.',
examples: ['+kill @Alcha#2625'],
argsType: 'multiple'
Expand Down
1 change: 0 additions & 1 deletion cmds/actions/Kiss.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = class Kiss extends Command {
group: 'actions',
memberName: 'kiss',
guildOnly: true,
throttling: { usages: 1, duration: 10 },
description: 'Returns a random kiss gif and includes the mentioned users username.',
examples: ['+kiss @Alcha#2625'],
argsType: 'multiple'
Expand Down
1 change: 0 additions & 1 deletion cmds/actions/Lick.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = class Lick extends Command {
group: 'actions',
memberName: 'lick',
guildOnly: true,
throttling: { usages: 1, duration: 10 },
description: 'Returns a random lick gif and includes the mentioned users username.',
examples: ['+lick @Alcha#2625'],
argsType: 'multiple'
Expand Down
1 change: 0 additions & 1 deletion cmds/actions/Love.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = class Love extends Command {
group: 'actions',
memberName: 'love',
guildOnly: true,
throttling: { usages: 1, duration: 10 },
description: 'Returns a random love gif and if a user is mentioned, includes their name.',
examples: ['+love @Alcha#2625'],
argsType: 'multiple'
Expand Down
1 change: 0 additions & 1 deletion cmds/actions/NoBulli.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = class NoBulli extends Command {
group: 'actions',
memberName: 'nobulli',
guildOnly: true,
throttling: { usages: 1, duration: 10 },
description: 'Warns @User1 not to bully @User2.',
examples: ['+nobulli @User1 @User2'],
args: [{
Expand Down
1 change: 0 additions & 1 deletion cmds/actions/Pat.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = class Pat extends Command {
group: 'actions',
memberName: 'pat',
guildOnly: true,
throttling: { usages: 1, duration: 10 },
description: 'Returns a random pat gif and includes the mentioned users username.',
examples: ['+pat @Alcha#2625'],
argsType: 'multiple'
Expand Down
1 change: 0 additions & 1 deletion cmds/actions/Poke.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = class Poke extends Command {
group: 'actions',
memberName: 'poke',
guildOnly: true,
throttling: { usages: 1, duration: 10 },
description: 'Returns a random poke gif and includes the mentioned users username.',
examples: ['+poke @Alcha#2625'],
argsType: 'multiple'
Expand Down
1 change: 0 additions & 1 deletion cmds/actions/Punch.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = class Punch extends Command {
group: 'actions',
memberName: 'punch',
guildOnly: true,
throttling: { usages: 1, duration: 10 },
description: 'Returns a random punch gif and includes the mentioned users username.',
examples: ['+punch @Alcha#2625'],
argsType: 'multiple'
Expand Down
28 changes: 28 additions & 0 deletions cmds/actions/Shank.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const Command = require('../BaseCmd')
const IOTools = require('../../util/IOTools')
const ioTools = new IOTools()

module.exports = class Shank extends Command {
constructor (client) {
super(client, {
name: 'shank',
group: 'actions',
memberName: 'shank',
guildOnly: false,
aliases: ['stab', 'shanks'],
description: 'Returns a random shank gif and includes the mentions users username.',
examples: ['+shank @Alcha#2625'],
argsType: 'multiple'
})
}

async run (msg, args) {
if (msg.mentions.users.size > 0) {
var content = `${this.getMentionedUsernames(msg)}, you've been shanked by **${msg.author.username}**! :knife:`
}

ioTools.getRandomImage('shank', args).then(image => {
msg.channel.send(content, { files: [image] })
}).catch(err => console.error(err))
}
}
1 change: 0 additions & 1 deletion cmds/actions/Slap.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = class Slap extends Command {
group: 'actions',
memberName: 'slap',
guildOnly: true,
throttling: { usages: 1, duration: 10 },
description: 'Returns a random slap gif and includes the mentioned users username.',
examples: ['+slap @Alcha#2625'],
argsType: 'multiple'
Expand Down
1 change: 0 additions & 1 deletion cmds/actions/Spank.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = class Spank extends Command {
group: 'actions',
memberName: 'spank',
guildOnly: true,
throttling: { usages: 1, duration: 10 },
description: 'Returns a random spank gif and includes the mentioned users username.',
examples: ['+spank @Alcha#2625'],
argsType: 'multiple'
Expand Down
1 change: 0 additions & 1 deletion cmds/actions/Wave.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = class Wave extends Command {
group: 'actions',
memberName: 'wave',
guildOnly: true,
throttling: { usages: 1, duration: 10 },
description: 'Returns a random wave gif and if a user is mentioned, includes their username.',
examples: ['+wave @Alcha#2625'],
argsType: 'multiple'
Expand Down
Loading

0 comments on commit 2eaf6f9

Please sign in to comment.