-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
45 lines (36 loc) · 1.22 KB
/
main.py
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
#Based off of juliankoh/ribbon-discord-bot/bot_tvl.py
import discord
from discord.ext import tasks
import os
from dotenv import load_dotenv
import requests
import json
import aiohttp
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
REFRESH_TIMER = os.getenv('REFRESH_TIMER')
client = discord.Client()
async def get_tvl():
async with aiohttp.ClientSession() as session:
async with session.get("https://analytics.abracadabra.money/api/statistic/tvl") as r:
if r.status == 200:
js = await r.json()
if js['tvl']<1000000000:
tvl = round(js['tvl'] / 1000000, 1)
tvlstring = (f"TVL: ${tvl}M")
return tvlstring
else:
tvl = round(js['tvl'] / 1000000000, 3)
tvlstring = (f"TVL: ${tvl}B")
return tvlstring
@client.event
async def on_ready():
print(f'{client.user} has connected to Discord! ')
for guild in client.guilds:
print("connected to ", guild.name)
refresh_tvl.start()
@tasks.loop(seconds=float(REFRESH_TIMER))
async def refresh_tvl():
for guild in client.guilds:
await guild.me.edit(nick=await get_tvl())
client.run(TOKEN)