-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
138 lines (120 loc) · 4.49 KB
/
bot.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
'use strict';
let _ = require('lodash')
let config = require('./config.js').config
let fatalities = require('./fatalities.js')
let ge = require('./ge.js')
let irc = require('tmi.js')
let jokes = require('./jokes.js')
let options = require('./config.js').options
let rsapi = require('runescape-api')
let Humanize = require('humanize-plus')
let Promise = require('bluebird')
let skillList = {
overall: ['overall', 'oa'],
attack: ['attack', 'att'],
defence: ['defence', 'defense', 'def'],
strength: ['strength', 'str'],
hitpoints: ['constitution', 'hp', 'hitpoints'],
ranged: ['ranged', 'range'],
prayer: ['prayer', 'pray'],
magic: ['magic', 'mage'],
cooking: ['cooking', 'coking', 'cook', 'cok'],
woodcutting: ['woodcutting', 'wc', 'woodchop'],
fletching: ['fletching', 'fletch'],
fishing: ['fishing', 'fish'],
firemaking: ['firemaking', 'fm'],
crafting: ['crafting', 'craft'],
smithing: ['smithing', 'smith', 'best'],
mining: ['mining', 'mine'],
herblore: ['herblore', 'herb', 'herby'],
agility: ['agility', 'agil'],
thieving: ['thieving', 'thiev', 'thief', 'thiefing', 'theiving', 'theiv', 'theif', 'theifing'],
slayer: ['slayer', 'slay'],
farming: ['farming', 'farm'],
runecrafting: ['runecrafting', 'rc'],
hunter: ['hunter', 'hunt', 'hunting'],
construction: ['construction', 'const', 'constr', 'construct'],
summoning: ['summoning', 'summon', 'sum', 'summ'],
dungeoneering: ['dungeoneering', 'dungeon', 'dung', 'dg', 'loldg'],
divination: ['divination', 'div', 'divi', 'divine']
}
function randomJoke(){
return jokes[Math.floor(Math.random() * jokes.length-1)]
}
function randomDeath(){
return fatalities[Math.floor(Math.random() * jokes.length-1)]
}
function findAlias(string){
let result = ""
_.keys(skillList).map( (key) => {
if(skillList[key].indexOf(string) != -1){
result = key
}
})
return result
}
function simplifyString(string){
string = string.replace(/[\(\)\.\-\']/g, "")
string = string.replace(/&/g, "and")
return string
}
let client = new irc.client(options);
client.on('chat', function(channel, user, message, self){
function getGeNumber (message) {
let thing = message.split(" ").slice(1).join("")
thing = thing.replace(/\+/g, 'plus')
let parsedInt = parseInt(thing, 10)
if(Number.isInteger(parsedInt)){
thing = parsedInt
} else {
thing = ge[simplifyString(thing)]
}
return thing
}
message = message.toLowerCase()
switch(true){
case new RegExp(options.identity.username.toLowerCase()).test(user.username):
// ignore everything the bot says
break;
case /!commands/.test(message):
client.say(channel, "Supported commands: !help, !joke, !death, !skill <name>, !ge <name> or <id>")
break;
case /!dead/.test(message):
case /!death/.test(message):
case /!die/.test(message):
client.say(channel, randomDeath())
break;
case /!ge ([0-9]* | [a-z\ ]*)*/.test(message):
let check = getGeNumber(message)
rsapi.rs.ge.itemInformation(check)
.then((result) => {
let response = result.item.name + " ---- " + result.item.current.price + " gp [" + result.item.today.price + " gp]"
client.say(channel, response)
})
break;
case /!help/.test(message):
client.say(channel, "You're now breathing manually. You're now blinking manually. You're now aware of your tongue.")
break;
case /!joke/.test(message):
client.say(channel, randomJoke())
break;
case /!skill [a-z]*/.test(message):
let skillName = findAlias(message.split(" ")[1])
//check against list of skill names
rsapi.rs.hiscores.player(config.username).then( (apiStats) => {
let skillObject = apiStats.skills[skillName]
let resultString = config.username + "'s " + _.capitalize(skillName) + " ---- " +
"Level: " + skillObject.level + " ░ " +
"Exp: " + Humanize.intComma(skillObject.exp) + " ░ " +
"Rank: " + Humanize.intComma(skillObject.rank)
Promise.resolve(resultString).then( (res) => {
client.say(channel, resultString)
})
})
break;
case /!who/.test(message):
client.say(channel, "I'm watching stats for: "+config.username)
break;
}
})
client.connect();