async def dispatch_casino(message, text): conn = create_connection(DATABASE) if not message.server.owner.id == message.author.id: casinoChannels = get_casino_channel(conn, int(message.server.id)) casinoChannels = [x[0] for x in casinoChannels] if int(message.channel.id) not in casinoChannels: if len(casinoChannels): return if text == 'bank': await player_bank(message, bot) return if text == 'slots': await slot_machine(message, bot) return if text == 'dice': await dice_roll(message, bot) return if text == 'blackjack': await black_jack(message, bot) return if text == 'jackpot': await show_pot(message, bot) return if text == 'mystats': await my_stats(message, bot) return if message.server.owner.id == message.author.id: if text == 'lotto': await lotto(message, bot) return
async def on_channel_create(channel): conn = create_connection(DATABASE) try: add_channel(conn, int(channel.server.id), int(channel.id), channel.name) except AttributeError: pass return
async def on_message(message): if message.author.bot: return conn = create_connection(DATABASE) if message.content.startswith(get_prefix(conn, int(message.server.id))[0]): await dispatch(message) return
async def slot_machine(message, bot): amount = await validate_play(message, bot) if amount < 0: return conn = create_connection(DATABASE) set_player_plays(conn, int(message.author.id), "slots") slotbed = discord.Embed(title=message.author.name, colour=0x00FFFF) col1 = random.randint(0, 4) col2 = random.randint(0, 4) col3 = random.randint(0, 4) if col1 == col2 == col3: amount *= 10 add_funds(conn, int(message.author.id), amount) update_money_won(conn, int(message.author.id), amount) slotbed.add_field(name='JACKPOT WIN!', value='```xl\nYOU WIN ${}```'.format(amount)) slotbed.set_image( url= 'https://bpsh2.hs.llnwd.net/e1/contenthub-cdn-origin/media/casinoeuro/casinoeuro_blog/' 'Blog_1140x400_Top_5_Jackpots_1000.jpg') elif col1 == col2 or col2 == col3: if (col1 == 2 and col2 == 2) or (col2 == 2 and col3 == 2): amount *= 2 add_funds(conn, int(message.author.id), amount) update_money_won(conn, int(message.author.id), amount) slotbed.add_field(name='HEARTS WIN!', value='```xl\nYou win ${}```'.format(amount)) slotbed.set_thumbnail( url= 'http://www.imagefully.com/wp-content/uploads/2015/07/Cute-Two-Heart-Picture-' 'Share-On-Whats-App-1024x768.jpg') else: slotbed.add_field(name='MONEY BACK!', value='```xl\nMoney back```'.format(amount)) slotbed.set_thumbnail( url= 'http://www.netentstalker.com/wp-content/uploads/2015/08/Spin-Party-Slot-Bar-' 'Symbol.jpg') else: remove_funds(conn, int(message.author.id), amount) update_money_lost(conn, int(message.author.id), amount) update_jackpot(conn, int(message.server.id), int(amount / 4)) slotbed.add_field(name='LOSS, TRY AGAIN!', value='```xl\nYou lose ${}```'.format(amount)) slotbed.add_field(name='SLOT MACHINE', value="[ {} | {} | {} ]".format(SLOT_PATTERN[col1], SLOT_PATTERN[col2], SLOT_PATTERN[col3]), inline=False) await bot.send_message(message.channel, embed=slotbed)
async def twitch_poster(after): conn = create_connection(DATABASE) streamerInfo = streamer_data(str(after.game.url)) streamChannels = get_stream_channel(conn, int(after.server.id)) streamChannels = [x[0] for x in streamChannels] if len(streamChannels) == 0: return twitchbed = discord.Embed(title="↓ Watch them now! ↓", description=after.game.url, color=0xEE00EE) twitchbed.set_author( name=after.name + " is now streaming!", url=after.game.url, icon_url= "https://cdn.discordapp.com/attachments/395303394547466241/395754894096597002" "/287637883022737418.png") twitchbed.set_thumbnail(url=streamerInfo['logo']) twitchbed.add_field(name="Now Playing", value=streamerInfo['game'], inline=False) twitchbed.add_field(name="Stream Title", value=after.game, inline=False) twitchbed.add_field(name="Followers", value=streamerInfo['followers'], inline=True) twitchbed.add_field(name="Total Views", value=streamerInfo['views'], inline=True) if str(streamerInfo['banner']) != 'None': twitchbed.set_image(url=streamerInfo['banner']) twitchbed.set_footer(text="Website coming soon | Github coming soon | " + str( time.strftime("%a %b %dth, %Y at %I:%M %p", time.localtime(time.time())))) if len(streamChannels) == 1: channel = bot.get_channel(str(streamChannels[0])) await bot.send_message( channel, "@here, {} is now live on Twitch, don't miss them!".format( after.name)) await bot.send_message(channel, embed=twitchbed) else: for channelId in streamChannels: channel = bot.get_channel(str(channelId)) await bot.send_message( channel, "@here, {} is now live on Twitch, don't miss them!".format( after.name)) await bot.send_message(channel, embed=twitchbed)
async def on_server_update(before, after): conn = create_connection(DATABASE) prefix = get_prefix(conn, int(after.id)) try: serverIcon = 'https://cdn.discordapp.com/icons/{}/{}.png'.format( after.id, after.icon) except TypeError: serverIcon = 0 add_server(conn, int(after.id), after.name, int(after.owner.id), after.owner.name, serverIcon, prefix=prefix[0]) return
async def my_stats(message, bot): conn = create_connection(DATABASE) stats = get_player_stats(conn, int(message.author.id)) statbed = discord.Embed(colour=0x00FFFF) statbed.set_author(name='{}\'s Casino Stats'.format(message.author.name), icon_url=message.author.avatar_url) statbed.set_thumbnail( url= 'https://pbs.twimg.com/profile_images/518176678384648192/h9VHq2Y2_400x400.png' ) statbed.add_field(name='Blackjack Plays', value=stats[1], inline=False) statbed.add_field(name='Dice Plays', value=stats[2], inline=False) statbed.add_field(name='Slots Plays', value=stats[3], inline=False) statbed.add_field(name='Money Won', value='${}'.format(stats[4])) statbed.add_field(name='Money Lost', value='${}'.format(stats[5])) await bot.send_message(message.channel, embed=statbed)
async def help_me(message, bot): conn = create_connection(DATABASE) prefix = get_prefix(conn, int(message.server.id))[0] helpBed = discord.Embed(colour=0xFF00FF) helpBed.set_author(name="Doo Bot", icon_url="http://www3.pictures.zimbio.com/mp/OLESKRmZW6Al.jpg") helpBed.set_footer(text=" Website coming soon | Github coming soon ") helpBed.set_thumbnail(url="https://www.mydish.com/filestream.ashx?ID=17612") helpBed.add_field(name="{}overwatch <BattleTag>".format(prefix), value="```fix\nGets Overwatch stats for entered player```") helpBed.add_field(name="{}youtube <Search Term>".format(prefix), value="```fix\nSearches Youtube and posts relevant video```") helpBed.add_field(name="{}insult <Name>".format(prefix), value="```fix\nInsults entered person```", inline=False) helpBed.add_field(name="{}imgur".format(prefix), value="```fix\nRandom image from Imgur's hot page```") helpBed.add_field(name="{}wouldyou".format(prefix), value="```fix\nAsks a would-you-rather question```") helpBed.add_field(name="{}either".format(prefix), value="```fix\nAsks an either-or quandary```", inline=False) helpBed.add_field(name="{}weird".format(prefix), value="```fix\nPosts some weird shit```", inline=False) helpBed.add_field(name="{}meme".format(prefix), value="```fix\nPosts a dank meme```") helpBed.add_field(name="{}comeondown".format(prefix), value="```fix\nStarts a Price is right game for up to 4 people```") helpBed.add_field(name="{}trends".format(prefix), value="```fix\nStarts a Google Trends game for up to 5 people```") await bot.send_message(message.channel, embed=helpBed)
async def validate_play(message, bot): conn = create_connection(DATABASE) try: money = message.content.split()[1] money = int(money) except ValueError: await bot.send_message(message.channel, 'You need to enter an integer amount') return -1 except IndexError: await bot.send_message(message.channel, 'You need to enter an amount') return -1 if money < 1: await bot.send_message(message.channel, 'You need to enter a positive amount') return -1 bank = get_player_bank(conn, int(message.author.id)) if bank < money: await bot.send_message(message.channel, 'You don\'t have enough money') return -1 return money
async def lotto(message, bot): winner = "" conn = create_connection(DATABASE) jackpot = get_jackpot(conn, int(message.server.id)) if not jackpot: await bot.send_message(message.channel, 'The current Jackpot is at $0') return users = get_users(conn, int(message.server.id)) while True: try: winner = random.choice(users) winnerObj = await bot.get_user_info(str(winner[1])) if winnerObj.bot: raise AttributeError break except AttributeError: users.remove(winner) pass lottobed = discord.Embed(title='{} IS THE LOTTO WINNER!'.format(winner[0]), color=0x00FFFF) lottobed.add_field(name='Today\'s Winnings', value='${}'.format(jackpot)) lottobed.set_thumbnail(url=winnerObj.avatar_url) lottobed.set_image( url= 'https://localtvktvi.files.wordpress.com/2011/12/lotto-winner.jpg?quality=85&strip=all&w=770' ) add_funds(conn, winner[1], jackpot) update_jackpot(conn, int(message.server.id), 0, empty=True) mentionName = '<@{}>'.format(winner[1]) await bot.send_message(message.channel, mentionName) await bot.send_message(message.channel, embed=lottobed)
async def youtube_search(message, bot): if len(message.content.split()) < 2: return conn = create_connection(DATABASE) linkList = [] textToSearch = message.content.replace('{}youtube'.format(get_prefix(conn, int(message.server.id))[0]), '') await bot.send_message(message.channel, 'Searching YouTube for: ' + textToSearch) query = urllib.request.quote(textToSearch) url = "https://www.youtube.com/results?search_query=" + query response = urllib.request.urlopen(url) html_s = response.read() soup = BeautifulSoup(html_s, "lxml") for vid in soup.findAll(attrs={'class': 'yt-uix-tile-link'}): linkList.append('https://www.youtube.com' + vid['href']) # noinspection PyBroadException try: random.randint(0, len(linkList) - 1) except Exception: await bot.send_message(message.channel, 'There was an error. Try another search term') return random_num = random.randint(0, 3) await bot.send_message(message.channel, linkList[random_num])
async def google_trends(message, bot): term = random.choice(trendTerms) guessesList = [] guessesDict = {} playerCount = 0 conn = create_connection(DATABASE) prefix = get_prefix(conn, int(message.server.id))[0] trendBed = discord.Embed(title="Let's play Google Trends! (Beta)", url="https://www.youtube.com/watch?v=AIsYJ_7chNc", color=0x11FF11, description="*Guess a word that would be combined with the " "Trend term (either before or after) you think is the most" " frequently searched on Google.*\n\n Today's Trend term is: " "__**{}**__".format(term)) trendBed.set_thumbnail(url="https://www.alternatememories.com/images/intro/science/google-trends_300x300.jpg.pagespeed.ce.7Zj5pQHJ5n.jpg") trendBed.set_footer(text="Use {0}before <word> if you think your word comes before the Trend term or {0}after <word>" " if you think your word comes after the Trend term.".format(prefix)) await bot.send_message(message.channel, embed=trendBed) def check(msg): if msg.content.startswith("{}before".format(prefix)): return msg.content.startswith("{}before".format(prefix)) elif msg.content.startswith("{}after".format(prefix)): return msg.content.startswith("{}after".format(prefix)) while playerCount < 5: u_msg = await bot.wait_for_message(check=check, timeout=30.0, channel=message.channel) try: word = u_msg.content.split()[1].lower() player = u_msg.author.name except AttributeError: break if u_msg.author.name in guessesDict: await bot.send_message(message.channel, "{}, You have already guessed".format(player)) continue if len(u_msg.content.split()) == 1: await bot.send_message(message.channel, "{}, You need to enter a word".format(player)) continue if len(u_msg.content.split()) > 2: await bot.send_message(message.channel, "{}, Only single word answers".format(player)) continue if len(word) > 25: await bot.send_message(message.channel, "{}, That word is too long".format(player)) continue guessDataBefore = "{} {}".format(word, term) guessDataAfter = "{} {}".format(term, word) if u_msg.content.split()[0] == "{}before".format(prefix): if guessDataBefore in guessesList: await bot.send_message(message.channel, "{}, {} is already taken". format(player, word)) continue guessesList.append(guessDataBefore) guessesDict[u_msg.author.name] = guessDataBefore elif u_msg.content.split()[0] == "{}after".format(prefix): if guessDataAfter in guessesList: await bot.send_message(message.channel, "{}, {} is already taken". format(player, word)) continue guessesList.append(guessDataAfter) guessesDict[u_msg.author.name] = guessDataAfter playerCount += 1 trend = TrendReq() try: trend.build_payload(kw_list=guessesList, timeframe='today 1-m') except ResponseError: await bot.send_message(message.channel, "Nobody played :cry:, game over") return playerCount = 0 for key, value in guessesDict.items(): try: guessesDict[key] = [value, trend.interest_over_time().tail(10).iloc[9, playerCount]] playerCount += 1 except IndexError: await bot.send_message(message.channel, "All guesses were so bad, there is no data for that on Google\n" "Everyone loses") return trendGraph = trend.interest_over_time().tail(10).plot(kind='line') saveGraph = trendGraph.get_figure() saveGraph.savefig("../pics/plots/plot{}.png".format(message.channel)) await bot.send_file(message.channel, "../pics/plots/plot{}.png".format(message.channel)) for key, value in guessesDict.items(): await bot.send_message(message.channel, "```ml\n{} guessed \"{}\" and scored {}\n```" .format(str(key).title(), value[0], value[1])) await bot.send_message(message.channel, "```css\n[ {} WINS! ]\n```" .format(max(guessesDict, key=lambda k: guessesDict[k][1])))
async def player_bank(message, bot): conn = create_connection(DATABASE) bank = get_player_bank(conn, int(message.author.id)) await bot.send_message( message.channel, '```xl\n{}: ${}\n```'.format(message.author.name, bank))
async def dispatch(message): try: text = str(message.content)[1:].split()[0].lower() except IndexError: return if text in GAMES: await dispatch_casino(message, text) return conn = create_connection(DATABASE) if not message.server.owner.id == message.author.id: allowedChannels = get_channel_permission(conn, int(message.server.id)) allowedChannels = [x[0] for x in allowedChannels] if int(message.channel.id) not in allowedChannels: if len(allowedChannels): return blacklist = get_blacklist_users(conn, int(message.server.id)) if int(message.author.id) in blacklist: return # User Commands if text == 'help': await help_me(message, bot) return if text == 'meme': await meme_pic(message, bot) return if text == 'weird': await cursed_pic(message, bot) return if text == 'youtube': await youtube_search(message, bot) return if text == 'wouldyou': await rather(message, bot) return if text == 'either': await either_or(message, bot) return if text == 'insult': await insult_me(message, bot) return if text == 'imgur': await imgur_meme(message, bot) return if text == 'overwatch': await ow_stats(message, bot) return # Game Commands if text == 'comeondown': if begin_game(message.server.id): await price_is_right(message, bot) end_game(message.server.id) return if text == 'trends': if begin_game(message.server.id): await google_trends(message, bot) end_game(message.server.id) return # Admin Commands if message.server.owner.id == message.author.id: if text == 'prefix': conn = create_connection(DATABASE) await set_server_prefix(conn, message, bot) return if text == 'addchannels': conn = create_connection(DATABASE) await set_channels(conn, message, bot, "add") return if text == 'removechannels': conn = create_connection(DATABASE) await set_channels(conn, message, bot, "remove") return if text == 'addstreamer': conn = create_connection(DATABASE) await set_streamer_user(conn, message, bot, "add") return if text == 'removestreamer': conn = create_connection(DATABASE) await set_streamer_user(conn, message, bot, "remove") return if text == 'streamer': conn = create_connection(DATABASE) await get_streamer_user(conn, message, bot) return if text == 'addstream': conn = create_connection(DATABASE) await set_channels(conn, message, bot, "add", chan_type='stream') return if text == 'removestream': conn = create_connection(DATABASE) await set_channels(conn, message, bot, "remove", chan_type='stream') return if text == 'addcasino': conn = create_connection(DATABASE) await set_channels(conn, message, bot, "add", chan_type='casino') return if text == 'removecasino': conn = create_connection(DATABASE) await set_channels(conn, message, bot, "remove", chan_type='casino') return if text == 'channels': conn = create_connection(DATABASE) await get_channels(conn, message, bot) return if text == 'addblacklist': conn = create_connection(DATABASE) await set_blacklist(conn, message, bot, "add") return if text == 'removeblacklist': conn = create_connection(DATABASE) await set_blacklist(conn, message, bot, "remove") return if text == 'blacklist': conn = create_connection(DATABASE) await get_blacklist(conn, message, bot) return
async def price_is_right(message, bot): randItem = random.randint(0, 100) guessesDict = {} guessesList = [] i = 0 guess = 0.0 breaker = False conn = create_connection(DATABASE) prefix = get_prefix(conn, int(message.server.id))[0] await bot.send_message(message.channel, "COME ON DOWN! :musical_note: *price is right jingle*:musical_note: ") webhoseio_api_key = "69c5d207-91a4-46a9-aa46-7d798b1e8b35" webhoseio_url = "http://webhose.io/productFilter?token={}&format=json".format(webhoseio_api_key) response = requests.get(webhoseio_url) if response.status_code == 200: data = json.loads(response.content.decode('utf-8')) else: bot.send_message(message.channel, "<API ERROR> Request not successful ({})".format(response.status_code)) return try: price = float(data['products'][randItem]['price']) except ValueError: await bot.send_message(message.channel, "<Error> converting price of product to float") return PIRBed = discord.Embed(title="THE PRICE IS RIGHT! (Beta)", url=data['products'][randItem]['url'], color=0xfffa2d) PIRBed.set_thumbnail(url="https://upload.wikimedia.org/wikipedia/en/a/a0/Tpir_40_logo.png") PIRBed.add_field(name="Product Name", value=data['products'][randItem]['name'], inline=True) PIRBed.set_footer(text="Be closest to actual price without going over to win! Use \'{}guess\' <amount>" .format(prefix)) try: PIRBed.set_image(url=data['products'][randItem]['images'][0]) except IndexError: pass try: PIRBed.add_field(name="Category", value=data['products'][randItem]['categories'][0].capitalize(), inline=True) except IndexError: pass await bot.send_message(message.channel, embed=PIRBed) def check(msg1): return msg1.content.startswith("{}guess".format(prefix)) while i < 4: msg = await bot.wait_for_message(check=check, timeout=30.0, channel=message.channel) try: guess = float(msg.content[7:]) if guess > 50000: await bot.send_message(message.channel, "{}, that is definitely too high".format(msg.author.name)) if i: i = len(guessesList) continue if guess < 0: await bot.send_message(message.channel, "{}, that is definitely too low".format(msg.author.name)) if i: i = len(guessesList) continue except ValueError: await bot.send_message(message.channel, "{}, that is not a valid input".format(msg.author.name)) if i: i = len(guessesList) continue except AttributeError: break for key, value in guessesDict.items(): if value == msg.author.id: await bot.send_message(message.channel, "{}, you have already guessed".format(msg.author.name)) if i: i = len(guessesList) breaker = True continue if breaker: breaker = False continue if guess not in guessesList: guessesList.append(guess) else: await bot.send_message(message.channel, "{}, amount already guessed".format(msg.author.name)) if i: i = len(guessesList) continue guessesDict[guess] = msg.author.id i += 1 await bot.send_message(message.channel, "```ml\nActual Retail Price Is: ${}\n```".format(price)) guessesList.sort(reverse=True) if not len(guessesList): await bot.send_message(message.channel, "Nobody played :cry:") return if guessesList[0] > price: try: if guessesList[1] <= price: user = message.server.get_member(guessesDict[guessesList[1]]) await bot.send_message(message.channel, "{} WINS!".format(user.name)) elif guessesList[2] <= price: user = message.server.get_member(guessesDict[guessesList[2]]) await bot.send_message(message.channel, "{} WINS!".format(user.name)) elif guessesList[3] <= price: user = message.server.get_member(guessesDict[guessesList[3]]) await bot.send_message(message.channel, "{} WINS!".format(user.name)) else: await bot.send_message(message.channel, "Sorry, you all went over the retail amount!") except IndexError: await bot.send_message(message.channel, "Sorry, you all went over the retail amount!") elif guessesList[0] <= price: user = message.server.get_member(guessesDict[guessesList[0]]) await bot.send_message(message.channel, "{} WINS!".format(user.name)) else: await bot.send_message(message.channel, "Sorry, you all went over the retail amount!")
async def dice_roll(message, bot): amount = await validate_play(message, bot) if amount < 0: return conn = create_connection(DATABASE) set_player_plays(conn, int(message.author.id), "dice") prefix = get_prefix(conn, int(message.server.id))[0] multiplier = 1.0 await bot.send_message( message.channel, '```xl\n{0}: Guess if the roll is \'{1}even\' or \'{1}odd\' ' '(Current Multiplier \'x{2}\')\n```'.format(message.author.name, prefix, multiplier)) while True: def check(msg): return msg.content.startswith(prefix) guess = await bot.wait_for_message(timeout=20, author=message.author, channel=message.channel, check=check) if guess is None: await bot.send_message( message.channel, '```xl\n{} timed out and loses bet of ${}\n```'.format( message.author.name, amount)) remove_funds(conn, int(message.author.id), amount) update_money_lost(conn, int(message.author.id), amount) update_jackpot(conn, int(message.server.id), int(amount / 4)) return if guess.content == '{}even'.format(prefix): pick = 0 break if guess.content == '{}odd'.format(prefix): pick = 1 break else: await bot.send_message( message.channel, '```xl\nTo guess use \'{0}even\' or \'{0}odd\'\n```'.format( prefix)) while True: roll = random.randint(1, 6) chosenPic = '../pics/dice/Die{}.jpg'.format(roll) evenOdd = roll % 2 with open(chosenPic, 'rb') as die: await bot.send_file(message.channel, die) if pick == evenOdd: multiplier += 0.2 await bot.send_message( message.channel, '```xl\n{0} ROLL: {1}\nGuess again to increase your winnings ' 'multiplier or cash out (Current Multiplier \'x{2}\')\nUse \'' '{3}even\' or \'{3}odd\' to go again or \'{3}quit\' to cash out\n```' .format(message.author.name, roll, float(multiplier), prefix)) def check(msg): return msg.content.startswith(prefix) guess = await bot.wait_for_message(timeout=20, author=message.author, channel=message.channel, check=check) if guess is None: await bot.send_message( message.channel, '```xl\n{} timed out and loses bet of ${}\n```'.format( message.author.name, amount)) remove_funds(conn, int(message.author.id), amount) update_money_lost(conn, int(message.author.id), amount) update_jackpot(conn, int(message.server.id), int(amount / 4)) return if guess.content == '{}even'.format(prefix): pick = 0 elif guess.content == '{}odd'.format(prefix): pick = 1 elif guess.content == '{}quit'.format(prefix): await bot.send_message( message.channel, '```xl\n{} wins ${}\n```'.format(message.author.name, int(amount * multiplier))) add_funds(conn, int(message.author.id), int(amount * multiplier)) update_money_won(conn, int(message.author.id), amount) return else: await bot.send_message( message.channel, '```xl\nTo guess use \'{0}even\' or \'{0}odd\'\n```'. format(prefix)) else: await bot.send_message( message.channel, '```xl\n{} loses bet of ${}\n```'.format( message.author.name, amount)) remove_funds(conn, int(message.author.id), amount) update_money_lost(conn, int(message.author.id), amount) update_jackpot(conn, int(message.server.id), int(amount / 4)) return
async def ow_stats(message, bot): database = '../database/OW_Ranks.db' conn = create_connection(database) QPtop5NameList = [] QPtop5TimeList = [] CPtop5NameList = [] CPtop5TimeList = [] QPElims = 0 QPDeaths = 0 QPTime = 0 CPElims = 0 CPDeaths = 0 CPTime = 0 player = message.content[11:].replace("#", "-") stat_page = "https://playoverwatch.com/career/pc/" + player if len(message.content.split()) == 1: return try: page = urllib.request.urlopen(stat_page).read() except HTTPError: await bot.send_message(message.channel, message.content[11:] + " not found. You need to include the # and " "numbers after their name, and proper " "capitalization matters too") return soup = BeautifulSoup(page, 'html.parser') # User Icon try: icon = soup.find("img", {'class': 'player-portrait'}).get('src') except AttributeError: await bot.send_message(message.channel, message.content[11:] + " not found. You need to include the # and " "numbers after their name, and proper " "capitalization matters too") return # User level (not competitive rank) prestigeLevel = soup.find("div", {'class': 'player-level'})['style'].split("url(") partialLevel = soup.find("div", {'class': 'u-vertical-center'}).text playerLevel = get_level(prestigeLevel[1][:-1].split("rewards/")[1].split("_Border")[0]) + int(partialLevel) emblem = get_ow_rank(conn, playerLevel) # QP stats for top5 in soup.find_all("div", {'id': 'quickplay'}): for item in top5.find_all("div", {'class': 'bar-text'})[:5]: QPtop5NameList.append(item.find("div", {'class': 'title'}).text) QPtop5TimeList.append(item.find("div", {'class': 'description'}).text) try: QPElims = top5.find("td", string="Eliminations").find_next_sibling("td").text except AttributeError: pass try: QPDeaths = top5.find("td", string="Deaths").find_next_sibling("td").text except AttributeError: pass try: QPTime = top5.find("td", string="Time Played").find_next_sibling("td").text except AttributeError: pass # CP stats for top5 in soup.find_all("div", {'id': 'competitive'}): for item in top5.find_all("div", {'class': 'bar-text'})[:5]: CPtop5NameList.append(item.find("div", {'class': 'title'}).text) CPtop5TimeList.append(item.find("div", {'class': 'description'}).text) try: CPElims = top5.find("td", string="Eliminations").find_next_sibling("td").text except AttributeError: pass try: CPDeaths = top5.find("td", string="Deaths").find_next_sibling("td").text except AttributeError: pass try: CPTime = top5.find("td", string="Time Played").find_next_sibling("td").text except AttributeError: pass OWBed = discord.Embed(title=message.content[11:] + "'s Overwatch stats", color=0x00FFFF, url=stat_page) OWBed.set_thumbnail(url=emblem) OWBed.set_image(url=icon) formattedData = "" for i in range(5): formattedData += "`{} :: {} `\n".format(QPtop5NameList[i].ljust(15, " "), QPtop5TimeList[i].rjust(11), " ") OWBed.add_field(name="__Top 5 Quick Play Characters Played__", value=formattedData, inline=False) formattedData = "" try: formattedData += "`{} :: {} `\n".format("Eliminations".ljust(15, " "), QPElims.rjust(11, " ")) except AttributeError: formattedData += "`{} :: {} `\n".format("Eliminations".ljust(15, " "), "0".rjust(11, " ")) try: formattedData += "`{} :: {} `\n".format("Deaths".ljust(15, " "), QPDeaths.rjust(11, " ")) except AttributeError: formattedData += "`{} :: {} `\n".format("Deaths".ljust(15, " "), "0".rjust(11, " ")) try: formattedData += "`{} :: {} `\n".format("Time Played".ljust(15, " "), QPTime.rjust(11, " ")) except AttributeError: formattedData += "`{} :: {} `\n".format("Time Played".ljust(15, " "), "0".rjust(11, " ")) OWBed.add_field(name="__Quick Play Stats__", value=formattedData, inline=False) OWBed.add_field(name="-----------------------------------------", value="----------------------------------------", inline=False) formattedData = "" for i in range(5): formattedData += "`{} :: {} `\n".format(CPtop5NameList[i].ljust(15, " "), CPtop5TimeList[i].rjust(11), " ") OWBed.add_field(name="__Top 5 Comp Play Characters Played__", value=formattedData, inline=False) formattedData = "" try: formattedData += "`{} :: {} `\n".format("Eliminations".ljust(15, " "), CPElims.rjust(11, " ")) except AttributeError: formattedData += "`{} :: {} `\n".format("Eliminations".ljust(15, " "), "0".rjust(11, " ")) try: formattedData += "`{} :: {} `\n".format("Deaths".ljust(15, " "), CPDeaths.rjust(11, " ")) except AttributeError: formattedData += "`{} :: {} `\n".format("Deaths".ljust(15, " "), "0".rjust(11, " ")) try: formattedData += "`{} :: {} `\n".format("Time Played".ljust(15, " "), CPTime.rjust(11, " ")) except AttributeError: formattedData += "`{} :: {} `\n".format("Time Played".ljust(15, " "), "0".rjust(11, " ")) OWBed.add_field(name="__Comp Play Stats__", value=formattedData, inline=False) await bot.send_message(message.channel, embed=OWBed)
async def bot_welcome(server): conn = create_connection(DATABASE) serverID = int(server.id) try: serverIcon = 'https://cdn.discordapp.com/icons/' + str( serverID) + '/' + server.icon + '.png' except TypeError: serverIcon = 0 add_server(conn, serverID, server.name, int(server.owner.id), server.owner.name, serverIcon) prefix = get_prefix(conn, serverID)[0] server = bot.get_server(str(serverID)) for member in server.members: add_user(conn, serverID, int(member.id), member.name) add_casino(conn, int(member.id)) server = bot.get_server(str(serverID)) for channel in server.channels: if str(channel.type) == "text": add_channel(conn, serverID, int(channel.id), channel.name) conn.commit() conn.close() welcomeLine1 = "Use {}help to see Doo Bot commands".format(prefix) adminBed = discord.Embed(colour=0xFF00FF) adminBed.set_author( name="Doo Bot", icon_url="http://www3.pictures.zimbio.com/mp/OLESKRmZW6Al.jpg") adminBed.set_footer(text=" Website coming soon | Github coming soon ") adminBed.set_thumbnail( url="https://www.mydish.com/filestream.ashx?ID=17612") adminBed.add_field( name= "Thanks for using Doo Bot! Below are some admin commands and configurations.", value="Here are some admin commands that only you are able to use") adminBed.add_field( name="{}prefix".format(prefix), value="This changes the prefixes Doo Bot will listen for. " "By default the prefix is {}.".format(prefix)) adminBed.add_field(name="{}addchannels".format(prefix), value="Add channels that Doo Bot will listen too. " "By default, it is all channels.") adminBed.add_field(name="{}removechannels".format(prefix), value="Remove channels that Doo Bot will listen too. " "If all channels are removed, Doo Bot will listen" "too all channels.") await bot.send_message(server.owner, embed=adminBed) welcomeBed = discord.Embed(title="Doo Bot", description="Version 4.0.0", color=0x00FFFF) welcomeBed.add_field(name="Thanks for choosing Doo Bot:", value=welcomeLine1) welcomeBed.set_footer(text=" Website coming soon | Github coming soon ") welcomeBed.set_thumbnail( url="http://www3.pictures.zimbio.com/mp/OLESKRmZW6Al.jpg") for channel in server.channels: if str(channel.type) == 'text': await bot.send_message(channel, embed=welcomeBed) break
async def black_jack(message, bot): amount = await validate_play(message, bot) if amount < 0: return conn = create_connection(DATABASE) set_player_plays(conn, int(message.author.id), "blackjack") prefix = get_prefix(conn, int(message.server.id))[0] deck = [1] * 54 player_turn = 200 dealer_turn = 200 score = await blackjack_start(message, bot, deck) hand = score[1] score = score[0] await check_ace(message, bot, hand, score, prefix) if score['player_score'] == 21: amount *= 2 add_funds(conn, int(message.author.id), amount) update_money_won(conn, int(message.author.id), amount) await bot.send_message( message.channel, '```xl\n\'{0}hit\' : or : \'{0}stay\'\n```'.format(prefix)) while True: def check(msg): if msg.content.startswith('{}hit'.format(prefix)): return msg.content.startswith('{}hit'.format(prefix)) if msg.content.startswith('{}stay'.format(prefix)): return msg.content.startswith('{}stay'.format(prefix)) hit = await bot.wait_for_message(author=message.author, check=check, channel=message.channel) if hit is None: await bot.send_message( message.channel, '```xl\n{} timed out and loses bet of ${}\n```'.format( message.author.name, amount)) remove_funds(conn, int(message.author.id), amount) update_money_lost(conn, int(message.author.id), amount) update_jackpot(conn, int(message.server.id), int(amount / 4)) return if hit.content == '{}hit'.format(prefix): score = await blackjack_hit(message, bot, deck, hand, score, 'player_cards', player_turn) player_turn += 100 hand = score[1] score = score[0] await check_ace(message, bot, hand, score, prefix) if score['player_score'] > 21: remove_funds(conn, int(message.author.id), amount) update_money_lost(conn, int(message.author.id), amount) update_jackpot(conn, int(message.server.id), int(amount / 4)) await bot.send_message( message.channel, '```xl\n{} busts, and loses ${}\n```'.format( message.author.name, amount)) return if hit.content == '{}stay'.format(prefix): break else: await bot.send_message( message.channel, '```xl\nPlease choose \'{0}hit\' : or : \'{0}stay\'\n```'. format(prefix)) while True: if score['dealer_score'] < score['player_score']: score = await blackjack_hit(message, bot, deck, hand, score, 'dealer_cards', dealer_turn) dealer_turn += 100 hand = score[1] score = score[0] elif score['dealer_score'] == score['player_score']: await bot.send_message( message.channel, 'Draw, {}: Money back!'.format(message.author.name)) return elif score['dealer_score'] < 22: remove_funds(conn, int(message.author.id), amount) update_money_lost(conn, int(message.author.id), amount) update_jackpot(conn, int(message.server.id), int(amount / 4)) await bot.send_message( message.channel, '```xl\n{} you lose ${}!\n```'.format(message.author.name, amount)) return elif score['dealer_score'] > 21: add_funds(conn, int(message.author.id), amount) update_money_won(conn, int(message.author.id), amount) await bot.send_message( message.channel, '```xl\n{} you win ${}!\n```'.format(message.author.name, amount)) return
async def on_member_join(member): conn = create_connection(DATABASE) add_user(conn, int(member.server.id), int(member.id), member.name) return
async def on_member_remove(member): conn = create_connection(DATABASE) remove_user(conn, int(member.server.id), int(member.id)) return
async def on_channel_update(before, after): if str(after.type) == "text": conn = create_connection(DATABASE) update_channel(conn, int(after.id), after.name) return
async def show_pot(message, bot): conn = create_connection(DATABASE) pot = get_jackpot(conn, int(message.server.id)) await bot.send_message(message.channel, 'Current Jackpot is at ${}'.format(pot))
async def on_channel_delete(channel): conn = create_connection(DATABASE) remove_channel(conn, int(channel.id)) return