-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot-helper.js
More file actions
66 lines (59 loc) · 1.9 KB
/
bot-helper.js
File metadata and controls
66 lines (59 loc) · 1.9 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
'use strict';
const { sprintf } = require(`sprintf-js`)
, Discord = require(`discord.js`)
, { ChainAdapter, ChainConstant, ChainTool } = require(`chain-tools-js`)
, ConfigParameter = require(`./config/parameter`)
, ConfigProvider = require(`./config/provider`)
;
module.exports = class BotHelper {
/**
* Updates bot's status with current VP info
* @param {Discord.Client} bot
* @param username
* @returns {Promise<void>}
*/
static async updateVotingPowerStatus(bot, username) {
try {
const wekuAdapter = ChainAdapter.factory(ChainConstant.WEKU)
, account = await wekuAdapter.apiGetAccount(username)
;
bot.user.setActivity(
sprintf(`VP - %s%%.`, ChainTool.calculateAccountVotingPower(account))
, { type: `WATCHING` }
);
} catch (err) {
console.error(err);
}
}
/**
* Checks user permission to perform command.
* @param {string} command Name of command to check.
* @param {Discord.Message} message Message object in which command was received.
*
* @return {boolean} Whether user has permission to perform command or not.
*/
static checkUserPermission(command, message) {
let admins = ConfigProvider.get(ConfigParameter.ADMIN_LIST);
if (null === admins) {
return true;
} else {
return admins.includes(this.getAuthorId(message));
}
}
/**
* Retrieves ID of author of message
* @param {Discord.Message} message
* @returns {string}
*/
static getAuthorId(message) {
return message.author.id;
}
/**
* Sends given test to user chennel
* @param {Discord.Message} message
* @param {string} text
*/
static sendMessage(message, text) {
message.channel.send(text);
}
};