async def emoji(client, text, channel, message='NONE'): text[0] = text[0].replace(':', '').replace('~1', '') if text[0] == 'carbot': await carbotSpray(text[1], channel) return if text[0] == 'proxy': await channel.send('Use these proxied emojis with [:emojiName]') hiddenEmojis = ['wheeze', 'volumeup'] await channel.send(''.join([ i[1] for i in client.proxyEmojis.items() if i[1].split(':')[1] not in hiddenEmojis ])) return if text[0] in client.proxyEmojis: if len(text) == 2: await proxyReact(client, text, message) else: await channel.send(client.proxyEmojis[text[0]]) return if len(text) == 2: hero = aliases(text[0]).replace('_', ' ').replace('The Butcher', 'Butcher') emojiCode = text[1].replace('lol', 'rofl').replace( 'wow', 'surprised').replace('smile', 'happy') file = hero + ' ' + emojiCode else: file = text[0] await sendEmoji('Emojis/' + file.capitalize(), channel)
async def carbotSpray(hero, channel): hero = aliases(hero) imageFormat = '.gif' if hero == 'Deflect': hero = 'Ninja_Skills' elif hero == 'Parry': hero = "Paryin'_with_Varian" elif hero == 'Evade': hero = 'Evade_This...' elif hero == 'Haha': hero = 'Ha_HA_ha_HA!' elif hero == 'Sleep': hero = 'Sleeping_Dragon' elif hero == 'Shield': hero = "Can't_Touch_This" else: hero = 'Carbot_' + hero imageFormat = '.png' emojiPage = 'https://heroesofthestorm.gamepedia.com/File:' + hero + '_Spray' + imageFormat html = urlopen(emojiPage) bs = BeautifulSoup(html, 'html.parser') images = bs.find_all('img', {'src': re.compile(imageFormat)}) emojiImagePage = images[1 if imageFormat == '.gif' else 2]['src'] async with aiohttp.ClientSession() as session: async with session.get(emojiImagePage) as resp: if resp.status != 200: pass data = io.BytesIO(await resp.read()) await channel.send(file=discord.File(data, 'cool_image' + imageFormat))
async def printBuild(client,channel,text): build,hero=text.split(',')#Example: T0230303,DVa hero=aliases(hero) (abilities,talents)=client.heroPages[hero] build=build.replace('q','1').replace('w','2').replace('e','3').replace('r','4').replace('t','5') output=[] for j,i in enumerate(build[1:]): if i=='0':continue output.append(talents[j][int(i)-1]) await printLarge(channel,'\n'.join(output))
async def downloadHero(hero, client, patch): async with aiohttp.ClientSession() as session: if patch == '': page = await fetch( session, 'https://raw.githubusercontent.com/heroespatchnotes/heroes-talents/master/hero/' + hero + '.json') else: page = await fetch( session, 'https://raw.githubusercontent.com/MGatner/heroes-talents/' + patch + '/hero/' + hero + '.json') page = loads(page) abilities = [] if hero in ['ltmorales', 'valeera', 'deathwing', 'zarya']: resource = 'energy' elif hero == 'chen': resource = 'brew' elif hero == 'sonya': resource = 'fury' else: resource = 'mana' for i in page['abilities'].keys(): for ability in page['abilities'][i]: if 'hotkey' in ability: output = '**[' + ability['hotkey'] + '] ' else: output = '**[D] ' output += ability['name'] + ':** ' if 'cooldown' in ability or 'manaCost' in ability: output += '*' if 'cooldown' in ability: output += str(ability['cooldown']) + ' seconds' if 'manaCost' in ability: output += ', ' if 'manaCost' in ability: output += str(ability['manaCost']) + ' ' + resource output += ';* ' output += await descriptionFortmatting(ability['description']) output = await fixTooltips(hero, ability['name'], output) abilities.append(output) if hero == 'samuro': abilities.append( "**[D] Image Transmission:** *14 seconds;* Activate to switch places with a target Mirror Image, removing most negative effects from Samuro and the Mirror Image.\n**Advancing Strikes:** Basic Attacks against enemy Heroes increase Samuro's Movement Speed by 25% for 2 seconds." ) talents = [] keys = sorted(list(page['talents'].keys()), key=lambda x: int(x)) for key in keys: tier = page['talents'][key] talentTier = [] for talent in tier: output = '**[' + str( int(key) - 2 * int(hero == 'chromie' and key != '1')) + '] ' output += talent['name'] + ':** ' if 'cooldown' in talent: output += '*' + str(talent['cooldown']) + ' seconds;* ' output += await descriptionFortmatting(talent['description']) output = await fixTooltips(hero, talent['name'], output) talentTier.append(output) talents.append(talentTier) try: client.heroPages[aliases(hero)] = (abilities, talents) except (Exception): print('y')
async def main(client, message, texts): global exitBool for draftAlias in draftAliases: if 'new' in message.content.lower(): continue if '[' + draftAlias + '/' in message.content.lower(): break else: channelName = message.channel.name loggingMessage = channelName + ' ' + ' ' * (17 - len(channelName)) + str( message.author.name) + ' ' * (18 - len(str(message.author.name))) + ' ' + message.content await client.get_channel(DiscordChannelIDs['LoggingChannel']).send('`{}`'.format(loggingMessage)) for text in texts: command = text[0].replace(' ', '') if command in ['trait', 'r', 'w', 'e', 'passive', 'react', '...']: continue # if command in ['event']: # await event(message.channel) # continue if command in ['armor', 'armour', 'ehp']: print(3) await message.channel.send('https://cdn.discordapp.com/attachments/741762417976934460' '/801905601809612821/unknown.png') continue if command == 'hoggerangles': print(4) await message.channel.send('https://editor.p5js.org/Asddsa76/sketches/CmGYMS2j1') continue if command in ['schedule', 'patchschedule']: print(5) await schedule(message) continue if command == 'sortlist': print(6) await sortList(message) continue if command in heroAliases + [i + 's' for i in heroAliases]: print(7) await heroes(message, text, message.channel, client) continue if command == 'ping': print(8) await ping(message.channel) continue if command == 'membercount': print(9) await memberCount(message.channel) continue if command in confidenceAliases: print(10) await confidence(message.channel, text) continue if command == 'exit' and message.author.id == DiscordUserIDs['TheCaptain']: print(11) exitBool = 1 await client.close() if command in restartAliases: print(12) exitBool = 0 await client.logout() if command in mapImageAliases: print(13) await mapImage(message.channel, text[1]) continue if command == 'core': print(14) await coreAbilities(message.channel, await mapAliases(text[1])) continue if command in listAliases: print(15) await waitList(message, text, client) continue if command in lfgAlises: await lfg(message.channel, text[1], client) continue # if command in deleteAliases: # print(17) # await deleteMessages(message.author, text[1], client) # continue if command in patchNotesAliases: await patchNotes(message.channel, text) continue if command in talentAliases: await message.channel.send("Call a hero's talent tier with [hero/level]") continue if command in rollAliases: await roll(text, message) continue if command == 'sort': await sortFromMessage(text[1], message, client) continue if command in ['season', 'seasons']: if command == 'season': await message.channel.send(get_current_season()) continue if command == 'seasons': await message.channel.send(get_seasons()) continue if command == 'roster': rosterPath = './app/data/roster.json' players = get_roster(rosterPath) df = pd.DataFrame(players) string = """ ``` {players} ``` """.format(players=df) print(string) await message.channel.send(string) continue if command == ':disapproval': print(22) await message.channel.send('ಠ_ಠ') continue if command == ':summon': print(23) if len(text) == 1: await message.channel.send('༼ つ ◕\_◕ ༽つ') elif '@' in text[1]: await message.channel.send('{0} {0} Summon {1}! {0} {0}'.format('༼ つ ◕\_◕ ༽つ', message.author.mention)) else: # text[1] is all lowercase etc. await message.channel.send('{0} {0} Summon {1}! {0} {0}'.format('༼ つ ◕\_◕ ༽つ', message.content.split('[')[1].split( '/')[1].split(']')[0])) continue if message.author.id == DiscordUserIDs['TheCaptain']: if command == 'repeat' and len(text) == 2: await message.channel.send(text[1]) await message.delete() continue if command == 'vote': print(26) await vote(message, text) continue if command in coinsAliases: print(27) await message.channel.send(random.choice(['Heads', 'Tails'])) continue if command in redditAliases: print(28) await reddit(client, message, text) continue if command in ['avatar', 'a']: print(29) await message.channel.send(await getAvatar(client, message.channel, text[1])) continue if command == '': print(30) continue if command in draftAliases: print(31) await draft(drafts, message.channel, message.author, text, lastDraftMessageDict, draftNames) continue if command in randomAliases: print(32) if len(text) == 1: await message.channel.send(getQuote(random.choice(getHeroes()))) continue command = random.choice(getHeroes()) if command in helpAliases: print(33) if len(text) == 2 and command in heroStatsAliases: # [info/hero] await heroStats(aliases(text[1]), message.channel) else: await message.channel.send(helpMessage()) continue if command in buildsAliases: print(34) if len(text) == 2: await message.channel.send("Elitesparkle's builds: <https://elitesparkle.wixsite.com/hots-builds>") continue if command in rotationAlises: print(35) await rotation(message.channel) continue if command == 'goodbot': print(36) await emoji(client, ['Probius', 'love'], message.channel) continue if command == 'badbot': print(37) if message.author.id in ProbiusPrivilegesIDs: await emoji(client, ['Probius', 'sad'], message.channel) else: await emoji(client, [':pylonbat'], message.channel) continue if ':' in command: print(38) await emoji(client, text, message.channel, message) continue if ']' in command: print(39) continue if command in ['chogall', "cho'gall", 'cg', 'cho gall', 'cho-gall']: print(40) await message.channel.send("Cho and Gall are 2 different heroes. Choose one of them") print('Dual hero') continue if command in quotesAliases: print(41) if len(text) == 2: if aliases(text[1]): print(aliases(text[1])) await message.channel.send(getQuote(aliases(text[1]))) # Calling [q] alone shouldn't show link, but [q/hero] works, as well as [quotes] elif text[0] != 'q': await message.channel.send( 'All hero select quotes: <https://github.com/Asddsa76/Probius/blob/master/quotes.txt>') continue if command in aliasesAliases: print(42) await message.channel.send( 'All hero alternate names: <https://github.com/Asddsa76/Probius/blob/master/aliases.py>') continue if command == 'all': print(43) await printAll(client, message, text[1], True) continue if command in emojiAliases: print(44) await message.channel.send( 'Emojis: [:hero/emotion], where emotion is of the following: happy, lol, sad, silly, meh, angry, cool, oops, love, or wow.') continue try: # [t3221323,sam] if len(text) == 1 and command[0] == 't' and command[8] == ',': await printBuild(client, message.channel, command) continue # [t3221323/sam] if len(text) == 2 and command[0] == 't' and len(command) == 8 and command != 'tassadar': await printBuild(client, message.channel, ','.join(text)) continue except: pass hero = command hero = aliases(hero) output = '' # Patch notes have abilities in []. Don't want spammed triggers again. Numbers for R1, R2, etc. if len(hero) == 1 or (len(hero) == 2 and ('1' in hero or '2' in hero)): continue if len(text) == 2: # If user switches to hero first, then build/quote if text[1] in buildsAliases: await guide(hero, message.channel) continue if text[1] in quotesAliases and text[1] != 'q': await message.channel.send(getQuote(hero)) continue if text[1] in heroStatsAliases: await heroStats(hero, message.channel) continue try: (abilities, talents) = client.heroPages[hero] except: try: await printAll(client, message, text[0]) except: pass continue try: # If there is no identifier, then it throws exception tier = text[1] if tier in randomAliases: await message.channel.send(printTier(talents, random.randint(0, 6))) return except: quote = getQuote(hero) output = '\n'.join(abilities) await printLarge(message.channel, quote + output) await heroStats(hero, message.channel) continue if output == '': if tier.isdigit(): # Talent tier tier = int(tier) # Talents for Chromie come 2 lvls sooner, except lvl 1 output = printTier(talents, int(tier / 3) + int(hero == 'Chromie' and tier not in [1, 18])) elif tier in ['mount', 'z']: await message.channel.send(printAbility(abilities, 'z')) return elif tier == 'extra': await message.channel.send(printAbility(abilities, '1')) return elif tier == 'r': # Ultimate if hero == 'Tracer': # She starts with her heroic already unlocked, and only has 1 heroic output = abilities[3] else: output = printTier(talents, 3 - 2 * int(hero == 'Varian') ) # Varian's heroics are at lvl 4 if hero == 'Deathwing': # Deathwing has Cataclysm baseline output = abilities[3] + '\n' + output elif len(tier) == 1 and tier in 'dqwe': # Ability (dqwe) output = printAbility(abilities, tier) elif tier == 'trait': output = printAbility(abilities, 'd') elif tier in wikipageAliases: # Linking user to wiki instead of printing everything await message.channel.send('<https://heroesofthestorm.gamepedia.com/Data:' + hero + '#Skills>') continue else: output = await printSearch(abilities, talents, tier, hero, True) if len(output) == 2: # If len is 2, then it's an array with output split in half if message.channel.name == 'rage': await message.channel.send(output[0].upper()) await message.channel.send(output[1].upper()) else: await message.channel.send(output[0]) await message.channel.send(output[1]) else: if message.channel.name == 'rage': output = output.upper() try: await message.channel.send(output) except: if output == '': try: # If no results, it's probably an emoji with : forgotten. Prefer to call with : to avoid loading abilities and talents page await emoji(client, [hero, tier], message.channel) continue except: pass if message.channel.name == 'rage': await message.channel.send('ERROR: {} DOES NOT HAVE "{}".'.format(hero, tier).upper()) else: await message.channel.send('Error: {} does not have "{}".'.format(hero, tier)) print('No results') else: if message.channel.name == 'rage': await printLarge(message.channel, output.upper()) else: await printLarge(message.channel, output)
async def printDraft(drafts, channel, draftList, lastDraftMessageDict, draftNames): #Print state, and the next action to be done if channel.id not in drafts: await channel.send(channel.id + ' does not currently have an active draft.') return if not draftList: await channel.send('Pick a map') return #Order and map have been picked now order = 'mABABabbaaBAbbaab' #map, order. AB bans, ab picks bansA = [] bansB = [] picks = '' #whitespaceAmount=32 try: whitespaceAmount = await getWhiteSpaceLength(draftList, draftNames[channel.id][0]) except: whitespaceAmount = await getWhiteSpaceLength(draftList, '') teamA = 'Team A' teamB = 'Team B' try: teamA += ' (' + draftNames[channel.id][0] + ')' teamB += ' (' + draftNames[channel.id][1] + ')' except: pass for i in range(1, len(draftList)): if order[i] == 'A': bansA.append(draftList[i]) elif order[i] == 'B': bansB.append(draftList[i]) elif order[i] == 'a': picks += draftList[i] + '\n' elif order[i] == 'b': picks += ' ' * whitespaceAmount + draftList[i] + '\n' output = '```Map: ' + draftList[0] + '\n\n' output += teamA + ' ' * (whitespaceAmount - len(teamA)) + teamB + '\n' output += 'Bans: ' + ' ' * (whitespaceAmount - 6) + 'Bans: \n' output += ', '.join( bansA) + ' ' * (whitespaceAmount - len(', '.join(bansA))) + ', '.join( bansB) + '\n' + '-' * (whitespaceAmount + 15) + '\n' output += 'Picks:' + ' ' * (whitespaceAmount - 6) + 'Picks:\n' + picks + '\n' completeDraft = 0 if len(draftList) == 17: output += 'Draft complete' completeDraft = 1 else: nextAction = order[len(draftList)] nextTurnIsTeamB = 1 if nextAction.lower() == 'a': output += '<---------- ' nextTurnIsTeamB = 0 if nextAction == nextAction.upper(): nextAction = 'BAN for team ' + nextAction else: nextAction = 'Pick for team ' + nextAction.upper() output += 'Next action: ' + nextAction try: output += ' (' + draftNames[channel.id][nextTurnIsTeamB] + ')' except: pass if nextTurnIsTeamB: output += ' ---------->' if len(draftList) > 1: hero = aliases(draftList[-1]).replace('_', ' ').replace( 'The Butcher', 'Butcher').capitalize() fileName = '' fileExtension = '.PNG' if hero == 'Maiev' else '.png' if len(draftList) in [2, 3, 4, 5, 11, 12]: #Numbers are the bans if hero in banEmojis.keys(): output = banEmojis[hero] + '\n' + output else: if channel in lastDraftMessageDict: try: await lastDraftMessageDict[channel].delete() except: pass lastDraftMessageDict[channel] = await channel.send( output + '```', file=discord.File('Emojis/' + hero + ' sad' + fileExtension)) return else: if channel in lastDraftMessageDict: try: await lastDraftMessageDict[channel].delete() except: pass lastDraftMessageDict[channel] = await channel.send( output + '```', file=discord.File('Emojis/' + hero + ' happy' + fileExtension)) await addCompleteReactions(completeDraft, lastDraftMessageDict[channel]) return if channel in lastDraftMessageDict: try: await lastDraftMessageDict[channel].delete() except: pass lastDraftMessageDict[channel] = await channel.send(output + '```') await addCompleteReactions(completeDraft, lastDraftMessageDict[channel])
async def draft(drafts, channel, member, text, lastDraftMessageDict, draftNames, printDraftBool=True): try: draftList = drafts[channel.id] except: drafts[channel.id] = [] draftList = drafts[channel.id] if len(text) == 2: if text[1] in ['help', 'info']: output = '''MOCK DRAFTING GUIDE [Draft] will show the current state of the draft. [Flip] will toss a coin that can be used to randomly select who will go for first pick or Map choice after writing your head or tail preference in chat. [Draft/<Map>] will set the Map at the beginning of the draft. [Draft/<Hero>] will pick or ban a Hero based on the in-game drafting order. [Draft/<Command>] will let you use a Command listed below. Commands: - "Help" will show this guide. - "Reset" will reset the draft. - "Undo" will revert the previous input.''' await channel.send(output) return if await mapAliases(text[1] ) in await getMaps() and len(draftList) in [0, 17]: drafts[channel.id] = [] draftList = drafts[channel.id] if channel in lastDraftMessageDict: del lastDraftMessageDict[channel] battleground = await mapAliases(text[1]) draftList.append(await mapString(battleground)) await channel.send('New draft started!') await mapImage(channel, battleground) draftNames[channel.id] = [] if printDraftBool: await printDraft(drafts, channel, draftList, lastDraftMessageDict, draftNames) return if len(text) == 1: #[draft] with no second part. To call status await printDraft(drafts, channel, draftList, lastDraftMessageDict, draftNames) return text = text[1] if text.count(','): for i in text.split(','): await draft(drafts, channel, member, ['d', i], lastDraftMessageDict, draftNames, False) await channel.send('Draft filled! Type [d] to view') return if text in ['new', 'start', 'n', 's', 'reset', 'r']: drafts[channel.id] = [] if channel in lastDraftMessageDict: del lastDraftMessageDict[channel] await channel.send('New draft started! Choose map') draftNames[channel.id] = [] return if text in ['undo', 'u']: await channel.send('Undid ' + draftList.pop()) elif len(draftList) < 17: if len(draftList) == 1: draftNames[channel.id] = [member.nick or member.name] elif len(draftList) == 2: draftNames[channel.id].append(member.nick or member.name) if simplifyName(aliases(text)) in draftList: await channel.send( simplifyName(aliases(text)) + ' has already been picked/banned. Choose another!') return else: if len(draftList) == 0: #Map name doesn't need check try: battleground = await mapAliases(text) except: await channel.send('`Unrecognized battleground!`') return draftList.append(await mapString(battleground)) await mapImage(channel, battleground) else: hero = aliases(text) if hero in getHeroes(): draftList.append(simplifyName(hero)) else: await channel.send('Invalid hero!') return if printDraftBool: await printDraft(drafts, channel, draftList, lastDraftMessageDict, draftNames)
async def patchNotes(channel, text): if len(text) != 2: await channel.send( 'Use with [patchnotes/hero,X], where X is number of patches ago, or a search term.' ) return async with channel.typing(): text = text[1] splitText = text.split(',') hero = aliases(splitText.pop(0)).replace('ú', 'u').lower().translate( {ord(i): None for i in "' _-."}).replace('thebutcher', 'butcher') async with aiohttp.ClientSession() as session: page = await fetch( session, 'https://heroespatchnotes.com/hero/' + hero + '.html') patches = page.split('<h3>') if splitText: text = splitText.pop(0) if text.isdigit(): if int(text) < len(patches): patch = patches[int(text)] else: await channel.send("The hero doesn't have " + text + ' patches yet.') return else: for trialPatch in patches[1:]: if text.lower() in trialPatch.lower(): patch = trialPatch break else: await channel.send('That has never been changed!') return else: patch = patches[1] remove = [ '<small class="hidden-xs">', ' ', '<li>', '<p>', '<em>', '</li>', '</p>', '</em>', '</ul>', '<blockquote>', '</blockquote>', '<span class="text-warning">', 'amp;' ] for i in remove: patch = patch.replace(i, '') output = '**' + patch.split('<')[0] + '**' #Date and version patch = '>'.join(patch.split('<h4')[1].split('>')[1:]) #output+=patch.split('<')[0]+':' #Type (bug fix, hero update) patch = '>'.join(patch.split('>')[1:]) patch = patch.split('</div>')[0] patch = patch.replace('\n', ' ').replace( '<strong>Developer Comment:</strong> ', '\n***Developer Comment***: *').replace( '<strong>', '\n**').replace('</strong>', ':** ').replace('<ul>', ' ') patch = patch.replace('\n**Talents:**', '').replace( '\n**Abilities:**', '').replace('**Stats:**', '').replace(' Health Regen ', ', Health Regen ') if '</span> <a class="label label-warning"' in patch: #Undocumented HTML patch = patch.split('</span> <a class="label label-warning"') patch = '\n'.join([patch[0]] + [ i.split( 'Undocumented <i class="fa fa-external-link"></i></a> ' )[1] for i in patch[1:] ]) output += patch if 'Developer Comment' in output: output = output.strip() + '*' await printLarge(channel, output)