-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
360 lines (348 loc) · 18.2 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
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
# Below is the Main File that controls bot looping
# and message and command handling
# ....
# Imports
import bot_ids
import os
import bot_class
from bot_class import discord_bot
from dotenv import load_dotenv
import asyncio
import discord
import datetime
from discord.ext import tasks, commands
from discord.ext.tasks import loop
import urllib.request
import requests
from urllib.request import Request, urlopen
from guppy import hpy
import tracemalloc
if __name__ == "__main__":
# main variables
bot_token = bot_ids.bot_token_real
bot_id = bot_ids.bot_id_real
askar_id = 372010870756081675
guild_p = "/r/Pennystocks"
bot_name = ""
bot_member = None
askar_member = None
askar_name = ""
last_fetch_time = ""
last_contract = "tst"
# logging.basicConfig(filename="log.log", level=logging.INFO)
# load up the coingecko, etherscan, and discord api's
load_dotenv()
intents = discord.Intents.all()
bot = commands.Bot(command_prefix='!', intents = intents)
theHeap = hpy()
db = discord_bot()
print(db.cg.ping())
# main functions that need to run
@loop(seconds=60.0)
async def background_task():
try:
await bot.wait_until_ready()
bot_list = []
for guild in bot.guilds:
for member in guild.members:
if member.id == bot_id:
bot_member = member
bot_name = member.name
bot_list.append(bot_member)
if member.id == askar_id:
askar_member = member
askar_name = member.name
# update the name to the price of bitcoin and the status to the price of eth
# logging.info(db.cg.ping())
# update all the bot in each server
for bot_x in bot_list:
await bot_x.edit(nick = db.btc_status())
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name= db.eth_status()))
# logging.info("Finished Updating Bot")
# global last_fetch_time
# last_fetch_time = datetime.datetime.now()
except:
print("Unsuspected error")
print(datetime.datetime.now())
return
@bot.event
async def on_ready():
bot_list = []
bot_names = []
for guild in bot.guilds:
members = '\n - '.join([member.name for member in guild.members])
ids = [member.id for member in guild.members]
for member in guild.members:
if member.id == bot_id:
bot_member = member
bot_name = member.name
bot_list.append(bot_member)
bot_names.append(bot_name)
if member.id == askar_id:
askar_member = member
askar_name = member.name
bot_count = 0
print(f"{bot_names[0]} (x" + str(len(bot_names)) + ") has connected to Discord!")
# global last_fetch_time
# last_fetch_time = datetime.datetime.now()
return
@bot.event
async def on_message(message):
# retrieve message
info = message.content
useless_words = ["future", "bought", "ban", "mute", "sold", "undo", "rank", "tempmute", "whois"]
command = ""
info = info.lower()
# if message is from a bot, return
if message.author == bot.user:
return
# if message begins with "!"
if len(info) > 0 and info[0] == '!':
# parse out "!", and separate into string array
command = info[1:]
str_divide = command.split()
if len(str_divide) < 1:
return
# if user asks for help on commands
if command == "crypto-help" or command == "help" or command == "chelp":
embedResponse = discord.Embed(title = "CryptoBot Site", url = "http://cryptobot.info", color= 0x4E6F7B)
embedResponse.set_footer(text = "Powered by cryptobot.info")
await message.channel.send(embed = embedResponse);
# if user wants to send a suggestion
elif str_divide[0] == "suggestion" or str_divide[0] == "suggestions":
if len(str_divide) > 1:
user = db.find_member(bot, guild_p, askar_id)
suggester = db.find_member(bot, guild_p, message.author.id)
await user.send("suggestion" + " by " + suggester.name + ": " + command[11:])
suggester = db.find_member(bot, guild_p, message.author.id)
await suggester.send("```Your suggestion was sent```")
await message.add_reaction('\N{THUMBS UP SIGN}')
else:
await message.channel.send("```Invalid Suggestion: There was no suggestion```")
# if user requests a line chart of a coin
elif str_divide[0] == "chart":
if len(str_divide) == 4:
# line_output = db.get_line_chart_two(str_divide[1], str_divide[2],str_divide[3])
line_output = db.get_line_chart(str_divide[1], str_divide[2], str_divide[3], 2)
if line_output != "error":
await message.channel.send(file = discord.File('chart.png'), embed = line_output)
else:
await message.channel.send(embed = db.error())
# check for default and also make default for chart coin1 coin2
elif len(str_divide) == 3:
# check to see if theyre doing a normal one coin chart or nto
if str_divide[2].isdigit() or str_divide[2] == "max":
line_output = db.get_line_chart(str_divide[1], "", str_divide[2], 1)
if line_output != "error":
await message.channel.send(file = discord.File('chart.png'), embed = line_output)
else:
await message.channel.send(embed = db.error())
# if not, then they are trying to do default two coin chart
else:
line_dual_output = db.get_line_chart(str_divide[1], str_divide[2], "30", 2)
if line_dual_output == "":
await message.channel.send(file = discord.File('chart.png'))
else:
await message.channel.send(embed = db.error())
# if user doesn't specify num days, default to 30
elif len(str_divide) == 2:
line_output = db.get_line_chart(str_divide[1], "", "30", 1)
if line_output != "error":
await message.channel.send(file = discord.File('chart.png'), embed = line_output)
else:
await message.channel.send(embed = db.error())
else:
await message.channel.send(embed = db.error())
return
# if user requests candle chart of a coin
elif str_divide[0] == "list" and len(str_divide) > 2:
suggester = db.find_member(bot, guild_p, message.author.id)
for coin in str_divide:
if coin != "list":
result = db.get_coin_price(coin)
if result == "":
await message.channel.send(embed = db.error())
else:
await suggester.send(embed = db.get_coin_price(coin))
await message.add_reaction('\N{THUMBS UP SIGN}')
elif str_divide[0] == "tvl-chart" or str_divide[0] == "tvlc" or str_divide[0] == "ctvl":
if len(str_divide) == 3:
# line_output = db.get_line_chart_two(str_divide[1], str_divide[2],str_divide[3])
ctvl_output = db.get_tvl_chart(str_divide[1], "", str_divide[2], 1)
if ctvl_output == "":
await message.channel.send(file = discord.File('ctvl.png'))
elif ctvl_output == "error":
await message.channel.send(embed = db.error())
else:
await message.channel.send(ctvl_output)
elif len(str_divide) == 2:
ctvl_output = db.get_tvl_chart(str_divide[1], "", "1m", 1)
if ctvl_output == "":
await message.channel.send(file = discord.File('ctvl.png'))
elif ctvl_output == "error":
await message.channel.send(embed = db.error())
else:
await message.channel.send(ctvl_output)
elif str_divide[0] == "candle":
if len(str_divide) == 3 and str(str_divide[2]).isdigit():
candle_output = db.get_candle_chart(str_divide[1], str_divide[2])
if candle_output == "":
embedImage = discord.Embed(color=0x4E6F7B) #creates embed
embedImage.set_image(url="attachment://candle.png")
await message.channel.send(file = discord.File("candle.png"), embed = embedImage)
elif candle_output == "error":
await message.channel.send(embed = db.error())
else:
await message.channel.send(candle_output)
# if user doesn't specify num days, default to 30
elif len(str_divide) == 2:
candle_output = db.get_candle_chart(str_divide[1], "30")
if candle_output == "":
embedImage = discord.Embed(color=0x4E6F7B) #creates embed
embedImage.set_image(url="attachment://candle.png")
await message.channel.send(file = discord.File("candle.png"), embed = embedImage)
elif candle_output == "error":
await message.channel.send(embed = db.error())
else:
await message.channel.send(candle_output)
else:
await message.channel.send(embed = db.error())
# if user wants to check conversion rates
elif str_divide[0] == "convert":
if len(str_divide) == 4 and str(str_divide[1]).isdigit():
convert_output = db.get_conversion(str_divide[1], str_divide[2], str_divide[3])
if convert_output != "e":
await message.channel.send(embed = convert_output)
else:
await message.channel.send(embed = db.error())
elif len(str_divide) == 3:
convert_output = db.get_conversion(1, str_divide[1], str_divide[2])
if convert_output != "e":
await message.channel.send(embed = convert_output)
else:
await message.channel.send(embed = db.error())
else:
await message.channel.send(embed = db.error())
elif str_divide[0] == "supply":
supply_output = db.get_supply(str_divide[1])
if supply_output != "e":
await message.channel.send(embed = supply_output)
else:
await message.channel.send(embed = db.error())
elif str_divide[0] == "image":
image_output = db.get_image(str_divide[1])
if image_output != "e":
embedResponse = discord.Embed(title = image_output, color=0x4E6F7B) #creates embed
embedResponse.set_image(url="attachment://image.png")
await message.channel.send(file = discord.File("image.png"), embed = embedResponse)
else:
await message.channel.send(embed = db.error())
elif str_divide[0] == "ath" or str_divide[0] == "atl" or str_divide[0] == "range":
if str_divide[0] == "ath":
output = db.get_all_time("H", str_divide[1])
if output != "e":
await message.channel.send(embed = output)
else:
await message.channel.send(embed = db.error())
elif str_divide[0] == "atl":
output = db.get_all_time("L", str_divide[1])
if output != "e":
await message.channel.send(embed = output)
else:
await message.channel.send(embed = db.error())
elif str_divide[0] == "range":
output = db.get_all_time("R", str_divide[1])
if output != "e":
await message.channel.send(embed = output)
else:
await message.channel.send(embed = db.error())
elif str_divide[0] == "tvl-ratio":
print("in here")
output = db.get_mcap_to_tvl_ratio(str_divide[1])
await message.channel.send(embed = output)
elif str_divide[0] == "tvl":
output = db.get_tvl(str_divide[1])
await message.channel.send(embed = output)
# if user's request has more than one string, send error
elif len(str_divide) > 1:
# ignores commands about coins
for word in useless_words:
if str_divide[0] == word:
pass
# else:
# await message.channel.send(embed = db.error())
elif len(str_divide) == 1:
# if user wants events
# if command == "events":
# await message.channel.send(db.get_events())
# elif command == 'global':
# get_global_data()
# if user wants eth gas prices
if command == "gas":
if not (str(message.guild) == "/r/Pennystocks" or str(message.guild) == "Playground"):
await message.channel.send(embed = db.gas())
# if user wants to get the knowledge of shi's shitcoin
elif command == "fetch":
await message.channel.send(last_fetch_time)
elif command == "trendy":
await message.channel.send(embed = db.get_trending())
elif command == 'future':
await message.channel.send(db.future())
elif command == "rekt":
await message.channel.send(embed = db.get_rekt())
# if user wants info about global defi stats
elif command == 'global-defi':
await message.channel.send(db.get_global_defi_data())
elif command == "defisocks":
await message.channel.send("Unavailable")
db.get_ds()
embedResponse = discord.Embed(color=0x4E6F7B) #creates embed
embedResponse.add_field(name= "Defisocks", value = "Price and Supply of Defisocks", inline=False)
embedResponse.set_image(url="attachment://ds.png")
await message.channel.send(file = discord.File("ds.png"), embed = embedResponse)
# if user wants info about exchanges
elif command == 'list-exchanges':
await message.channel.send(db.get_list_exchanges())
elif command == 'grm-chart':
db.get_gmr()
embedResponse = discord.Embed(color=0x4E6F7B) #creates embed
embedResponse.add_field(name= "Golden Ratio Multiple Chart", value = "Multiple: Ma_350 * (1.6, 2, 3, 5, 8, 13, 21)", inline=False)
embedResponse.set_image(url="attachment://grm.png")
await message.channel.send(file = discord.File("grm.png"), embed = embedResponse)
elif command == 'mvrv-chart':
db.get_mvrv()
embedResponse = discord.Embed(color=0x4E6F7B) #creates embed
embedResponse.add_field(name= "MVRV Z-Score ", value = "Score: (Market_cap - realized_cap) / StdDev(Market_cap)", inline=False)
embedResponse.set_image(url="attachment://mvrv.png")
await message.channel.send(file = discord.File("mvrv.png"), embed = embedResponse)
elif command == 'puell-chart':
db.get_puell()
embedResponse = discord.Embed(color=0x4E6F7B) #creates embed
embedResponse.add_field(name= "Puell Multiple Chart", value = "Multiple: Daily Coin Insurrance / MA_365 (Daily Coin Insurrance)", inline=False)
embedResponse.set_image(url="attachment://puell.png")
await message.channel.send(file = discord.File("puell.png"), embed = embedResponse)
elif command == 'pi-chart':
db.get_pi()
embedResponse = discord.Embed(color=0x4E6F7B) #creates embed
embedResponse.add_field(name= "Pi Cycle Top Indicator Chart", value = "Value: MA_365*2 and MA_111", inline=False)
embedResponse.set_image(url="attachment://picycle.png")
await message.channel.send(file = discord.File("picycle.png"), embed = embedResponse)
# if user wants info about any coin
elif str_divide[0] == "servers":
result = db.get_servers(bot)
await message.channel.send(result)
elif str_divide[0] == "heap":
# result = db.get_heap(theHeap)
print(theHeap.heap())
await message.channel.send(theHeap.heap())
else:
result = db.get_coin_price(command)
if result != "":
await message.channel.send(embed = db.get_coin_price(command))
# else:
# await message.channel.send(embed = db.error())
return
# run background task and bot indefintely
background_task.start()
bot.run(bot_token)
print(theHeap.heap())