Skip to content

Commit 908bd9f

Browse files
authored
Merge pull request #32 from twisterghost/v4.0.0
V4.0.0
2 parents ad07ef7 + 8821542 commit 908bd9f

21 files changed

+10658
-913
lines changed

.eslintrc.js

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,9 @@
11
module.exports = {
2-
"env": {
3-
"es6": true,
4-
"node": true,
5-
"mocha": true
2+
env: {
3+
mocha: true
64
},
7-
"extends": "eslint:recommended",
8-
"rules": {
9-
"indent": [
10-
"error",
11-
2,
12-
{"SwitchCase": 1}
13-
],
14-
"quotes": [
15-
"error",
16-
"single"
17-
],
18-
"semi": [
19-
"error",
20-
"always"
21-
],
22-
"no-console": 0
23-
}
5+
extends: 'airbnb-base',
6+
plugins: [
7+
'import',
8+
],
249
};

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ quoteslist
1111
*.zip
1212
coverage
1313
helpfile
14+
.nyc_output

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
language: node_js
22
node_js:
3-
- "6.10.0"
4-
before_install: npm install -g grunt-cli
3+
- "8.9.1"
54
script: npm run ci

Gruntfile.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
module.exports = function(grunt) {
1+
const loadGruntTasks = require('load-grunt-tasks');
22

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

56
grunt.initConfig({
67

78
compress: {
89
main: {
910
options: {
10-
archive: 'jankbot.zip'
11+
archive: 'jankbot.zip',
1112
},
1213
files: [
13-
{src: ['jankbot.js']},
14-
{src: ['README.md']},
15-
{src: ['package.json']},
16-
{src: ['dict/*']},
17-
{src: ['core/*']},
18-
{src: ['scripts/*']},
19-
{src: ['lib/*']}
20-
]
21-
}
14+
{ src: ['jankbot.js'] },
15+
{ src: ['README.md'] },
16+
{ src: ['package.json'] },
17+
{ src: ['dict/*'] },
18+
{ src: ['core/*'] },
19+
{ src: ['scripts/*'] },
20+
{ src: ['lib/*'] },
21+
],
22+
},
2223
},
2324

2425
clean: {
2526
all: [
2627
'coverage',
2728
'output.log',
2829
'npm-debug.log',
29-
'jankbot.zip'
30-
]
31-
}
30+
'jankbot.zip',
31+
],
32+
},
3233
});
3334

3435
grunt.registerTask('build', [
35-
'jshint'
36+
'jshint',
3637
]);
3738

3839
grunt.registerTask('release', [
39-
'compress'
40+
'compress',
4041
]);
41-
4242
};
4343

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Jankbot
22
A Steam chat bot, built for Dota 2, made for everyone!
33

4-
Current version: 3.3.1
4+
Current version: 4.0.0
55

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

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

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

39-
1. Install [NodeJS 6.10.* LTS](https://nodejs.org/en/download/)
39+
1. Install [NodeJS 8.9.1 LTS](https://nodejs.org/en/download/)
4040
2. Make a steam account with at least one purchase on it
4141
3. Download Jankbot's [latest release](https://github.com/twisterghost/jankbot/releases)
4242
4. Unzip it to a folder

core/admin.js

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,19 @@
1-
'use strict';
2-
31
// Handler for admin functionality.
4-
let minimap = require('minimap');
5-
let friends = require('./friends.js');
6-
let logger = require('./logger.js');
2+
const minimap = require('minimap');
3+
const _ = require('lodash');
4+
const friends = require('./friends.js');
5+
const logger = require('./logger.js');
6+
77
let DICT;
88
let bot;
99
let shutdown;
1010

11-
exports.init = function(initBot, dictionary, killCommand) {
12-
bot = initBot;
13-
DICT = dictionary;
14-
shutdown = killCommand;
15-
};
16-
17-
exports.command = function(source, input, original) {
18-
19-
let command = input[1];
20-
if (actions.hasOwnProperty(command)) {
21-
actions[command](source, input, original);
22-
return;
23-
} else {
24-
return;
25-
}
26-
27-
};
28-
29-
let actions = {
30-
quit: function() {
11+
const actions = {
12+
quit() {
3113
shutdown();
3214
},
3315

34-
dump: function(source, input) {
16+
dump(source, input) {
3517
if (input[2] === 'friends') {
3618
logger.log(JSON.stringify(friends.getAllFriends()));
3719
friends.messageUser(source, DICT.ADMIN.dump_friends);
@@ -41,28 +23,27 @@ let actions = {
4123
}
4224
},
4325

44-
lookup: function(source, input) {
45-
let lookupList = friends.getAllFriends();
46-
if (lookupList.hasOwnProperty(input[2])) {
47-
let friend = lookupList[input[2]];
26+
lookup(source, input) {
27+
const lookupList = friends.getAllFriends();
28+
if (lookupList[input[2]]) {
29+
const friend = lookupList[input[2]];
4830
friends.messageUser(source, JSON.stringify(friend, null, ' '));
4931
} else {
5032
friends.messageUser(source, DICT.ADMIN.lookup_error);
5133
}
5234
},
5335

54-
inactive: function(source) {
55-
let ONE_WEEK = 60 * 60 * 24 * 7 * 1000;
56-
let inactiveList = friends.getAllFriends();
57-
let inactiveUsers = [];
58-
for (let inactiveFriend in inactiveList) {
59-
60-
// If this user hasn't used this bot in a week, log it.
61-
if (new Date(inactiveList[inactiveFriend].lastMessageTime).getTime() <
36+
inactive(source) {
37+
const ONE_WEEK = 60 * 60 * 24 * 7 * 1000;
38+
const inactiveList = friends.getAllFriends();
39+
const inactiveUsers = _.compact(_.map(inactiveList, (inactiveFriend, id) => {
40+
if (new Date(inactiveFriend.lastMessageTime).getTime() <
6241
(new Date().getTime() - ONE_WEEK)) {
63-
inactiveUsers.push(inactiveList[inactiveFriend]);
42+
return id;
6443
}
65-
}
44+
45+
return undefined;
46+
}));
6647

6748
if (inactiveUsers.length === 0) {
6849
friends.messageUser(source, DICT.ADMIN.no_inactive_users);
@@ -71,38 +52,58 @@ let actions = {
7152
}
7253
},
7354

74-
kick: function(source, input) {
75-
let friendId = input[2];
55+
kick(source, input) {
56+
const friendId = input[2];
7657
bot.removeFriend(input[2]);
77-
friends.removeFriend(friendId, function(success) {
58+
friends.removeFriend(friendId, (success) => {
7859
if (success) {
79-
friends.messageUser(source, minimap.map({id: friendId}, DICT.ADMIN.remove_friend_success));
60+
friends.messageUser(
61+
source,
62+
minimap.map(
63+
{ id: friendId },
64+
DICT.ADMIN.remove_friend_success,
65+
),
66+
);
8067
} else {
81-
friends.messageUser(source, minimap.map({id: friendId}, DICT.ADMIN.remove_friend_error));
68+
friends.messageUser(source, minimap.map({ id: friendId }, DICT.ADMIN.remove_friend_error));
8269
}
8370
});
8471
},
8572

86-
blacklist: function(source, input) {
73+
blacklist(source, input) {
8774
friends.blacklist(input[2]);
8875
friends.messageUser(source, DICT.ADMIN.blacklist_add);
8976
},
9077

91-
unblacklist: function(source, input) {
78+
unblacklist(source, input) {
9279
friends.unBlacklist(input[2]);
9380
friends.messageUser(source, DICT.ADMIN.blacklist_remove);
9481
},
9582

96-
add: function(source, input) {
83+
add(source, input) {
9784
bot.addFriend(input[2]);
9885
friends.addFriend(input[2]);
9986
},
10087

101-
broadcast: function(source, input, original) {
102-
let adminMessage = original.replace('admin broadcast', '');
103-
logger.log(minimap.map({message: adminMessage}, DICT.ADMIN.broadcast_log));
88+
broadcast(source, input, original) {
89+
const adminMessage = original.replace('admin broadcast', '');
90+
logger.log(minimap.map({ message: adminMessage }, DICT.ADMIN.broadcast_log));
10491
friends.broadcast(source, adminMessage);
10592
friends.messageUser(source, DICT.ADMIN.broadcast_sent);
106-
}
93+
},
94+
95+
};
96+
97+
exports.init = function init(initBot, dictionary, killCommand) {
98+
bot = initBot;
99+
DICT = dictionary;
100+
shutdown = killCommand;
101+
};
107102

103+
exports.command = function handleCommand(source, input, original) {
104+
const command = input[1];
105+
if (actions[command]) {
106+
actions[command](source, input, original);
107+
}
108108
};
109+

0 commit comments

Comments
 (0)