Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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])
Ejemplo n.º 5
0
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])))
Ejemplo n.º 6
0
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!")
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
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