Skip to content

Commit

Permalink
Merge pull request #32 from twisterghost/v4.0.0
Browse files Browse the repository at this point in the history
V4.0.0
  • Loading branch information
twisterghost authored Jun 1, 2018
2 parents ad07ef7 + 8821542 commit 908bd9f
Show file tree
Hide file tree
Showing 21 changed files with 10,658 additions and 913 deletions.
27 changes: 6 additions & 21 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
module.exports = {
"env": {
"es6": true,
"node": true,
"mocha": true
env: {
mocha: true
},
"extends": "eslint:recommended",
"rules": {
"indent": [
"error",
2,
{"SwitchCase": 1}
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
],
"no-console": 0
}
extends: 'airbnb-base',
plugins: [
'import',
],
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ quoteslist
*.zip
coverage
helpfile
.nyc_output
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
language: node_js
node_js:
- "6.10.0"
before_install: npm install -g grunt-cli
- "8.9.1"
script: npm run ci
36 changes: 18 additions & 18 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
module.exports = function(grunt) {
const loadGruntTasks = require('load-grunt-tasks');

require('load-grunt-tasks')(grunt);
module.exports = function gruntConfig(grunt) {
loadGruntTasks(grunt);

grunt.initConfig({

compress: {
main: {
options: {
archive: 'jankbot.zip'
archive: 'jankbot.zip',
},
files: [
{src: ['jankbot.js']},
{src: ['README.md']},
{src: ['package.json']},
{src: ['dict/*']},
{src: ['core/*']},
{src: ['scripts/*']},
{src: ['lib/*']}
]
}
{ src: ['jankbot.js'] },
{ src: ['README.md'] },
{ src: ['package.json'] },
{ src: ['dict/*'] },
{ src: ['core/*'] },
{ src: ['scripts/*'] },
{ src: ['lib/*'] },
],
},
},

clean: {
all: [
'coverage',
'output.log',
'npm-debug.log',
'jankbot.zip'
]
}
'jankbot.zip',
],
},
});

grunt.registerTask('build', [
'jshint'
'jshint',
]);

grunt.registerTask('release', [
'compress'
'compress',
]);

};

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Jankbot
A Steam chat bot, built for Dota 2, made for everyone!

Current version: 3.3.1
Current version: 4.0.0

Maintained by [@twisterghost](http://twitter.com/twisterghost)

Expand Down Expand Up @@ -36,7 +36,7 @@ For a point by point walkthrough of the installation process, see the

*Please be sure you understand what you're doing if you use this summary!*

1. Install [NodeJS 6.10.* LTS](https://nodejs.org/en/download/)
1. Install [NodeJS 8.9.1 LTS](https://nodejs.org/en/download/)
2. Make a steam account with at least one purchase on it
3. Download Jankbot's [latest release](https://github.com/twisterghost/jankbot/releases)
4. Unzip it to a folder
Expand Down
105 changes: 53 additions & 52 deletions core/admin.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,19 @@
'use strict';

// Handler for admin functionality.
let minimap = require('minimap');
let friends = require('./friends.js');
let logger = require('./logger.js');
const minimap = require('minimap');
const _ = require('lodash');
const friends = require('./friends.js');
const logger = require('./logger.js');

let DICT;
let bot;
let shutdown;

exports.init = function(initBot, dictionary, killCommand) {
bot = initBot;
DICT = dictionary;
shutdown = killCommand;
};

exports.command = function(source, input, original) {

let command = input[1];
if (actions.hasOwnProperty(command)) {
actions[command](source, input, original);
return;
} else {
return;
}

};

let actions = {
quit: function() {
const actions = {
quit() {
shutdown();
},

dump: function(source, input) {
dump(source, input) {
if (input[2] === 'friends') {
logger.log(JSON.stringify(friends.getAllFriends()));
friends.messageUser(source, DICT.ADMIN.dump_friends);
Expand All @@ -41,28 +23,27 @@ let actions = {
}
},

lookup: function(source, input) {
let lookupList = friends.getAllFriends();
if (lookupList.hasOwnProperty(input[2])) {
let friend = lookupList[input[2]];
lookup(source, input) {
const lookupList = friends.getAllFriends();
if (lookupList[input[2]]) {
const friend = lookupList[input[2]];
friends.messageUser(source, JSON.stringify(friend, null, ' '));
} else {
friends.messageUser(source, DICT.ADMIN.lookup_error);
}
},

inactive: function(source) {
let ONE_WEEK = 60 * 60 * 24 * 7 * 1000;
let inactiveList = friends.getAllFriends();
let inactiveUsers = [];
for (let inactiveFriend in inactiveList) {

// If this user hasn't used this bot in a week, log it.
if (new Date(inactiveList[inactiveFriend].lastMessageTime).getTime() <
inactive(source) {
const ONE_WEEK = 60 * 60 * 24 * 7 * 1000;
const inactiveList = friends.getAllFriends();
const inactiveUsers = _.compact(_.map(inactiveList, (inactiveFriend, id) => {
if (new Date(inactiveFriend.lastMessageTime).getTime() <
(new Date().getTime() - ONE_WEEK)) {
inactiveUsers.push(inactiveList[inactiveFriend]);
return id;
}
}

return undefined;
}));

if (inactiveUsers.length === 0) {
friends.messageUser(source, DICT.ADMIN.no_inactive_users);
Expand All @@ -71,38 +52,58 @@ let actions = {
}
},

kick: function(source, input) {
let friendId = input[2];
kick(source, input) {
const friendId = input[2];
bot.removeFriend(input[2]);
friends.removeFriend(friendId, function(success) {
friends.removeFriend(friendId, (success) => {
if (success) {
friends.messageUser(source, minimap.map({id: friendId}, DICT.ADMIN.remove_friend_success));
friends.messageUser(
source,
minimap.map(
{ id: friendId },
DICT.ADMIN.remove_friend_success,
),
);
} else {
friends.messageUser(source, minimap.map({id: friendId}, DICT.ADMIN.remove_friend_error));
friends.messageUser(source, minimap.map({ id: friendId }, DICT.ADMIN.remove_friend_error));
}
});
},

blacklist: function(source, input) {
blacklist(source, input) {
friends.blacklist(input[2]);
friends.messageUser(source, DICT.ADMIN.blacklist_add);
},

unblacklist: function(source, input) {
unblacklist(source, input) {
friends.unBlacklist(input[2]);
friends.messageUser(source, DICT.ADMIN.blacklist_remove);
},

add: function(source, input) {
add(source, input) {
bot.addFriend(input[2]);
friends.addFriend(input[2]);
},

broadcast: function(source, input, original) {
let adminMessage = original.replace('admin broadcast', '');
logger.log(minimap.map({message: adminMessage}, DICT.ADMIN.broadcast_log));
broadcast(source, input, original) {
const adminMessage = original.replace('admin broadcast', '');
logger.log(minimap.map({ message: adminMessage }, DICT.ADMIN.broadcast_log));
friends.broadcast(source, adminMessage);
friends.messageUser(source, DICT.ADMIN.broadcast_sent);
}
},

};

exports.init = function init(initBot, dictionary, killCommand) {
bot = initBot;
DICT = dictionary;
shutdown = killCommand;
};

exports.command = function handleCommand(source, input, original) {
const command = input[1];
if (actions[command]) {
actions[command](source, input, original);
}
};

Loading

0 comments on commit 908bd9f

Please sign in to comment.