-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.js
335 lines (277 loc) · 15.1 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
//
// Inverse.Finance Discord Bot
//
// By Somer, March 2021
//
const Discord = require('discord.js');
const fs = require('fs');
require('dotenv').config();
// Create client instance
const client = new Discord.Client();
// Load config data
let config = loadConfigData();
// Bot prefix
const prefix = config.prefix;
// Message delete timeout
const msgTimeout = config.msg_delete_timeout;
// IF Discord Role IDs
const adminRoleId = config.inv_admin_role_id;
const moderatorRoleId = config.inv_mod_role_id;
const invaderOnDutyRoleId = config.inv_invader_onduty_role_id;
// Test Role IDs
//const adminRoleId = config.test_admin_role_id;
//const moderatorRoleId = config.test_mod_role_id;
//const invaderOnDutyRoleId = config.test_member_role_id;
// Global scope storage for mission data
var missions = config.missions_data;
// Login to server
client.login(process.env.DISCORD_BOT_TOKEN);
// Confirm connection
client.on('ready', () => console.log('The INVader Bot is ready!'));
console.log(config);
//-------------------------------------------------------------------------- Command Parser
client.on('message', (msg) => {
if (msg.author.bot) return;
if (!msg.content.startsWith(prefix)) return;
// Parse the command
const commandBody = msg.content.slice(prefix.length);
const args = commandBody.split('|');
const command = args[0].toLowerCase();
// inv
if (command === 'inv') {
sendMessageWithTimeout(msg, commandsEmbed, msgTimeout);
}
// links
else if (command === 'links' || command === 'ln') {
sendMessageWithTimeout(msg, officialLinks, msgTimeout);
}
// accounts
else if (command === 'accounts' || command === 'acc') {
sendMessageWithTimeout(msg, accountsEmbed, msgTimeout);
}
// contracts
else if (command === 'contracts' || command === 'con') {
sendMessageWithTimeout(msg, contractsEmbed, msgTimeout);
}
// tokens
else if (command === 'tokens' || command === 'tok') {
sendMessageWithTimeout(msg, tokensEmbed, msgTimeout);
}
// Add mission (admin only)
else if (command === 'addmission' || command === 'am') {
// Check for Admin or Moderator role
if (!(msg.member.roles.cache.has(adminRoleId) || msg.member.roles.cache.has(moderatorRoleId))) {
sendMessageWithTimeout(msg, 'Adding missions requires the Admin or Moderator role.', msgTimeout);
}
else {
// Only add if values present
if (!args[1] || !args[2]) {
sendMessageWithTimeout(msg, 'Nothing to add. Provide both a title and a description. E.g. /am|Mission 1|The first mission', msgTimeout);
}
else {
missions[args[1]] = args[2];
sendMessageWithTimeout(msg, 'Mission added: ' + args[1] + ': ' + args[2], msgTimeout);
// Save the change to the config json file
updateConfigData('missions_data', missions);
}
}
}
// Remove mission (admin only)
else if (command === 'removemission' || command === 'rm') {
// Check for Admin or Moderator role
if (!(msg.member.roles.cache.has(adminRoleId) || msg.member.roles.cache.has(moderatorRoleId))) {
sendMessageWithTimeout(msg, 'Removing missions requires the Admin or Moderator role.', msgTimeout);
}
else {
// Check if mission exists
if (!missions[args[1]]) {
sendMessageWithTimeout(msg, 'No such mission. Use /miss to see a list of missions.', msgTimeout);
}
else {
sendMessageWithTimeout(msg, 'Mission removed: ' + args[1] + ': ' + missions[args[1]], msgTimeout);
delete missions[args[1]];
// Save the change to the config json file
updateConfigData('missions_data', missions);
}
}
}
// Clear all missions (admin only)
else if (command === 'clearmissions' || command === 'cm') {
// Check for Admin or Moderator role
if (!(msg.member.roles.cache.has(adminRoleId) || msg.member.roles.cache.has(moderatorRoleId))) {
sendMessageWithTimeout(msg, 'Clearing missions requires the Admin or Moderator role.', msgTimeout);
}
else {
// Check if empty
if (isEmpty(missions)) {
sendMessageWithTimeout(msg, 'No missions to clear.', msgTimeout);
}
else {
missions = {};
sendMessageWithTimeout(msg, 'Missions cleared.', msgTimeout);
// Save the change to the config json file
updateConfigData('missions_data', missions);
}
}
}
// List missions (admin only)
else if (command === 'missions' || command === 'miss') {
// Check for Admin or Moderator role
if (!(msg.member.roles.cache.has(adminRoleId) || msg.member.roles.cache.has(moderatorRoleId))) {
sendMessageWithTimeout(msg, 'Listing missions requires the Admin or Moderator role.', msgTimeout);
}
else {
// Check if empty
if (isEmpty(missions)) {
sendMessageWithTimeout(msg, 'No missions at the moment.', msgTimeout);
}
else {
// Remove original call
msg.delete();
// No timeout
var missionMsg = config.missions_header;
for (var m in missions) {
missionMsg += m + ': ' + missions[m] + '\n\n';
}
missionMsg += config.missions_footer;
msg.channel.send(missionMsg);
}
}
}
// List missions + announce (admin only)
else if (command === 'missionsblast' || command === 'missb') {
// Check for Admin or Moderator role
if (!(msg.member.roles.cache.has(adminRoleId) || msg.member.roles.cache.has(moderatorRoleId))) {
sendMessageWithTimeout(msg, 'Blasting missions requires the Admin or Moderator role.', msgTimeout);
}
else {
// Check if empty
if (isEmpty(missions)) {
sendMessageWithTimeout(msg, 'No missions at the moment.', msgTimeout);
}
else {
// Remove original call
msg.delete();
// No timeout
var missionMsg = config.missions_header;
for (var m in missions) {
missionMsg += m + ': ' + missions[m] + '\n\n';
}
missionMsg += config.missions_footer;
missionMsg += '<@&' + invaderOnDutyRoleId + '>';
msg.channel.send(missionMsg);
}
}
}
});
//-------------------------------------------------------------------------- Commands
// Bot Command List
const commandsEmbed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('INVader Bot Commands')
.addField('Official Links', "/links or /ln")
.addField('Accounts', '/accounts or /acc')
.addField('Contracts', '/contracts or /con')
.addField('Tokens', '/tokens or /tok')
.addField('List Missions*', '/missions or /miss')
.addField('List Missions & Blast*', '/missionsblast or /missb - List missions and @ the INVader_OnDuty role')
.addField('Add Mission*', '/addmission or /am - Use | to separate. E.g. /am|Task 1|The first mission')
.addField('Remove Mission*', '/removemission or /rm - Use | to separate. E.g. /rm|Task 1')
.addField('Clear Missions*', '/clearmissions or /cm')
.setFooter('* = Admin/Moderator only. Embed timeout: ' + (msgTimeout / 1000) + 'sec');
//-------------------------------------------------------------------------- Accounts
// Accounts Bot - Etherscan/Zerion
const accountsEmbed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Inverse.Finance Accounts')
.addField('Inverse Deployer', '[Etherscan](https://etherscan.io/address/0x3fcb35a1cbfb6007f9bc638d388958bc4550cb28) | [Zerion](https://app.zerion.io/0x3fcb35a1cbfb6007f9bc638d388958bc4550cb28/overview)')
.addField('Inverse Treasury', '[Etherscan](https://etherscan.io/address/0x926df14a23be491164dcf93f4c468a50ef659d5b) | [Zerion](https://app.zerion.io/0x926df14a23be491164dcf93f4c468a50ef659d5b/overview)')
.addField('Anchor Bank (ETH)', '[Etherscan](https://etherscan.io/address/0x697b4acaa24430f254224eb794d2a85ba1fa1fb8) | [Zerion](https://app.zerion.io/0x697b4acaa24430f254224eb794d2a85ba1fa1fb8/overview)')
.addField('Anchor Bank (DOLA)', '[Etherscan](https://etherscan.io/address/0x7Fcb7DAC61eE35b3D4a51117A7c58D53f0a8a670) | [Zerion](https://app.zerion.io/0x7Fcb7DAC61eE35b3D4a51117A7c58D53f0a8a670/overview)')
.setFooter('Embed timeout: ' + (msgTimeout / 1000) + 'sec');
//-------------------------------------------------------------------------- Contracts
// Contracts Bot - Etherscan
const contractsEmbed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Inverse.Finance Contracts')
.addField('INV contract', '[0x41d5d79431a913c4ae7d69a668ecdfe5ff9dfb68](https://etherscan.io/address/0x41d5d79431a913c4ae7d69a668ecdfe5ff9dfb68)')
.addField('xINV contract', '[0x65b35d6eb7006e0e607bc54eb2dfd459923476fe](https://etherscan.io/address/0x65b35d6eb7006e0e607bc54eb2dfd459923476fe)')
.addField('DOLA contract', '[0x865377367054516e17014ccded1e7d814edc9ce4](https://etherscan.io/address/0x865377367054516e17014ccded1e7d814edc9ce4)')
.addField('anETH contract', '[0x697b4acAa24430F254224eB794d2a85ba1Fa1FB8](https://etherscan.io/address/0x697b4acAa24430F254224eB794d2a85ba1Fa1FB8)')
.addField('anDOLA contract', '[0x7fcb7dac61ee35b3d4a51117a7c58d53f0a8a670](https://etherscan.io/address/0x7fcb7dac61ee35b3d4a51117a7c58d53f0a8a670)')
.addField('Anchor Stabilizer contract', '[0x7ec0d931affba01b77711c2cd07c76b970795cdd](https://etherscan.io/address/0x7ec0d931affba01b77711c2cd07c76b970795cdd)')
.addField('DCA Vault - USDC-ETH contract', '[0x89eC5dF87a5186A0F0fa8Cb84EdD815de6047357](https://etherscan.io/address/0x89eC5dF87a5186A0F0fa8Cb84EdD815de6047357)')
.addField('DCA Vault - DAI-wBTC contract', '[0xc8f2E91dC9d198edEd1b2778F6f2a7fd5bBeac34](https://etherscan.io/address/0xc8f2E91dC9d198edEd1b2778F6f2a7fd5bBeac34)')
.addField('DCA Vault - DAI-YFI contract', '[0x41D079ce7282d49bf4888C71B5D9E4A02c371F9B](https://etherscan.io/address/0x41D079ce7282d49bf4888C71B5D9E4A02c371F9B)')
.addField('DCA Vault - DAI-ETH contract', '[0x2dCdCA085af2E258654e47204e483127E0D8b277](https://etherscan.io/address/0x2dCdCA085af2E258654e47204e483127E0D8b277)')
.setFooter('Embed timeout: ' + (msgTimeout / 1000) + 'sec');
//-------------------------------------------------------------------------- Tokens
// Tokens Bot - Etherscan
const tokensEmbed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Inverse.Finance Tokens')
.addField('INV Token', '[0x41d5d79431a913c4ae7d69a668ecdfe5ff9dfb68](https://etherscan.io/token/0x41d5d79431a913c4ae7d69a668ecdfe5ff9dfb68)')
.addField('DOLA Token', '[0x865377367054516e17014ccded1e7d814edc9ce4](https://etherscan.io/token/0x865377367054516e17014ccded1e7d814edc9ce4)')
.addField('inUSDC->ETH Token', '[0x89eC5dF87a5186A0F0fa8Cb84EdD815de6047357](https://etherscan.io/token/0x89eC5dF87a5186A0F0fa8Cb84EdD815de6047357)')
.addField('inDAI->wBTC Token', '[0xc8f2E91dC9d198edEd1b2778F6f2a7fd5bBeac34](https://etherscan.io/token/0xc8f2E91dC9d198edEd1b2778F6f2a7fd5bBeac34)')
.addField('inDAI->YFI Token', '[0x41D079ce7282d49bf4888C71B5D9E4A02c371F9B](https://etherscan.io/token/0x41D079ce7282d49bf4888C71B5D9E4A02c371F9B)')
.addField('inDAI->ETH Token', '[0x2dCdCA085af2E258654e47204e483127E0D8b277](https://etherscan.io/token/0x2dCdCA085af2E258654e47204e483127E0D8b277)')
.addField('UniSwap_v2 INV-ETH Token', '[0x73e02eaab68a41ea63bdae9dbd4b7678827b2352](https://etherscan.io/token/0x73e02eaab68a41ea63bdae9dbd4b7678827b2352)')
.addField('UniSwap_v2 DOLA-ETH Token', '[0xecfbe9b182f6477a93065c1c11271232147838e5](https://etherscan.io/token/0xecfbe9b182f6477a93065c1c11271232147838e5)')
.setFooter('Embed timeout: ' + (msgTimeout / 1000) + 'sec');
//-------------------------------------------------------------------------- Links
// Official Links
const officialLinks = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Inverse.Finance Official Links')
.addField('Website', '[https://inverse.finance/](https://inverse.finance/)')
.addField('Discord', '[https://discord.com/invite/YpYJC7R5nv](https://discord.com/invite/YpYJC7R5nv)')
.addField('Telegram', '[https://t.me/InverseFinance](https://t.me/InverseFinance)')
.addField('Telegram Announcements', '[https://t.me/InverseFinanceAnn](https://t.me/InverseFinanceAnn)')
.addField('Twitter', '[https://twitter.com/InverseFinance](https://twitter.com/InverseFinance)')
.addField('Medium', '[https://medium.com/inversefinance ](https://medium.com/inversefinance )')
.addField('Github', '[https://github.com/InverseFinance](https://github.com/InverseFinance)')
.addField('Dune Analytics', '[http://bit.ly/INV_DUNE](http://bit.ly/INV_DUNE)')
.addField('Tally Governance', '[https://www.withtally.com/governance/inverse](https://www.withtally.com/governance/inverse)')
.addField('Dex Tools WETH-INV', '[Dex Tools](https://www.dextools.io/app/uniswap/pair-explorer/0x73e02eaab68a41ea63bdae9dbd4b7678827b2352)')
.addField('Dex Tools WETH-DOLA', '[Dex Tools](https://www.dextools.io/app/uniswap/pair-explorer/0xecfbe9b182f6477a93065c1c11271232147838e5)')
.addField('INV-ETH Uniswap Trade', '[Uniswap](https://app.uniswap.org/#/swap?inputCurrency=0x41d5d79431a913c4ae7d69a668ecdfe5ff9dfb68)')
.addField('INV-ETH Uniswap Pair', '[Uniswap](https://info.uniswap.org/pair/0x73e02eaab68a41ea63bdae9dbd4b7678827b2352)')
.addField('DOLA-ETH Uniswap Trade', '[Uniswap](https://app.uniswap.org/#/swap?inputCurrency=0x865377367054516e17014ccded1e7d814edc9ce4&outputCurrency=ETH)')
.addField('DOLA-ETH Uniswap Pair', '[Uniswap](https://info.uniswap.org/pair/0xecfbe9b182f6477a93065c1c11271232147838e5)')
.addField('Buy DOLA', '[https://inverse.finance/stabilizer](https://inverse.finance/stabilizer)')
.setFooter('Embed timeout: ' + (msgTimeout / 1000) + 'sec');
//-------------------------------------------------------------------------- Helper Functions
// Send an embed message with a timeout to delete it
function sendMessageWithTimeout(msgObj, msgToSend, timeout) {
msgObj.channel.send(msgToSend).then(embedMessage => {
setTimeout(() => msgObj.delete(), timeout);
setTimeout(() => embedMessage.delete(), timeout);
});
}
// Load config data
function loadConfigData() {
return JSON.parse(fs.readFileSync('config.json', 'utf-8'));
}
// Update config data
function updateConfigData(key, value) {
config[key] = value;
saveConfigData();
}
// Save config data
function saveConfigData() {
const json = JSON.stringify(config);
fs.writeFile('config.json', json, (err) => {
if (err) {
console.log(err);
}
});
}
// Check if object is empty
function isEmpty(obj) {
for (var key in obj) {
if (obj.hasOwnProperty(key))
return false;
}
return true;
}