-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain_v2.py
399 lines (388 loc) · 20.9 KB
/
main_v2.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
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
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 sys
import urllib.request
import requests
from urllib.request import Request, urlopen
import json
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
import bot_ids
if __name__ == "__main__":
# main variables
bot_token = bot_ids.bot_token_real_first_half + bot_ids.bot_token_real_second_half
bot_id = bot_ids.bot_id_real
askar_id = 372010870756081675
bot_name = ""
bot_member = None
askar_member = None
askar_name = ""
last_fetch_time = ""
count = 0
guild_id = 769635647782256690
guild_p = "/r/Pennystocks"
guild_pp = "Playground"
app_id = 769265839584051200
# load up the coingecko, etherscan, and discord api's
load_dotenv()
db = discord_bot()
print(db.cg.ping())
def suggestSlash(slash_command):
embedResponse = discord.Embed(color = 0xF93A2F)
invite_link = "https://discord.com/api/oauth2/authorize?client_id=769265839584051200&permissions=416008371392&scope=bot%20applications.commands"
discord_rules = "https://support-dev.discord.com/hc/en-us/articles/4404772028055"
explanation = "We are transitioning to **slash commands** due to Discord rules. [Learn more](" + discord_rules + ")"
explanation2 = "1) Admins need to re-add the bot (no need to kick the bot) via this [link](" + invite_link + ")" + "\n" + "2) Use only slash commands. For this, " + slash_command
explanation3 = "[Join our discord](" + "https://discord.gg/QjUW5uspnA" + ") or message @Askar#1000"
embedResponse.add_field(name = "IMPORTANT changes for bot commands!", value = str(explanation), inline=False)
embedResponse.add_field(name = "How to avoid this warning?", value = explanation2, inline=False)
embedResponse.add_field(name = "Questions?", value = str(explanation3), inline=False)
try:
embedResponse.set_footer(text = "Powered by http://cryptobot.info", icon_url = bot_ids.twitter_logo_url)
except:
embedResponse.set_footer(text = "Powered by http://cryptobot.info")
return embedResponse
class MainBot(commands.Bot):
# initialize the bot
def __init__(self):
intents = discord.Intents.all()
super().__init__(command_prefix='?', intents = intents, application_id = app_id)
self.initial_extensions = [
'crypto_commands'
]
# add the background task
async def setup_hook(self):
self.background_task.start()
for ext in self.initial_extensions:
await self.load_extension(ext)
# create background loop to update bot information
@tasks.loop(seconds = 60)
async def background_task(self):
await self.wait_until_ready()
bot_list = []
global count
try:
# change presence globally
await self.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name= db.eth_status()))
# however, because we are restricted to changing usernames often
# we need to change nicknames which are a guild-by-guild basis
btc_status = db.btc_status()
for guild in self.guilds:
await guild.me.edit(nick = btc_status)
count += 1
global last_fetch_time
last_fetch_time = datetime.datetime.now()
except Exception as err:
print(err)
print("Unsuspected error")
print(datetime.datetime.now())
async def on_ready(self):
print("Ready!")
# create instance of bot class
bot_class = MainBot()
# do this to update all the guilds
@bot_class.command()
async def all_tree(ctx):
print("ran command")
for guild in bot_class.guilds:
bot_class.tree.copy_global_to(guild = discord.Object(id = guild.id))
await bot_class.tree.sync(guild = discord.Object(id = guild.id))
@bot_class.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_class.user:
return
# if message begins with "!"
if len(info) > 0 and info[0] == '!':
# parse out "!", and separate into string array
correct_check = False
command = info[1:]
str_divide = command.split()
if str_divide[0] == "all_tree":
for guild in bot_class.guilds:
try:
bot_class.tree.copy_global_to(guild = discord.Object(id = guild.id))
await bot_class.tree.sync(guild = discord.Object(id = guild.id))
print("updated for: ", guild.id)
except Exception as err:
print(err)
print("Did not add for: ", guild.id)
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);
correct_check = True
# 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}')
# correct_check = True
# 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)
warning = suggestSlash("`/chart2 [coin] [coin_2] [num_days]`")
await message.channel.send(embed = warning)
if line_output != "error":
await message.channel.send(file = discord.File('chart.png'), embed = line_output)
correct_check = True
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)
warning = suggestSlash("`/chart [coin] [num_days]`")
await message.channel.send(embed = warning)
if line_output != "error":
await message.channel.send(file = discord.File('chart.png'), embed = line_output)
correct_check = True
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'))
correct_check = True
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)
# warning = suggestSlash("`/chart [coin] [num_days]`")
# await message.channel.send(embed = warning)
if line_output != "error":
await message.channel.send(file = discord.File('chart.png'), embed = line_output)
correct_check = True
else:
await message.channel.send(embed = db.error())
correct_check = True
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_class, guild_p, message.author.id)
for coin in str_divide:
if coin != "list":
result = db.get_coin_price(coin)
correct_check = True
if result == "":
await message.channel.send(embed = db.error())
else:
await suggester.send(embed = db.get_coin_price(coin))
correct_check = True
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'))
correct_check = True
elif ctvl_output == "error":
await message.channel.send(embed = db.error())
else:
await message.channel.send(ctvl_output)
correct_check = True
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'))
correct_check = True
elif ctvl_output == "error":
await message.channel.send(embed = db.error())
else:
await message.channel.send(ctvl_output)
correct_check = True
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])
correct_check = True
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")
correct_check = True
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])
correct_check = True
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])
correct_check = True
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])
warning = suggestSlash("`/supply [coin]`")
await message.channel.send(embed = warning)
correct_check = True
if supply_output != "e":
await message.channel.send(embed = supply_output)
else:
await message.channel.send(embed = db.error())
elif str_divide[0] == "tvl-ratio":
warning = suggestSlash("`/tvl-ratio [coin]`")
await message.channel.send(embed = warning)
output = db.get_mcap_to_tvl_ratio(str_divide[1])
correct_check = True
await message.channel.send(embed = output)
elif str_divide[0] == "tvl":
warning = suggestSlash("`/tvl [coin]`")
await message.channel.send(embed = warning)
output = db.get_tvl(str_divide[1])
correct_check = True
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())
correct_check = True
elif command == 'future':
await message.channel.send(db.future())
correct_check = True
elif command == "crypto_gsb":
await message.channel.send("Running global sync!")
# bot_class.tree.copy_global_to()
return_val = await bot_class.tree.sync()
print(return_val)
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] == "crypto_some_trees":
print("ran command")
test_guilds= [769635647782256690, 297939923741310979]
for guild in test_guilds:
try:
# bot_class.tree.copy_global_to(guild = discord.Object(id = guild))
await bot_class.tree.sync(guild = discord.Object(id = guild))
print("Updated guild: ", guild)
except Exception as err:
print("Could not add guild: ", guild)
else:
result = db.get_coin_price(command)
if result != "":
correct_check = True
await message.channel.send(embed = db.get_coin_price(command))
warning = suggestSlash("`/c [coin]`")
await message.channel.send(embed = warning)
# else:
# await message.channel.send(embed = db.error())
# if correct_check:
# warning = suggestSlash()
# await message.channel.send(embed = warning)
return
bot_class.run(bot_token)