-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfishbot.py
514 lines (409 loc) · 16.9 KB
/
fishbot.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
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
print("Loading...")
#Discord
import discord
import discord.utils
from discord.ext import commands
from discord.ext import tasks
#Dependencies
from gtts import gTTS as gtts
import requests
import random
import os
#-----------------------------------------------------------------------------------#
# #
# ╔══════════════════════════════╗ #
# ║ ║ #
# ║Coding is it's own kind of art║ #
# ║ ║ #
# ║ Fish-art ║ #
# ║ ║ #
# ╚══════════════════════════════╝ #
# #
# ======== ====== #
# ========= ======== #
# ====================== #
# :==++++==================== #
# --=++++++++++++++++++++++++=== #
# +++++++++++++++++++++++++++==== #
# :+++++++++++++++++++++++++++++++++= #
# :-=++++++++++++++**********+++++++++= #
# =++++++++++++++**##########**+++++++= #
# ::=+++++++++++++*####******####+++++++= #
# ++++++++++++++++*####+====*####+++++++= #
# ++++++++++++++++*####*++++*####+++++++= #
# +++++++++++++++++**##########**+++++++= #
# +++++++++++++++++++**********+++++++++= #
# ++++++++++++++++++++++++++++++++++++++= #
# ++++++++++++++++++++++++++++++++++++++= #
# ++++++++++++++++++++++++++++++++++++++= #
# ++++++++++++++++++++++++++++++++++++++= #
# +++++++++++++++++++++++++++++++++++++= #
# ++++++++++++++++++++++++++++++++++++= #
# +++++++++++++++++++++++++++++++++++= #
# ++++++++++++++++++++++++++++++++++= #
# +++++++++++++++++++++++++++++++++= #
# ++++++++++++++++++++++++++++++= #
# ++++++++++++++++++++++++++++++= #
# +++++++++++++++++++++++++++++++++++++++ #
# -++++++++++++++++++++++++++++++++++++++++++= #
# .==++++++++++++++++++++++++++++++++++++++++++= #
# =+++++++++++++++++++++++++++++++++++++++++++++= #
# .+++++++++++++++++++++++++ +++++++++++++++++++= #
# .+++++++++++++++++++++++ ++++++++++++++++= #
# .+++++++++++++++++++ .++++++= #
# .-+++++++++++++ ..++++= #
# #
#-----------------------------------------------------------------------------------#
#Global Variables
prefix = '-'
bot = commands.Bot(command_prefix = prefix)
bot.queue = []
bot.queueing = 0
bot.read_channel = {''}
bot.voices = {404650697183723530: 'en'}
# List of all element emojis
bot.elements_emoji = [
'<:fire_element:848956850875793440>',
'<:water_element:848956903270121483>',
'<:earth_element:848956867357966346>',
'<:arcane_element:848956818516082698>',
'<:goo_element:848956888153849857>',
]
# List of all element combinations with names
bot.classes = {
"0":"Fire",
"1":"Water",
"2":"Earth",
"3":"Arcane",
"4":"Goo",
"00":"Fireball",
"01":"Push",
"02":"Meteor",
"03":"Fireblast",
"04":"Goo Flame",
"11":"Frost Ray",
"12":"Dive",
"13":"Frost Orb",
"14":"Heal",
"22":"Rock Dash",
"23":"Invincibility",
"24":"Totem",
"33":"Arcane Shield",
"34":"Goo Beam",
"44":"Grab",
"012": "Classic Fishard",
"013": "Skillshot Simon",
"014": "Baby Fancy",
"023": "Huntin' Henry",
"024": "Brawlin' Bob",
"034": "Franz Flammenwerfer",
"123": "Slippery Sam",
"124": "Camping Carl",
"134": "Snipin Snyder",
"234": "Hidin' Harry",
"1234": "Fireless Fred",
"0234": "Waterless Walter",
"0134": "Earthless Eric",
"0124": "Arcanaless Angela",
"0123": "Gooless Gary",
"01234": "Sensei",
}
bot.langs = {
"af": "Afrikaans",
"ar": "Arabic",
"bg": "Bulgarian",
"bn": "Bengali",
"bs": "Bosnian",
"ca": "Catalan",
"cs": "Czech",
"cy": "Welsh",
"da": "Danish",
"de": "German",
"el": "Greek",
"en": "English",
"eo": "Esperanto",
"es": "Spanish",
"et": "Estonian",
"fi": "Finnish",
"fr": "French",
"gu": "Gujarati",
"hi": "Hindi",
"hr": "Croatian",
"hu": "Hungarian",
"hy": "Armenian",
"id": "Indonesian",
"is": "Icelandic",
"it": "Italian",
"ja": "Japanese",
"jw": "Javanese",
"km": "Khmer",
"kn": "Kannada",
"ko": "Korean",
"la": "Latin",
"lv": "Latvian",
"mk": "Macedonian",
"ml": "Malayalam",
"mr": "Marathi",
"my": "Myanmar (Burmese)",
"ne": "Nepali",
"nl": "Dutch",
"no": "Norwegian",
"pl": "Polish",
"pt": "Portuguese",
"ro": "Romanian",
"ru": "Russian",
"si": "Sinhala",
"sk": "Slovak",
"sq": "Albanian",
"sr": "Serbian",
"su": "Sundanese",
"sv": "Swedish",
"sw": "Swahili",
"ta": "Tamil",
"te": "Telugu",
"th": "Thai",
"tl": "Filipino",
"tr": "Turkish",
"uk": "Ukrainian",
"ur": "Urdu",
"vi": "Vietnamese",
"zh-CN": "Chinese"
}
#-------------------------------------------------------------------------------------------
#Functions
def save(text, lang: str = 'en'):
try: gtts(text, lang = lang).save('gtts.mp3')
except: gtts("Error", lang = lang).save('gtts.mp3')
def queue_player(ctx):
if bot.queue:
voice = voice = discord.utils.get(bot.voice_clients, guild=ctx.guild)
if voice and voice.is_connected():
text, id = bot.queue[0]
lang = bot.voices.setdefault(id, 'en')
save(text, lang)
voice.play(discord.FFmpegPCMAudio('gtts.mp3', **{'before_options': ('-channel_layout mono'), 'options': ('-vn', '-loglevel quiet')} ), after = lambda e: After(ctx), )
else:
bot.queue.pop(0)
bot.queueing = 0
else: bot.queueing = 0
def play_queue(ctx):
if not bot.queueing:
if discord.utils.get(bot.voice_clients, guild=ctx.guild):
bot.queueing = 1
queue_player(ctx)
def After(ctx):
bot.queue.pop(0)
queue_player(ctx)
def Player_Count(): #returns amount of people currently playing Fishards
headers = {"Client-ID": "F07D7ED5C43A695B3EBB01C28B6A18E5"}
appId = '1637140' #Fishards
url = 'https://api.steampowered.com/ISteamUserStats/GetNumberOfCurrentPlayers/v1/?format=json&appid=' + appId
game_players = requests.get(url, headers=headers)#request people currently playing the game
return (str(game_players.json()['response']['player_count']))
#-------------------------------------------------------------------------------------------
#Commands
@bot.command(aliases=['coin','flop'], description='''
flips a coin and gives you heads or tails
''')
async def flip(ctx):
coin = random.getrandbits(1) #Roll Number Between 0 and 1
if coin: #if 1 its head
await ctx.channel.send("Wizard Heads")
else:
await ctx.channel.send("Fish Tails")
@bot.command(pass_context=True, description='''
gives you random number between 1 and 6
''')
async def roll(ctx, sides: int = 6):
if sides < 1: sides = 1
roll = random.randint(1, sides)#roll a number between 1 and intidure
await ctx.send(f'Fish God of Randomenss Rolled You a {roll}!')
@bot.command(description='''
Displays current count of players in Fishards
''')
async def players(ctx):
await ctx.channel.send(f'Current Player Count: {Player_Count()}')
@bot.command(aliases=['suggestion', 'suggest', 'pool', 'vote'], description='''
Makes a poll in which people can vote
''')
async def poll(ctx, text):
#find first space in message and add everything after it to variable
#because passing variables trough commands is wired
text = ctx.message.content
text = text[text.find(" "):]
Embed = discord.Embed(colour = 0xFF0000)
Embed.set_author(name=f'Poll by {ctx.message.author}', icon_url = f'{ctx.author.avatar_url}')
Embed.add_field(name = 'They are asking: ', value = f'{text.title()}')
message = await ctx.channel.send(embed=Embed)
await message.add_reaction('👍')
await message.add_reaction('👎')
@bot.command(aliases=['randclass','randomelement','randelement','randelem','randomspell','randspell', 'r'], description='''
Gives you random class, spell or element
''')
async def randomclass(ctx, amount: int = 3, elements = None):
#check if variable is in acceptable range, else make it acceptable
if amount > 5: amount = 5
elif amount < 1: amount = 1
#find first space in message and add everything after it to variable
#because passing variables trough commands is wired
elements = ctx.message.content
elements = elements[elements.find(" "):]
elements = elements[elements.find(" "):]
#split emojis into list
elements = elements.replace('><', '> <')
elements = elements.split()
#remove dublicates if its a class
if amount > 2:
elements = list(dict.fromkeys(elements))
#variables
text = ''
fclass = []
breaker = 0
amount_decrease = 0
#convert emojis into number ids
for element in elements:
num = -1
for emoji in bot.elements_emoji:
num += 1
if element == emoji:
fclass.append(num) #save element numbers to list
amount_decrease += 1
if not amount: breaker = 1; break
if breaker: break
#make a list of random numbers between 0 and 4
for i in range(amount-amount_decrease):
while 1:
num = random.randint(0,4)
if num in fclass and amount > 2: #check if numbe was already rolled | unless we are randomizing spell
None
else:
fclass.append(num) #add number to the list of numbers
break
fclass.sort() #sort numbers so they are in right element order
#add class name to message
fclass_str = ''
for i in fclass: #convert list to str of numbers
fclass_str += str(i)
try: #find class in global bot.classes
text += bot.classes[fclass_str] + " "
if amount > 2: text += '\n'
except KeyError: None
#make a message with emojis out of number list
for element in fclass:
text += bot.elements_emoji[element]
await ctx.channel.send(text)
@bot.command(aliases=['defind','search','class','spell','name','f'], description='''
Displays name of class, spell or element
''')
async def find(ctx, text: str = '<:fire_element:848956850875793440><:water_element:848956903270121483><:earth_element:848956867357966346>'):
#find first space in message and add everything after it to variable
#because passing variables trough commands is wired
text = ctx.message.content
text = text[text.find(" "):]
old_text = text.replace(" ", "")
#split emojis into list
text = text.replace('><', '> <')
text = text.split()
fclass = ''
#complare emojis from list with saved emoji list\
for element in text:
num = -1
for emoji in bot.elements_emoji:
num += 1
if element == emoji:
fclass += str(num) #save element numbers to variable
#Send Class Name if it exist
try: await ctx.channel.send(f'{bot.classes[fclass]} {old_text}')
except KeyError: await ctx.channel.send(f"{old_text} Not Found")
"""
@bot.command(description='''
Sends link to Fishards Wikipedia
''')
async def wiki(ctx, page: str = 'Home'):
await ctx.channel.send('https://fishards.fandom.com/wiki/'+page)
"""
#-------------------------------------------------------------------------------------------
@bot.command()
async def join(ctx):
voice = discord.utils.get(bot.voice_clients, guild=ctx.guild)
if voice and voice.is_connected(): await voice.disconnect()
if ctx.author.voice: voice = ctx.author.voice.channel
else: voice = 0
if voice:
await voice.connect()
await ctx.channel.send(f"Joined {voice}")
else: await ctx.channel.send("You Are Not In A Voice Channel")
@bot.command()
async def leave(ctx):
voice = discord.utils.get(bot.voice_clients, guild=ctx.guild)
if voice and voice.is_connected(): await voice.disconnect()
else: await ctx.channel.send("Not Connected To Voice Channel")
@bot.command()
async def stop(ctx, num: int = 1):
if num < 0:
num = 1
elif num > len(bot.queue) or not num:
num = 0
bot.queue = []
bot.queueing = 0
for i in range(num - 1): bot.queue.pop(0)
voice = discord.utils.get(bot.voice_clients, guild=ctx.guild)
if voice and voice.is_playing(): voice.stop()
@bot.command()
async def tts(ctx, text):
text = text.lower()
if text in ['2', 'all']:
for channel in ctx.guild.text_channels:
bot.read_channel.add(channel)
await ctx.send('Global TTS ON')
elif text in ['1', 'on']:
bot.read_channel.add(ctx.channel)
await ctx.send(f"TTS ON in {ctx.channel}")
elif text in ['0', 'off']:
try:
bot.read_channel.remove(ctx.channel)
await ctx.send(f"TTS OFF in {ctx.channel}")
except Exception as e:
await ctx.send(f"TTS Was NOT ON in {ctx.channel}")
elif text in ['-1', 'clear', 'stop']:
bot.read_channel = {''}
await ctx.send("TTS OFF")
@bot.command(aliases = ['lang'])
async def language(ctx, text: str = 'en'):
if text in bot.langs:
bot.voices[ctx.author.id] = text
await ctx.send(f'Set Your Language as {text.upper()}')
else:
await ctx.send(f'{text.upper()} Is Not a Correct Code')
@bot.command()
async def failsafe(ctx):
bot.queueing = 0
bot.queue = []
discord.utils.get(bot.voice_clients, guild=ctx.guild).stop()
#-------------------------------------------------------------------------------------------
#Events
@bot.event
async def on_ready():
print(f'Logged in as {bot.user}')
TimedStatus.start()
@bot.event
async def on_message(ctx):
if (ctx.author != bot.user):
if (ctx.content != None):
if not('http' in ctx.content) and not(str(ctx.content)[0] in '!@#$%-+=<') and (ctx.channel in bot.read_channel):
if discord.utils.get(bot.voice_clients, guild=ctx.guild):
bot.queue.append((ctx.content, ctx.author.id))
play_queue(ctx)
else:
bot.read_channel = {''}
await bot.process_commands(ctx)
bot.savePlayers = '-1'
@tasks.loop(minutes = 1)
async def TimedStatus(): #Change Status to a Random one Each Hour
players = Player_Count()
if players != bot.savePlayers:
bot.savePlayers = players
text = f'with {players} Players in Fishards'
await bot.change_presence(activity=discord.Game(name = text))
#-------------------------------------------------------------------------------------------
bot.run(os.environ['TOKEN'])