-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.js
More file actions
77 lines (67 loc) · 2.33 KB
/
helper.js
File metadata and controls
77 lines (67 loc) · 2.33 KB
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
let instance = null
, sprintf = require(`sprintf-js`).sprintf
, moment = require(`moment`)
, config = require(`./config`)
, messages = require(`./messages`)
, Adapter = require(`./adapter`).Adapter
, Tool = require(`./tool`).Tool
;
class BotHelper {
constructor() {
}
static instance() {
if (null === instance) {
instance = new BotHelper();
}
return instance;
}
updateStatus(bot) {
bot.user.setActivity(`Say ??help`, { type: `WATCHING` });
}
handleCommand(command, params, message) {
switch (command) {
case `help`:
case `info`:
this.handleHelpCommand(message);
break;
case `account_info`:
this.handleAccountInfoCommand(params, message);
break;
default:
console.info(sprintf(`Unsupported "%s" command received.`, command));
}
}
handleHelpCommand(message) {
message.channel.send(sprintf(messages.info, message.author.id, config.commandPrefix))
}
handleAccountInfoCommand(params, message) {
if (params.length < 1) {
console.error(`Don't receive account username...`);
return;
}
Adapter.instance().processAccountDetails(
params[0],
(account, gp) => {
message.channel.send(sprintf(
messages.accountInfo,
message.author.id,
account.name,
Tool.calculateAccountReputation(account),
Tool.calculateAccountFullPower(account, gp),
Tool.calculateAccountOwnPower(account, gp),
Tool.calculateAccountReceivedPower(account, gp),
Tool.calculateAccountDelegatedPower(account, gp),
Tool.calculateAccountVotingPower(account),
account.last_vote_time,
Tool.formatBalance(account.balance),
Tool.formatBalance(account.sbd_balance),
moment(account.created).fromNow(true)
))
},
() => {
message.channel.send(sprintf(messages.accountNotFound, message.author.id))
}
);
}
}
module.exports.BotHelper = BotHelper;