-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
615 lines (562 loc) · 25.9 KB
/
main.py
File metadata and controls
615 lines (562 loc) · 25.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
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
import discord
import os
import requests
import json
from discord.ext import tasks, commands
from dotenv import load_dotenv
load_dotenv()
intents = discord.Intents.default()
intents.members = True # Subscribe to the privileged members intent.
client = discord.Client(intents=intents)
token = os.environ.get('TOKEN')
warning_channel_production = os.environ.get('warning_channel_production')
warning_channel_test = os.environ.get('warning_channel_test')
resources_channel_production = os.environ.get('resources_channel_production')
bot_help_channel_production = os.environ.get('bot_help_channel_production')
bot_git_channel_production = os.environ.get('bot_git_channel_production')
bot_wallet_channel_production = os.environ.get('bot_wallet_channel_production')
bot_explorer_channel_production = os.environ.get('bot_explorer_channel_production')
bot_whitepaper_channel_production = os.environ.get('bot_whitepaper_channel_production')
bot_shentusite_channel_production = os.environ.get('bot_shentusite_channel_production')
bot_townhallrecording_channel_production = os.environ.get('bot_townhallrecording_channel_production')
bot_shield_channel_production = os.environ.get('bot_shield_channel_production')
production_server_id = os.environ.get('production_server_id')
admin_role_id = os.environ.get('admin_role_id')
shentu_role_id = os.environ.get('shentu_role_id')
chain_role_id = os.environ.get('chain_role_id')
admin_warning_channel_production=os.environ.get('admin_warning_channel_production')
shentu_endpoint=os.environ.get('shentu_endpoint')
#Fetch Data from CoinGecko
def get_CGdata(cur):
coingecko_link = "https://api.coingecko.com/api/v3/coins/markets?vs_currency="+cur+"&ids=certik"
response = requests.get(coingecko_link)
#Load data and return
json_data = json.loads(response.text)
return(json_data)
#Fetch chain Data from Shentu Chain
def get_Chaindata(info):
#Fetch Staking data
if info=="staked":
response = requests.get(shentu_endpoint + "/staking/pool")
#Fetch Total supply data
elif info=="total_supply":
response = requests.get(shentu_endpoint + "/cosmos/bank/v1beta1/supply")
#Fetch Inflation data
elif info=="inflation":
response = requests.get(shentu_endpoint + "/minting/inflation")
#Fetch unbonding validators
elif info=="unbonding":
response = requests.get(shentu_endpoint + "/staking/validators?status=BOND_STATUS_UNBONDING")
#Fetch bonded validators
elif info=="bonded":
response = requests.get(shentu_endpoint + "/staking/validators?status=BOND_STATUS_BONDED")
#Fetch unbonded validators
elif info=="unbonded":
response = requests.get(shentu_endpoint + "/staking/validators?status=BOND_STATUS_UNBONDED")
#Fetch Chain info
elif info=="network":
response = requests.get(shentu_endpoint + "/cosmos/base/tendermint/v1beta1/node_info")
#Fetch Shield Provider info
elif info=="shieldproviders":
response = requests.get(shentu_endpoint + "/shield/providers")
elif info=="shieldpurchases":
response = requests.get(shentu_endpoint + "/shield/purchases")
#Load data and return
json_data = json.loads(response.text)
return(json_data)
def get_total_supply():
uctk_total_supply=0
supply_data=get_Chaindata("total_supply")
supply_dataset=supply_data['supply']
for supply_result in supply_data['supply'] :
if supply_result['denom']=="uctk":
uctk_total_supply=supply_result['amount']
return (uctk_total_supply)
def get_yield():
#Get full supply data
uctk_total_supply=get_total_supply()
#Get staking data
staking_data=get_Chaindata("staked")
result_data=staking_data['result']
uctk_bonded=result_data['bonded_tokens']
#Get inflation data
inflation_data=get_Chaindata("inflation")
inflation=inflation_data['result']
#calculate yield %
yield_percentage=float(uctk_total_supply)/float(uctk_bonded)*float(inflation)*100
return(yield_percentage)
#Fetch validator Data from Shentu Chain
def get_validatordata(validator_address):
#Fetch Validator data for the given address
response = requests.get(shentu_endpoint + "/staking/validators/" + validator_address)
json_data = json.loads(response.text)
return(json_data)
#Discord Login
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
#set status
discord.CustomActivity(name="-shentuhelp for info", emoji='🖥️')
#Start the Jailed check
jailed.start()
#Spammer alert
spammer.start()
@tasks.loop(seconds=60.0)
async def jailed():
#Initialize variable
known_jailed=0
new_list = ""
#Define channel to post in
channel = await client.fetch_channel(warning_channel_production)
#Read the known jailed validators
f = open("jail.dat", "r")
old_list=f.read()
f.close()
#print ("jailed test")
#Make a list of known jailed addresses by splitting the jail.dat file content
known_jailed_addresses=old_list.split('-')
#Fetch full list of jailed validators
unbonding_data=get_Chaindata("unbonding")
for i in unbonding_data['result']:
#Store address of unbinding validator for this loop
unbinding_validator_address= i['operator_address']
#loop through the known addresses to verify if it is a new one
for jailed_address in known_jailed_addresses:
if unbinding_validator_address == jailed_address:
known_jailed=1
#If jailed validator isn't known yet post in channel (skip if already known)
if known_jailed==0:
#Fetch Validator data
unbinding_validator_data= get_validatordata(unbinding_validator_address)
#Fetch Validator moniker (name)
unbinding_validator_result_data=unbinding_validator_data['result']
unbinding_validator_description_data=unbinding_validator_result_data['description']
unbinding_validator_moniker=unbinding_validator_description_data['moniker']
#Send message
await channel.send(":warning::warning:**Validator jailed**:warning::warning:\n""**" + str(unbinding_validator_moniker) + "** - " + str(unbinding_validator_address))
#Append new jailed validator list
new_list+=unbinding_validator_address + "-"
#Reset known variable
known_jailed=0
#Overwrite known jailed validators
f = open("jail.dat", "w")
f.write(new_list)
f.close
@tasks.loop(seconds=900.0)
async def spammer():
#Initialize variables
known_spammer_name=0
known_spammer_display_name=0
new_name_list = ""
new_display_name_list = ""
#Define channel to post in
channel = await client.fetch_channel(admin_warning_channel_production)
#Get the template list
f = open("spammer_templates.dat", "r")
template_list=f.read()
f.close()
#Get the name list
f = open("known_spammer_name.dat", "r")
spammer_name_list=f.read()
f.close()
#Get the display name list
f = open("known_spammer_display_name.dat", "r")
spammer_display_name_list=f.read()
f.close()
#transform lists into arrays
templates=template_list.split('-')
spammer_names=spammer_name_list.split('_-_')
spammer_display_names=spammer_display_name_list.split('_-_')
#Define server
server = client.get_guild(int(production_server_id))
#Get all members
member_list = server.members
#Loop through members
for member in member_list:
#Check all templates
for template in templates:
#Check if name contains current template
if template in member.display_name.lower():
#Add to new list
new_display_name_list += member.display_name + "_-_"
#Verify if already flagged before
for display_name in spammer_display_names:
if display_name == member.display_name:
known_spammer_display_name=1
#If not known post in channel
if known_spammer_display_name == 0:
await channel.send(member.display_name + " display name found")
#Check if name contains current template
if template in member.name.lower():
new_name_list += member.name + "_-_"
#Verify if already flagged before
for name in spammer_names:
if name == member.name:
known_spammer_name=1
#If not known post in channe
if known_spammer_name == 0:
await channel.send(member.name + " name found")
#Reset known variables
known_spammer_display_name=0
known_spammer_name=0
#write new list
f = open("known_spammer_name.dat", "w")
f.write(new_name_list)
f.close
f = open("known_spammer_display_name.dat", "w")
f.write(new_display_name_list)
f.close
#Read Messages
@client.event
async def on_message(message):
if message.author == client.user:
return
msg = message.content
#Reply with correct answer
#Request prices from CoinGecko
if msg.lower().startswith('-price'):
#Check for given Currency
try:
currency = msg.lower().split(' ')[1]
#Use USD if no currency is given
except:
currency = "$"
#Request data and convert to correct currency sign
if currency=="eur" or currency=="€" or currency=="euro":
currency = "eur"
full_data=get_CGdata(currency)
currency_sign = "€"
elif currency=="" or currency=="usd" or currency=="$" or currency=="dollar":
currency = "usd"
full_data=get_CGdata(currency)
currency_sign = "$"
elif currency=="pound" or currency=="gbp" or currency=="£":
currency = "gbp"
full_data=get_CGdata(currency)
currency_sign = "£"
elif currency=="yen" or currency=="jpy" or currency=="¥":
currency = "jpy"
full_data=get_CGdata(currency)
currency_sign = "¥"
elif currency=="yuan" or currency=="cny" or currency=="¥":
currency = "cny"
full_data=get_CGdata(currency)
currency_sign = "¥"
elif currency=="rubles" or currency=="rub" or currency=="₽":
currency = "rub"
full_data=get_CGdata(currency)
currency_sign = "₽"
elif currency=="twd" or currency=="ntdollar" or currency=="NT$":
currency = "twd"
full_data=get_CGdata(currency)
currency_sign = "NT$"
elif currency=="idr" or currency=="rupiah" or currency=="Rp":
currency = "idr"
full_data=get_CGdata(currency)
currency_sign = "Rp"
elif currency=="won" or currency=="krw" or currency=="₩":
currency = "krw"
full_data=get_CGdata(currency)
currency_sign = "₩"
#Get price data
price = full_data[0]['current_price']
high =full_data[0]['high_24h']
low = full_data[0]['low_24h']
price_change = full_data[0]['price_change_24h']
#Send message
await message.channel.send( "**Current price: "+ currency_sign + str('{:,}'.format(round(float(price),2)))+ "**\n24H high: "+ currency_sign + str('{:,}'.format(round(float(high),2))) + "\n24H low: "+ currency_sign +str('{:,}'.format(round(float(low),2))) + "\n24H price change: "+ currency_sign + str('{:,}'.format(round(float(price_change),4))))
#Request Staking info
if msg.lower().startswith('-staked'):
#Get staking data
staking_data=get_Chaindata("staked")
result_data=staking_data['result']
uctk_not_bonded=result_data['not_bonded_tokens']
uctk_bonded=result_data['bonded_tokens']
#Get full supply data
uctk_total_supply=get_total_supply()
#Convert from uctk to CTK
total_supply=int(uctk_total_supply)/1000000
bonded=int(uctk_bonded)/1000000
not_bonded=int(uctk_not_bonded)/1000000
#Calculate staked %
staked_percentage=(int(uctk_bonded)/int(uctk_total_supply))*100
inflation_data=get_Chaindata("inflation")
inflation=inflation_data['result']
#Fetch yield
yield_percentage=get_yield()
#Send message
await message.channel.send("Total supply: " + str('{:,}'.format(round(float(total_supply),2))) + "CTK\nBonded (staked): " + str('{:,}'.format(round(float(bonded),2)))+ "CTK \nUnbonding: " + str('{:,}'.format(round(float(not_bonded),2))) + "CTK\nStaked Percentage: "+ str('{:,}'.format(round(float(staked_percentage),2))) +"%\nYield: "+str('{:,}'.format(round(float(yield_percentage),2)))+ "%")
#Request Total supply
if msg.lower().startswith('-total'):
#Get full supply data
uctk_total_supply=get_total_supply()
#Convert from uctk to CTK
total_supply=int(uctk_total_supply)/1000000
#Send message
await message.channel.send("Total supply: " + str('{:,}'.format(round(float(total_supply),2)))+"CTK")
#Request Inflation information
if msg.lower().startswith('-inflation'):
#Get inflation data
inflation_data=get_Chaindata("inflation")
inflation=inflation_data['result']
#Convert to percentage
inflation_percentage=float(inflation)*100
#Send message
await message.channel.send("Inflation: " + str('{:,}'.format(round(float(inflation_percentage),2)))+ "%")
#Request staking yield
if msg.lower().startswith('-apy') or msg.lower().startswith('-yield') or msg.lower().startswith('-apr'):
#Fetch yield
yield_percentage=get_yield()
#Send message
await message.channel.send("Yield: " + str('{:,}'.format(round(float(yield_percentage),2)))+ "%")
#Request staking rewards
if msg.lower().startswith('-stakingrewards') or msg.lower().startswith('-srewards') or msg.lower().startswith('-scalc') or msg.lower().startswith('-stakingcalculator'):
staking_rewards_error = 0
validator_commission = 0
try:
validator_commission = msg.lower().split(' ')[1]
#Use 0 commission if none is given
except:
staked_quantity = 0
try:
staked_quantity = msg.lower().split(' ')[2]
#Use 1000CTK if none is given
except:
staked_quantity = 1000
if float(validator_commission) > 100 or float(validator_commission) < 0 or float(staked_quantity) < 0:
staking_rewards_error=1
if staking_rewards_error == 0:
#Fetch yield
yield_percentage=get_yield()
#Calculate staking rewards
year_reward=float(staked_quantity)*(float(yield_percentage)/100)*(1-(float(validator_commission)/100))
day_reward=year_reward/365
month_reward=day_reward*30
week_reward=day_reward*7
hour_reward=day_reward/24
#Send message
await message.channel.send("Given data used to calculate is "+ str('{:,}'.format(round(float(staked_quantity),4))) +"CTK with a validator commission of " + str(validator_commission) + "%\nCurrent yield: " + str(round(float(yield_percentage),2)) + "%\n1 Year : " + str('{:,}'.format(round(float(year_reward),4))) + "CTK\n30 Days : " + str('{:,}'.format(round(float(month_reward),4))) + "CTK\n7 Days : " + str('{:,}'.format(round(float(week_reward),4))) + "CTK\n1 Day : " + str('{:,}'.format(round(float(day_reward),4))) + "CTK\n1 Hour : " + str('{:,}'.format(round(float(hour_reward),4))) + "CTK\n*Please note that the staking yield is variable and this is only an estimation*")
else:
await message.channel.send("Bad parameters given. Please use \'command validator commission staked quantity\'.\n Example: \'-stakingcalculator 5 2500\' ")
#Request unbonding Validators
if msg.lower().startswith('-jailed') or msg.lower().startswith('-unbonding'):
#Initialize string
unbinding_validator_list=""
#Get unbonding validator data
unbonding_data=get_Chaindata("unbonding")
#Loop through all unbinding validators
for i in unbonding_data['result']:
#Store address of unbinding validator
unbinding_validator_address= i['operator_address']
#Fetch Validator data
unbinding_validator_data= get_validatordata(unbinding_validator_address)
#Fetch Validator moniker (name)
unbinding_validator_result_data=unbinding_validator_data['result']
unbinding_validator_description_data=unbinding_validator_result_data['description']
unbinding_validator_moniker=unbinding_validator_description_data['moniker']
#Build string to use in the message
unbinding_validator_list+="**" + unbinding_validator_moniker + "** - " + unbinding_validator_address + "\n"
#Send message
await message.channel.send(unbinding_validator_list)
#Request shentu site link
if msg.lower().startswith('-site'):
#fetch last message from the shentu-site channel
bot_shentusite_last_message = (await client.get_channel(int(bot_shentusite_channel_production)).history(limit=2).flatten())[0]
#Send message
await message.channel.send(bot_shentusite_last_message.content)
#Request Whitepaper link
if msg.lower().startswith('-whitepaper'):
#fetch last message from the whitepaper channel
bot_whitepaper_last_message = (await client.get_channel(int(bot_whitepaper_channel_production)).history(limit=2).flatten())[0]
#Send message
await message.channel.send(bot_whitepaper_last_message.content)
#Request official wallet link
if msg.lower().startswith('-wallet') or msg.lower().startswith('-deepwallet'):
#fetch last message from the wallet channel
bot_wallet_last_message = (await client.get_channel(int(bot_wallet_channel_production)).history(limit=2).flatten())[0]
#Send message
await message.channel.send(bot_wallet_last_message.content)
#Request official chain explorer
if msg.lower().startswith('-chain') or msg.lower().startswith('-explorer'):
#fetch last message from the explorer channel
bot_explorer_last_message = (await client.get_channel(int(bot_explorer_channel_production)).history(limit=2).flatten())[0]
#Send message
await message.channel.send(bot_explorer_last_message.content)
#Request Shield link
if msg.lower().startswith('-shieldweb'):
#fetch last message from the shield channel
bot_shield_last_message = (await client.get_channel(int(bot_shield_channel_production)).history(limit=2).flatten())[0]
#Send message
await message.channel.send(bot_shield_last_message.content)
#Request Resources links
if msg.lower().startswith('-useful') or msg.lower().startswith('-resources') or msg.lower().startswith('-links'):
#fetch last message info in the resources channel
resources_last_message=(await client.get_channel(int(resources_channel_production)).history(limit=1).flatten())[0]
#Send message
await message.channel.send(resources_last_message.content + "\n\n You can also visit <#"+resources_channel_production+"> to see all links")
#Request Github link
if msg.lower().startswith('-git') or msg.lower().startswith('-github'):
#fetch last message from the git channel
bot_github_last_message = (await client.get_channel(int(bot_git_channel_production)).history(limit=2).flatten())[0]
#Send message
await message.channel.send(bot_github_last_message.content)
#Post Shentu Bot help
if msg.lower().startswith('-shentuhelp'):
#fetch last 2 messages info in the Shentu-bot channel
bot_help_second_last_message =(await client.get_channel(int(bot_help_channel_production)).history(limit=2).flatten())[1]
bot_help_last_message =(await client.get_channel(int(bot_help_channel_production)).history(limit=2).flatten())[0]
#Send message
await message.channel.send(bot_help_second_last_message.content)
await message.channel.send(bot_help_last_message.content + "\n\n You can also visit <#"+bot_help_channel_production+"> to see all commands")
#Request Townhall recording link
if msg.lower().startswith('-threcording'):
#fetch last message from the townhallrecording channel
bot_townhallrecording_last_message = (await client.get_channel(int(bot_townhallrecording_channel_production)).history(limit=2).flatten())[0]
#Send message
await message.channel.send(bot_townhallrecording_last_message.content)
#Shentu bot to repeat message
if msg.lower().startswith('-shentusay'):
#Pick up the text
say_text = msg.partition(' ')[2]
#Fetch messenger
message_author_id = message.author.id
#Fetch server
server = client.get_guild(int(production_server_id))
#fetch user
user = server.get_member(message_author_id)
#Fetch authorized roles
admin_role = server.get_role(int(admin_role_id))
shentu_role = server.get_role(int(shentu_role_id))
chain_role = server.get_role(int(chain_role_id))
#Init accepted
accepted=0
#Loop through the roles (range is a bad workaround)
for r in range(15):
try:
role=user.roles[r]
if shentu_role == role or admin_role == role or chain_role_id == role:
accepted=1
except:
break
#If the user is allowed and message isn't empty the message will be posted
if accepted==1:
if say_text != "":
await message.channel.send(say_text)
#Add Shentu Bot feature request
if msg.lower().startswith('-request'):
#Read message and get the requested feature
try:
requested_feature = str(msg.split(',')[1])
except:
await message.channel.send("Couldn't read the request please make sure to use -request ,requested feature")
#Use USD if no currency is given
stripped_request = requested_feature
new_feature_request= str(stripped_request) + "-_-"
#Add to list
f = open("features.dat", "a")
f.write(new_feature_request)
f.close
#Send message
await message.channel.send("\'" + requested_feature + "\' added to the list of requested features")
#Show Shentu Bot feature requests
if msg.lower().startswith('-showrequests'):
#read existing list
f = open("features.dat", "r")
old_list=f.read()
f.close()
features_message = "List of requested features: \n\n"
requested_features=old_list.split('-_-')
#loop through list and add to message
for feature_request in requested_features:
if feature_request != "":
features_message = features_message + "-" + feature_request + "\n"
#Send message
await message.channel.send(features_message)
#Show Shentu versions
if msg.lower().startswith('-version'):
#Get full network data
network_data=get_Chaindata("network")
protocol_data=network_data['default_node_info']
application_data=network_data['application_version']
#Send message
protocol_version=protocol_data['network']
application_version=application_data['app_name'] + " " + application_data['version']
await message.channel.send("Network version: " + protocol_version + "\nValidator binary version: " + application_version )
#Show Social media links
if msg.lower().startswith('-social'):
#fetch last message info in the resources channel
resources_last_message=(await client.get_channel(int(resources_channel_production)).history(limit=1).flatten())[0]
#Trim to only get social media
resources_last_message_string=resources_last_message.content
social_media=resources_last_message_string.split("***Social Media***",1)[1]
#Send message
await message.channel.send("***Social Media***" + social_media)
#Show Validator info
if msg.lower().startswith('-validatorinfo') or msg.lower().startswith('-validators'):
#Initialize variables
unbonding_amount=0
bonded_amount=0
unbonded_amount=0
top_voting_power=0
#Get all data
staking_data=get_Chaindata("staked")
result_data=staking_data['result']
uctk_bonded=result_data['bonded_tokens']
uctk_not_bonded=result_data['not_bonded_tokens']
unbonding_data=get_Chaindata("unbonding")
bonded_data=get_Chaindata("bonded")
unbonded_data=get_Chaindata("unbonded")
for unbonding_validator in unbonding_data['result']:
#Count number of unbonding validators
unbonding_amount+=1
for unbonded_validator in unbonded_data['result']:
#Count number of unbonding validators
unbonded_amount+=1
for bonded_validator in bonded_data['result']:
#Count number of unbonding validators
bonded_amount+=1
validator_voting_power=bonded_validator['tokens']
if int(top_voting_power)<int(validator_voting_power):
top_voting_power=validator_voting_power
top_validator=bonded_validator['operator_address']
top_voting_power_percentage=float(top_voting_power)/float(uctk_bonded)*100
#Fetch Validator data
top_validator_data= get_validatordata(top_validator)
#Fetch Validator moniker (name)
top_validator_result_data=top_validator_data['result']
top_validator_description_data=top_validator_result_data['description']
top_validator_moniker=top_validator_description_data['moniker']
await message.channel.send("Running validators: " + str(bonded_amount) + "\nJailed validators: " + str(unbonding_amount) + "\nUnbonded validators: " + str(unbonded_amount)+"\n\nTop validator: " + top_validator_moniker + "\nTop validator power: "+ str('{:,}'.format(round(float(top_voting_power_percentage),2))) + "%")
#Show supported valuta
if msg.lower().startswith('-valuta'):
await message.channel.send("US Dollar : usd | Euro : eur | Great Britain Pound : gbp | Korean Won : krw | Japanese Yen : jpy | Chinese Yuan : cny | Russian Rubles : rub | Indonesian Rupiah : idr | New Taiwan Dollar : twd")
#Show shield info
if msg.lower().startswith('-shieldinfo'):
#init variables
total_collateral=0
total_bonded=0
total_purchased=0
#Get Shield data
shield_provider_data=get_Chaindata("shieldproviders")
shield_provider_result_data=shield_provider_data['result']
shield_purchases_data=get_Chaindata("shieldpurchases")
shield_purchases_result_data=shield_purchases_data['result']
for provider in shield_provider_result_data:
total_collateral += int(provider['collateral'])
total_bonded += int(provider['delegation_bonded'])
for purchase in shield_purchases_result_data:
shield_purchases_servicefees_data=purchase['service_fees']
print(shield_purchases_servicefees_data)
shield_purchases_native_data=shield_purchases_servicefees_data['native']
print(shield_purchases_native_data)
for native in shield_purchases_native_data:
print(native)
print(native['amount'])
total_purchased += float(native['amount'])
#Convert uCTK to CTK
total_collateral_ctk=total_collateral/1000000
total_bonded_ctk=total_bonded/1000000
total_purchased_ctk=total_purchased/1000000
#Send message
await message.channel.send("Total Collateral: " + str('{:,}'.format(round(float(total_collateral_ctk),4))) + "\nTotal bonded: " + str('{:,}'.format(round(float(total_bonded_ctk),4))) + "\nTotal Shields purchased: " + str('{:,}'.format(round(float(total_purchased_ctk),4))))
client.run(token)