-
Notifications
You must be signed in to change notification settings - Fork 83
/
RoomMessages.js
103 lines (85 loc) · 3.06 KB
/
RoomMessages.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"use strict";
// the users input is scanned for these keywords
// and can trigger the messages below
// chance controls the frequency the result will be echoed back by the camper
// using js rather than json so we can have functions and comments
var Utils = require('../../lib/utils/Utils');
var BotCommands = require('../../lib/bot/BotCommands');
var _ = require('lodash-node');
// TODO - add these to all of the rooms
// this is easier for people to add content to as they don't have to add to two lists
var AllRoomMessages = [
{
// regex: /help.*bonfire:?s?[.?]$/i,
regex: /.*help.*bonfire:?s?/i,
text: " > type `bonfire name` to get some info on that bonfire. And check [HelpBonfires chatroom](https://gitter.im/FreeCodeCamp/HelpBonfires)",
not: 'freecodecamp/HelpBonfires' // optional to skip for this room
},
{
regex: /botx/i,
text: "> you called?"
},
{
regex: /\btroll\b/i,
text: "> :trollface: troll problems? [notify admins here](https://gitter.im/camperbot/admins)"
},
{
regex: /allyourbase/,
text: "![all your base](https://files.gitter.im/FreeCodeCamp/CoreTeam/Bw51/imgres.jpg)"
},
{
regex: /'''/,
text: "> :bulb: to format code use backticks! ``` [more info](https://github.com/freecodecamp/freecodecamp/wiki/code-formatting)"
},
{
regex: /holler/i,
text: "> holler back!",
chance: 1 // only say this 50% of the time
},
{
regex: /\bth?a?n?[xk]s?q?\b/gim,
func: BotCommands.thanks
}
];
var RoomMessages = {
scanInput: function(input, roomName, chance) {
if (Math.random() > chance) {
return null; // dont always reply
}
var oneMessage;
var chat = input.message.model.text.toLowerCase();
chance = chance || 1;
roomName = roomName.toLowerCase();
// some messages are only for certain rooms so exclude them here
var thisRoomMessages = AllRoomMessages.filter(function(msg) {
if (msg.not) {
return (msg.not != roomName);
} else {
return true;
}
});
if (!thisRoomMessages) { return false; }
var msgList = thisRoomMessages.filter(function(item) {
if(!item) { return null; }
if (item.regex) {
var flag = item.regex.test(chat);
}
if(flag) {
//Utils.clog(chat, item.word, "flag:" + flag);
}
return flag;
});
// now check if chance is high enough
if (msgList.length > 0) {
oneMessage = _.sample(msgList); // if we have multiple messages, make sure to choose just one
chance = oneMessage.chance || 1; // check if the chance is high enough so we can have % of time messages
if (Math.random() < (chance)) {
// we have a winner!
return oneMessage;
}
} else {
return null;
}
}
};
module.exports = RoomMessages;