Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .bash_profile
Empty file.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.idea/
node_modules/
npm-debug.log
sh.exe.stackdump
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ language: node_js
node_js:
- '0.10'
script:
- npm run jsHint -- --failTaskOnError
- echo $BOT >> .env
before_install:
- export DISPLAY=:99.0
Expand All @@ -13,4 +12,5 @@ deploy:
provider: modulus
api_key: $MODULUS_TOKEN
project_name: miscord
on: CommandLogging
skip_cleanup: true
22 changes: 22 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch node debugging",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/main.js",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceRoot}",
"preLaunchTask": null,
"runtimeExecutable": null,
"runtimeArgs": ["--nolazy"],
"env": {"NODE_ENV": "development"},
"externalConsole": false,
"sourceMaps": false,
"outDir": null

}
]
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added audio/trump/bigchina.mp3
Binary file not shown.
Binary file added audio/trump/bomb.mp3
Binary file not shown.
Binary file added audio/trump/china_time.wav
Binary file not shown.
Binary file added audio/trump/daughter.wav
Binary file not shown.
Binary file added audio/trump/i_run_i_win.mp3
Binary file not shown.
Binary file added audio/trump/maga.wav
Binary file not shown.
Binary file added audio/trump/mexico_pays.wav
Binary file not shown.
Binary file added audio/trump/scent.mp3
Binary file not shown.
Binary file added audio/trump/you'll_get_bored_with_winning.wav
Binary file not shown.
8 changes: 8 additions & 0 deletions db/preference.db
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{"command":".gg","path":"./audio/random","volume":"1.2","type":"random","_id":"2ta04BGjEAAP87uA"}
{"command":".reddit","path":null,"volume":null,"type":"reddit","_id":"HTrt2ckQd1B9AXSB"}
{"command":".bag","path":"https://hydra-media.cursecdn.com/dota2.gamepedia.com/e/ee/Wdoc_inthebag_01.mp3","volume":".125","type":"audio","_id":"MFBVfW21GoidA8PF"}
{"command":".cheers","path":"https://my.mixtape.moe/dcvdxs.wav","volume":".5","type":"audio","_id":"O6h1K3ex3nGyGV2x"}
{"command":".gg","path":"./audio/gg.mp3","volume":".25","type":"audio","_id":"bA0ITBRJbRhN9o1P"}
{"command":".lion","path":"http://hydra-media.cursecdn.com/dota2.gamepedia.com/4/4a/Lion_respawn_01.mp3","volume":".25","type":"audio","_id":"bS3gYZIsgNNGSAnQ"}
{"command":".random","path":"./audio/gg.mp3","volume":".25","type":"random","_id":"ht33oaUuP5giHFVm"}
{"command":".trump","path":"./audio/trump","volume":"1.5","type":"random","_id":"ynyIK88s2rwLZ0cZ"}
20 changes: 20 additions & 0 deletions lib/Models/Commands/audioCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

var BaseCommand = require ('./baseCommand');
var playFile = require('./../../playFile');


class AudioCommand extends BaseCommand {

constructor(command, path, volume, bot) {
super(bot, command);
this.path = path;
this.volume = volume;
}

doWork(voiceChannel) {
playFile(this.bot, voiceChannel, this.volume, this.path);
}
}

module.exports = AudioCommand;
14 changes: 14 additions & 0 deletions lib/Models/Commands/baseCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

class BaseCommand {
constructor(bot, command) {
this.command = command;
this.bot = bot;
}

doWork() {
//implement in child classes
}
}

module.exports = BaseCommand;
41 changes: 41 additions & 0 deletions lib/Models/Commands/commandCollection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

var command = require('./baseCommand');

class CommandCollection {
constructor() {
this.Commands = [];
this.length = function(){
return this.Commands.length;
};
}

Add(command) {
if(this.Commands.indexOf(command) != -1) {
throw new Error("Command already exists in the collection");
}
this.Commands.push(command);
}


Remove(command) {
for(let i = 0; i < this.Commands.length; i ++ ) {
if(Commands[i] === command) {
Commands[i].Remove();
return;
}
throw new Error("Command not found in collection");
}
}

Find(query) {
for(let i = 0; i < this.Commands.length; i++) {
if(this.Commands[i].command === query) {
return this.Commands[i];
}
throw new Error("Command not found in collection");
}
}
}

module.exports = CommandCollection;
22 changes: 22 additions & 0 deletions lib/Models/Commands/randomAudioCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';
var playFile = require('./../../playFile');
var utils = require('./../../utils');

var BaseCommand = require ('./baseCommand');

class RandomAudioCommand extends BaseCommand {

constructor(command, path, volume, bot) {
super(bot, command);
this.path = path;
this.volume = volume;
this.fileOptions = utils.dirToArray(this.path);
}

doWork(voiceChannel) {
let chosenFile = this.fileOptions[utils.randomRange(this.fileOptions.length)]
playFile(this.bot, voiceChannel, this.volume, chosenFile);
}
}

module.exports = RandomAudioCommand;
40 changes: 40 additions & 0 deletions lib/Models/Commands/redditImageCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';

var parent = require ('./baseCommand');
var reddit = require('redwrap');
var LINQ = require('node-linq').LINQ;

class RedditImageCommand extends BaseCommand {
constructor(command) {
super(command);
}

doWork(channel, subreddit, msg) {
bot.reply(msg, 'gimme a sec...', function (error, message) {
if (error) {
throw error;
}
console.log(message);
});
var urlArray = [];
reddit.r(subreddit).limit(100, function (err, data) {
var parsedData = new LINQ(data.data.children)
.Where(function (file) {
if (file.data.url.includes('i.sli.mg') || file.data.url.includes('imgur.com')) {
return true;
}
return false;
})
.ToArray().forEach(function (item) {
urlArray.push([item.data.url, item.data.title]);
})
var image = urlArray[utils.randomRange(urlArray.length)];
bot.sendFile(channel, image[0], null, image[1], function (error, message) {
if (error) {
throw error;
}
console.log(message);
});
});
}
}
35 changes: 35 additions & 0 deletions lib/Models/Database/dbContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

var Datastore = require ('nedb');

class DbContext {
constructor(dbName) {
this.db = {};
this.dbPath = './db/' + dbName;
this.db = new Datastore(this.dbPath);
this.db.loadDatabase();
}

addEntry(document) {
this.db.insert(document, function(err) {
if(err) {
throw err;
}
});
}

getEntry(query) {
return new Promise(function (fulfill, reject) {
this.db.find(query, function (err, docs) {
if (err) {
reject(err);
}
else {
console.log('first' + docs);
fulfill(docs);
}
});
});
}
}
module.exports = DbContext;
24 changes: 24 additions & 0 deletions lib/Models/Services/commandService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

var dbContext = require('../Database/dbContext');
var commandCollection = require('../Commands/commandCollection');
class CommandService {
constructor(db, collection) {
this.db = db;
this.collection = collection;
}

populateCollection() {
return new Promise(function(resolve) {
resolve({
value: this.db.getEntry({type: 'audio'})
});
})
}

populateDatabase() {

}
}

module.exports = CommandService;
22 changes: 12 additions & 10 deletions lib/eventLogging.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var dateFormat = require('dateformat');
var historyChannel;

/**
* Records the activities of users joining and leaving voice channels based on the given parameters.
Expand All @@ -11,13 +12,13 @@ var dateFormat = require('dateformat');
* @param {Object} user the given user
*/
function history(event, bot, channel, user) {
if (event === 'leave') {
bot.sendMessage(channel.server.channels.get('name', 'history'), '**' + user.username + '**' + ' left **' + channel.name + '** at **' + dateFormat(new Date(), 'mmmm dS, yyyy, h:MM:ss TT Z') + '**');
if (event === 'leave' && user.bot === false) {
bot.sendMessage(channel.server.channels.get('name', 'history'), '**' + user.username + '**' + ' left **' + channel.name + '** at **' + dateFormat(new Date(), 'mmmm dS, yyyy, h:MM:ss TT Z') + '**\n');
}

if (event === 'join') {
bot.sendMessage(channel.server.channels.get('name', 'history'), '**' + user.username + '**' + ' joined **' + channel.name + '** at **' + dateFormat(new Date(), 'mmmm dS, yyyy, h:MM:ss TT Z') + '**');
}
if (event === 'join' && user.bot === false) {
bot.sendMessage(channel.server.channels.get('name', 'history'), '**' + user.username + '**' + ' joined **' + channel.name + '** at **' + dateFormat(new Date(), 'mmmm dS, yyyy, h:MM:ss TT Z') + '**\n');
}
}

/**
Expand All @@ -39,13 +40,13 @@ function presenceUpdated(oldUser, newUser, bot) {
} else {
statusVerb = 'come';
}
bot.sendMessage(historyChannel, '**' + newUser.username + '**' + ' has ' + statusVerb + ' **' + newUser.status + '** at **' + dateFormat(new Date(), 'mmmm dS, yyyy, h:MM:ss TT Z') + '**');
bot.sendMessage(historyChannel, '**' + newUser.username + '**' + ' has ' + statusVerb + ' **' + newUser.status + '** at **' + dateFormat(new Date(), 'mmmm dS, yyyy, h:MM:ss TT Z') + '**\n');
}
if (oldUser.game !== newUser.game) {
if (!newUser.game) {
bot.sendMessage(historyChannel, '**' + newUser.username + '**' + ' stopped playing **' + oldUser.game.name + '** at **' + dateFormat(new Date(), 'mmmm dS, yyyy, h:MM:ss TT Z') + '**');
bot.sendMessage(historyChannel, '**' + newUser.username + '**' + ' stopped playing **' + oldUser.game.name + '** at **' + dateFormat(new Date(), 'mmmm dS, yyyy, h:MM:ss TT Z') + '**\n');
} else {
bot.sendMessage(historyChannel, '**' + newUser.username + '**' + ' started playing **' + newUser.game.name + '** at **' + dateFormat(new Date(), 'mmmm dS, yyyy, h:MM:ss TT Z') + '**');
bot.sendMessage(historyChannel, '**' + newUser.username + '**' + ' started playing **' + newUser.game.name + '** at **' + dateFormat(new Date(), 'mmmm dS, yyyy, h:MM:ss TT Z') + '**\n');
}
}
}
Expand All @@ -54,6 +55,7 @@ function presenceUpdated(oldUser, newUser, bot) {
}

module.exports = {
history : history,
presenceUpdated : presenceUpdated
history: history,
presenceUpdated: presenceUpdated,
historyChannel: historyChannel
};
Loading