-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
executable file
·187 lines (162 loc) · 7.3 KB
/
bot.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
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
import os
import discord
import requests
import asyncio
# Replace this with your bot's token
TOKEN = os.getenv('TOKEN')
PRICE_CHANNEL_ID = int(os.getenv('PRICE_CHANNEL_ID'))
HASHRATE_CHANNEL_ID = int(os.getenv('HASHRATE_CHANNEL_ID'))
MARKETCAP_CHANNEL_ID = int(os.getenv('MARKETCAP_CHANNEL_ID'))
HOOSAT_LISTING_WALLET_CHANNEL = int(os.getenv('HOOSAT_LISTING_WALLET_CHANNEL'))
TRON_USDT_LISTING_WALLET_CHANNEL = int(os.getenv('TRON_USDT_LISTING_WALLET_CHANNEL'))
API_URL = os.getenv('API_URL')
FUNDING_HTN_WALLET = "hoosat:qqqht7hgt5jay507ragnk73rkjgwvjqzq238krdd9mpfryr6jcah28ejmxruv"
FUNDUNG_TRON_USDT_WALLET = "TQQzQS1hepsZNuCdhBnGYryCCDegpiASHm"
client = discord.Client(intents=discord.Intents.default())
async def fetch_tron_usdt_wallet_balance(wallet_address, contract_address="TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"):
url = "https://api.trongrid.io/v1/accounts"
try:
response = requests.get(f"{url}/{wallet_address}")
response.raise_for_status()
data = response.json()
# Access the trc20 token balances
trc20_tokens = data.get("data", [{}])[0].get("trc20", [])
for token in trc20_tokens:
if contract_address in token:
# Convert balance from Sun (10^6 precision) to USDT value
balance = int(token[contract_address]) / (10 ** 6)
return balance
# Return 0.0 if no balance found for the specified contract
return 0.0
except requests.exceptions.RequestException as e:
print(f"An error occurred: {e}")
return None
async def update_funding_tron_usdt_wallet_balance(channel):
try:
balance = await fetch_tron_usdt_wallet_balance(FUNDUNG_TRON_USDT_WALLET)
if balance >= 1_000_000:
formatted_balance = f"{balance / 1_000_000:.2f}M"
elif balance >= 1_000:
formatted_balance = f"{balance / 1_000:.2f}K"
else:
formatted_balance = f"{balance:.2f}"
formatted_balance = formatted_balance.replace('.', '․')
activity = discord.Activity(type=discord.ActivityType.watching, name=f"Balance: {formatted_balance}")
await client.change_presence(activity=activity)
new_name = f"💸 {formatted_balance} TRC20 USDT"
await channel.edit(name=new_name)
print(f"Updated channel name to: {new_name}")
except Exception as e:
print(f"An error occurred: {e}")
async def fetch_htn_wallet_balance(address):
try:
response = requests.get(API_URL + f"/addresses/{address}/balance")
data = response.json()
balance = int(data['balance']) / 100_000_000
return balance
except requests.exceptions.RequestException as e:
print(f"An error occurred: {e}")
return None
async def update_funding_htn_wallet_balance(channel):
try:
balance = await fetch_htn_wallet_balance(FUNDING_HTN_WALLET)
if balance >= 1_000_000:
formatted_balance = f"{balance / 1_000_000:.2f}M"
elif balance >= 1_000:
formatted_balance = f"{balance / 1_000:.2f}K"
else:
formatted_balance = f"{balance:.2f}"
formatted_balance = formatted_balance.replace('.', '․')
activity = discord.Activity(type=discord.ActivityType.watching, name=f"Balance: {formatted_balance}")
await client.change_presence(activity=activity)
new_name = f"💸 {formatted_balance} HTN"
await channel.edit(name=new_name)
print(f"Updated channel name to: {new_name}")
except Exception as e:
print(f"An error occurred: {e}")
async def fetch_price():
response = requests.get(API_URL + "/info/price")
data = response.json()
price = data['price']
return price
async def update_price(channel):
try:
price = await fetch_price()
formatted_price = f"{price:.6f}".replace('.', '․')
activity = discord.Activity(type=discord.ActivityType.watching, name=f"Price: ${formatted_price}")
await client.change_presence(activity=activity)
new_name = f"💰 ${formatted_price} HTN"
await channel.edit(name=new_name)
print(f"Updated channel name to: {new_name}")
except Exception as e:
print(f"An error occurred: {e}")
async def fetch_hashrate():
response = requests.get(API_URL + "/info/hashrate?stringOnly=false")
data = response.json()
hashrate = data['hashrate']
return hashrate
async def update_hashrate(channel):
try:
hashrate = await fetch_hashrate()
formatted_hashrate = f"{hashrate:.2f}".replace('.', '․')
activity = discord.Activity(type=discord.ActivityType.watching, name=f"Hashrate: {formatted_hashrate} Th/s")
await client.change_presence(activity=activity)
new_name = f"⛏️ {formatted_hashrate} Th/s"
await channel.edit(name=new_name)
print(f"Updated channel name to: {new_name}")
except Exception as e:
print(f"An error occurred: {e}")
async def fetch_marketcap():
response = requests.get(API_URL + "/info/marketcap?stringOnly=false")
data = response.json()
marketcap = data['marketcap']
return marketcap
async def update_marketcap(channel):
try:
marketcap = await fetch_marketcap()
marketcapDivided = marketcap / 1000
formatted_marketcap = f"{marketcapDivided:.2f} K"
if marketcap >= 1000000:
marketcapDivided = marketcap / 1000000
formatted_marketcap = f"{marketcapDivided:.2f} M"
activity = discord.Activity(type=discord.ActivityType.watching, name=f"marketcap: {formatted_marketcap} USDT")
await client.change_presence(activity=activity)
new_name = f"💹 {formatted_marketcap} USDT"
await channel.edit(name=new_name)
print(f"Updated channel name to: {new_name}")
except Exception as e:
print(f"An error occurred: {e}")
async def update_channel_name():
await client.wait_until_ready()
priceChannel = client.get_channel(PRICE_CHANNEL_ID)
if priceChannel is None:
print(f"Channel with ID {PRICE_CHANNEL_ID} not found.")
return
hashrateChannel = client.get_channel(HASHRATE_CHANNEL_ID)
if hashrateChannel is None:
print(f"Channel with ID {HASHRATE_CHANNEL_ID} not found.")
return
marketcapChannel = client.get_channel(MARKETCAP_CHANNEL_ID)
if marketcapChannel is None:
print(f"Channel with ID {MARKETCAP_CHANNEL_ID} not found.")
return
hoosatListingWalletChannel = client.get_channel(HOOSAT_LISTING_WALLET_CHANNEL)
if hoosatListingWalletChannel is None:
print(f"Channel with ID {HOOSAT_LISTING_WALLET_CHANNEL} not found.")
return
tronUSDTListingWalletChannel = client.get_channel(TRON_USDT_LISTING_WALLET_CHANNEL)
if tronUSDTListingWalletChannel is None:
print(f"Channel with ID {TRON_USDT_LISTING_WALLET_CHANNEL} not found.")
return
while not client.is_closed():
await update_price(priceChannel)
await update_hashrate(hashrateChannel)
await update_marketcap(marketcapChannel)
await update_funding_htn_wallet_balance(hoosatListingWalletChannel)
await update_funding_tron_usdt_wallet_balance(tronUSDTListingWalletChannel)
await asyncio.sleep(60)
@client.event
async def on_ready():
print(f'Logged in as {client.user}')
client.loop.create_task(update_channel_name())
client.run(TOKEN)