Example #1
0
async def list(ctx, *, raw_gym_name):

    if ctx and ((ctx.message.channel.id == str(bot_channel)) or
                ((ctx.message.channel.id == str(admin_channel)))):
        database.ping(True)
        try:
            if raw_gym_name.isnumeric():
                cursor.execute(
                    "SELECT id, name, lat, lon FROM forts WHERE id LIKE '" +
                    str(raw_gym_name) + "';")
            else:
                cursor.execute(
                    "SELECT id, name, lat, lon FROM forts WHERE name LIKE '%" +
                    str(raw_gym_name) + "%';")
            data = cursor.fetchall()
            count = cursor.rowcount
            gym_names = ''
            for gym in data:
                gym_names += str(gym[0]) + ': ' + gym[
                    1] + ' <https://www.google.com/maps?q=loc:' + str(
                        gym[2]) + ',' + str(gym[3]) + '>'
            await bot.say('There are ' + str(count) +
                          ' gyms with the word(s) "' + str(raw_gym_name) +
                          '" in it:\n' + str(gym_names))
            database.commit()
        except:
            database.rollback()
            await bot.say(
                'No gym with the word "' + str(raw_gym_name) +
                '" in it OR too many to list. Try narrowing down your search.')
async def spawn(ctx, arg, arg2, arg3):
    if ctx and ctx.message.channel.id == str(bot_channel) and arg in pokemon:
        pokemon_id = find_pokemon_id(str(arg).capitalize())
        time = datetime.datetime.utcnow() + timedelta(minutes=15)
        time2 = datetime.datetime.utcnow() + timedelta()
        number = random.randint(1,2000000001)
        try:
            cursor.execute("REPLACE INTO pokemon(encounter_id, spawnpoint_id, pokemon_id, latitude, longitude, disappear_time, individual_attack, individual_defense, individual_stamina, move_1, move_2, cp, cp_multiplier, weight, height, gender, costume, form, weather_boosted_condition, last_modified)"
                           "VALUES ("+str(number)+", "+str(number)+", "+str(pokemon_id)+", "+str(arg2)+", "+str(arg3)+", '"+str(time)+"', null, null, null, null, null, null, null, null, null, null, null, null, null, '"+str(time2)+"');")

            database.ping(True)
            database.commit()
            await bot.say('Successfully added your spawn to the live map.\n'
                          '*Pokemon timers are automatically given 15 minutes since the timer is unknown.*')
            #await bot.say("VALUES ("+str(number)+", "+str(number)+", "+str(pokemon_id)+", "+str(arg2)+", "+str(arg3)+", '"+str(time)+"', null, null, null, null, null, null, null, null, null, null, null, null, null, null);")
            await bot.send_message(discord.Object(id=log_channel), str(ctx.message.author.name) + ' said there was a wild ' + str(arg) +
                                   ' at these coordinates: ' + str(arg2) + ', ' + str(arg3))  and print(str(ctx.message.author.name) + ' said there was a wild ' + str(arg) +
                                   ' at these coordinates: ' + str(arg2) + ', ' + str(arg3))

            spawn_embed=discord.Embed(
                title='Click for directions!',
                url=("https://www.google.com/maps/?q=" + str(arg2) + "," + str(arg3)),
                description=('A wild ' + str(arg).capitalize() + ' is available!\n\n'
                                                                 '**Time Remaining:** ~15 minutes.\n'
                                                                 '**Spotted by:** ' + str(ctx.message.author.name) + '!'),
                color=3447003
            )
            spawn_embed.set_image(url="http://www.pokestadium.com/sprites/xy/" + str(arg).lower() + ".gif")
            await bot.send_message(discord.Object(id=spawn_channel), embed=spawn_embed)

        except:
            tb = traceback.print_exc(file=sys.stdout)
            print(tb)
            await bot.say("VALUES ("+str(number)+", "+str(number)+", "+str(pokemon_id)+", "+str(arg2)+", "+str(arg3)+", '"+str(time)+"', null, null, null, null, null, null, null, null, null, null, null, null, null, null);")
            await bot.say('Unsuccessful in database query, your reported spawn was not added to the live map.')
Example #3
0
async def update(raw_table, raw_field_list, raw_values, raw_condition):
    sql_table = str(raw_table)
    field_list = str(raw_field_list)
    str_values = raw_values
    sql_condition = str(raw_condition)
    current_time = datetime.datetime.utcnow()
    current_hour = time.strftime(
        '%H%M', time.localtime(calendar.timegm(current_time.timetuple())))
    database.ping(True)
    #       print (sql_state + ":" + server)
    try:
        strsql = "UPDATE " + str(sql_table) + " SET (" + str(
            field_list) + ") VALUES (" + str(str_values) + ") WHERE " + str(
                sql_condition) + ";"
        #                cursor.execute(strsql)
        #                sql_data = cursor.fetchall()
        #                count = cursor.rowcount
        await bot.say(strsql)


#            sql_count = 0
#            sql_result = ''
#            for sql in sql_result:
#                sql_result += str(sql[0]) + ': ' + sql[1] + ' (' + str(gym[2]) + ', ' + str(gym[3]) + ')\n'

    except Exception as e:
        message = e.args[0]
        await bot.say(message)
        print(message)

    except:
        database.rollback()
async def raid(ctx, raid_gym_name, raid_pokemon_name, raid_level, raid_time_remaining):
    if ctx and ctx.message.channel.id == str(bot_channel) and str(raid_pokemon_name).lower() in pokemon or str(raid_pokemon_name).lower() == "egg":
        """example: ^raid "Canandagua National Bank Clock Tower" Lugia 5 45"""

        time = datetime.datetime.utcnow() + timedelta()

        if raid_pokemon_name == "egg":
            pokemon_id = "NULL"
            pokecp = "NULL"
            start = datetime.datetime.utcnow() + timedelta(minutes=int(raid_time_remaining))
            end = start + timedelta(minutes=int(60))
            spawn = start - timedelta(minutes=int(60))
        else:
            pokemon_id = find_pokemon_id(str(raid_pokemon_name).capitalize())
            pokecp = find_pokecp(str(raid_pokemon_name).capitalize())
            end = datetime.datetime.utcnow() + timedelta(minutes=int(raid_time_remaining))
            start = end - timedelta(minutes=int(60))
            spawn = start - timedelta(minutes=int(60))

        try:
            cursor.execute("SELECT gym_id FROM gymdetails WHERE name LIKE '" + str(raid_gym_name) + "%';")
            gym_id = str(cursor.fetchall())
            gym_id = gym_id.split(',')
            gym_id = gym_id[0].split('((')
            cursor.execute("REPLACE INTO raid("
                           "gym_id, level, spawn, start, "
                           "end, pokemon_id, cp, move_1, "
                           "move_2, last_scanned)"
                           " VALUES ("+str('{}').format(gym_id[1])+", "+str(raid_level)+", "+str("'{}'").format(spawn)+", "+str("'{}'").format(start)+", "+str("'{}'").format(end)+", "+str(pokemon_id)+", "+str(pokecp)+", NULL, NULL, "+str("'{}'").format(time)+");")
            cursor.execute("UPDATE gym SET last_modified = '"+str(time)+"', last_scanned = '"+str(time)+"' WHERE gym_id = "+str(gym_id[1])+";")
            database.ping(True)
            database.commit()
            await bot.say('Successfully added your raid to the live map.')
            await bot.send_message(discord.Object(id=log_channel), str(ctx.message.author.name) + ' said there was a ' + str(raid_pokemon_name) +
                                   ' raid going on at ' + str(raid_gym_name)) and print(str(ctx.message.author.name) + ' said there was a ' + str(raid_pokemon_name) +
                                   ' raid going on at ' + str(raid_gym_name))

        except:
            database.rollback()
            await bot.say('Unsuccesful in database query, your raid was not added to the live map.')
            await bot.say("Could not find `{}` in my database. Please check your gym name. \nuse `^gym gym-name` to try and look it up".format(raid_gym_name))
            # Uncomment for debug messages
            #await bot.say("VALUES ("+str('{}').format(gym_id[1])+", "+str(raid_level)+", "+str("'{}'").format(time)+", "+str("'{}'").format(time)+", "+str("'{}'").format(now)+", "+str(pokemon_id)+", "+str(pokecp)+", 1, 1, "+str("'{}'").format(time)+");")
            #await bot.say("UPDATE gym SET last_modified = '"+str(time)+"', last_scanned = '"+str(time)+"' WHERE gym_id = "+str(gym_id[1])+";")
            tb = traceback.print_exc(file=sys.stdout)
            print(tb)
Example #5
0
async def updategymname(ctx, fort_id, new_gym_name):
    if (admin_channel == 'disabled'):
        await bot.say('The !updategymname command is disabled')
        pass
    else:
        database.ping(True)
        if ctx and ctx.message.channel.id == str(admin_channel):
            try:
                cursor.execute("SELECT id, name FROM forts WHERE id='" +
                               str(fort_id) + "';")
                gym_data = cursor.fetchall()
                gym_count = cursor.rowcount

                if (gym_count == 1):
                    fort_id, gym_name = gym_data[0]

                    cursor.execute("UPDATE forts SET name='" +
                                   str(new_gym_name) + "' WHERE id='" +
                                   str(fort_id) + "';")
                    cursor.execute("SELECT name FROM forts WHERE id='" +
                                   str(fort_id) + "';")
                    updated_gym_data = cursor.fetchall()
                    updated_gym_name = updated_gym_data[0][0]
                    await bot.say('Changed the name of:\n__' + str(fort_id) +
                                  ': ' + str(gym_name) + '__\nto:\n**' +
                                  str(fort_id) + ': ' + str(updated_gym_name) +
                                  '**')
                else:
                    await bot.say(
                        'There are multiple gyms with gym_id: ' +
                        str(fort_id) +
                        '.  Delete all of the duplicate gym_ids before proceeding.'
                    )
                database.commit()
            except:
                database.rollback()
Example #6
0
async def raid(ctx, raw_pokemon_name, raw_time_remaining, *, raw_gym_name):
    if ctx and ctx.message.channel.id == str(bot_channel):
        pokemon_name = str(raw_pokemon_name).capitalize()
        pokemon_id = find_pokemon_id(pokemon_name)
        remaining_time = get_time(int(raw_time_remaining))
        current_time = datetime.datetime.utcnow()
        current_hour = time.strftime(
            '%H%M', time.localtime(calendar.timegm(current_time.timetuple())))
        gym_team_id = '0'
        #        raw_raid_level = 5
        database.ping(True)
        if (int(pokemon_id) == int(legendary_id)) or (pokemon_name == 'Egg'):
            raw_raid_level = '5'
        else:
            raw_raid_level = '4'

        raid_level = str(raw_raid_level)
        try:
            if ((int(raw_time_remaining) < 1)
                    or (int(raw_time_remaining) >= 60)):
                raise Exception(
                    'Invalid time entered. Enter value between 1-60.')
            if (curfew == 'true'):
                if ((int(current_hour) >= 1930) or (int(current_hour) <= 500)):
                    raise Exception(
                        'Raid report is outside of the valid raid times. Raids can be reported between 5am - 7:30pm daily.'
                    )

            if raw_gym_name.isnumeric():
                cursor.execute(
                    "SELECT id, name, lat, lon FROM forts WHERE id LIKE '" +
                    str(raw_gym_name) + "';")
            else:
                cursor.execute(
                    "SELECT id, name, lat, lon FROM forts WHERE name LIKE '%" +
                    str(raw_gym_name) + "%';")
            gym_data = cursor.fetchall()
            count = cursor.rowcount
            raid_count = 0
            gym_names = ''
            for gym in gym_data:
                gym_names += str(gym[0]) + ': ' + gym[1] + ' (' + str(
                    gym[2]) + ', ' + str(gym[3]) + ')\n'

            # Single gym_id is returned so check if a raid exists for it
            if (count == 1):
                gym_id = gym_data[0][0]
                gym_name = gym_data[0][1]
                cursor.execute(
                    "SELECT id, fort_id, time_end FROM raids WHERE fort_id='" +
                    str(gym_id) + "' AND time_end>'" +
                    str(calendar.timegm(current_time.timetuple())) + "';")
                raid_data = cursor.fetchall()
                raid_count = cursor.rowcount

                if (raid_count):
                    raid_id = raid_data[0][0]
                    raid_fort_id = raid_data[0][1]
                    raid_time_end = raid_data[0][2]
            elif (count > 1):
                raise Exception('There are multiple gyms with the word "' +
                                str(raw_gym_name) + '" in it:\n' +
                                str(gym_names) +
                                '\nBe a little more specific.')
            elif (count == 0):
                raise Exception(
                    'No gym with the word "' + str(raw_gym_name) +
                    '" in it. Use the !list command to list gyms available in the region.\n'
                )
            else:
                raise Exception(
                    'Error. !raid "*gym_name*" *pokemon_name* *minutes_left*\n'
                )

            if (pokemon_name == "Egg"):
                est_end_time = remaining_time + 2700

                if (raid_count):
                    cursor.execute("UPDATE raids SET level='" +
                                   str(raw_raid_level) + "', time_battle='" +
                                   str(remaining_time) + "', time_end='" +
                                   str(est_end_time) + "' WHERE id='" +
                                   str(raid_id) + "';")
                    await bot.say(
                        'Updated **Level ' + str(raw_raid_level) + ' ' +
                        str(pokemon_name) + '**' + '\nGym: **' + str(gym_id) +
                        ': ' + str(gym_name) + ' Gym' + '**' +
                        '\nHatches: **' + str(
                            time.strftime('%I:%M %p',
                                          time.localtime(remaining_time))) +
                        '**' + '\nRaid Ends: **' + str(
                            time.strftime('%I:%M %p',
                                          time.localtime(est_end_time))) +
                        '**')
                else:
                    # Setup task to automatically hatch Legendary egg
                    if (raw_raid_level == '5'):
                        bot.loop.create_task(
                            incubate(ctx, gym_id, remaining_time))

                    cursor.execute("INSERT INTO raids("
                                   "id, external_id, fort_id , level, "
                                   "pokemon_id, move_1, move_2, time_spawn, "
                                   "time_battle, time_end, cp, reported_by)"
                                   "VALUES "
                                   "(null, null, " + str(gym_id) + ", " +
                                   str(raw_raid_level) + ", " +
                                   str(pokemon_id) + ", null, null, "
                                   "null, " + str(remaining_time) + ", " +
                                   str(est_end_time) + ", null, '" +
                                   str(ctx.message.author.name) + "');")
                    await bot.say(
                        'Added ' + str(pokemon_name) + '\nGym: **' +
                        str(gym_name) + '**' + '\nHatches: **' + str(
                            time.strftime('%I:%M %p',
                                          time.localtime(remaining_time))) +
                        '**' + '\nRaid Ends: **' + str(
                            time.strftime('%I:%M %p',
                                          time.localtime(est_end_time))) +
                        '**' + '\nTime Left Until Hatch: **' +
                        str(raw_time_remaining) + ' minutes**')
                    raid_embed = discord.Embed(
                        title='Hatch at: ' + str(
                            time.strftime('%I:%M %p',
                                          time.localtime(remaining_time))),
                        description='Gym: **' + str(gym_name) + '**'
                        '\nRaid Ends: **' + str(
                            time.strftime('%I:%M %p',
                                          time.localtime(est_end_time))) +
                        '**' + '\nReported by: __' +
                        str(ctx.message.author.name) + '__' +
                        '\n\nhttps://www.google.com/maps?q=loc:' +
                        str(gym_data[0][2]) + ',' + str(gym_data[0][3]),
                        color=get_team_color(gym_team_id))
                    thumbnail_image_url = get_egg_url(raw_raid_level)
                    raid_embed.set_thumbnail(url=thumbnail_image_url)
                    await bot.send_message(discord.Object(id=log_channel2),
                                           embed=raid_embed)

                    print(
                        str(ctx.message.author.name) + ' reported a ' +
                        str(pokemon_name) + ' at ' + str(gym_id) + ': ' +
                        str(gym_name) + ' with ' + str(raw_time_remaining) +
                        ' minutes left.')
            else:
                # Update Egg to a hatched Raid Boss
                if (raid_count):
                    cursor.execute(
                        "UPDATE raids SET pokemon_id='" + str(pokemon_id) +
                        "', level='" + str(raw_raid_level) +
                        "', time_battle='" +
                        str(calendar.timegm(current_time.timetuple())) +
                        "', time_end='" + str(remaining_time) +
                        "' WHERE id='" + str(raid_id) + "';")
                    await bot.say(
                        'Updated Egg to ' + str(pokemon_name) + ' Raid' +
                        '\nGym: **' + str(gym_id) + ': ' + str(gym_name) +
                        '**' + '\nRaid Ends: **' + str(
                            time.strftime('%I:%M %p',
                                          time.localtime(remaining_time))) +
                        '**')

                    raid_embed = discord.Embed(
                        title=str(pokemon_name) + ' Raid',
                        description='Gym: **' + str(gym_name) + '**' +
                        '\nRaid Ends: **' + str(
                            time.strftime('%I:%M %p',
                                          time.localtime(remaining_time))) +
                        '**' + '\nReported by: __' +
                        str(ctx.message.author.name) + '__' +
                        '\n\nhttps://www.google.com/maps?q=loc:' +
                        str(gym_data[0][2]) + ',' + str(gym_data[0][3]),
                        color=get_team_color(gym_team_id))
                    thumbnail_image_url = 'https://bitbucket.org/anzmap/sprites/raw/HEAD/' + str(
                        pokemon_id) + '.png'
                    raid_embed.set_thumbnail(url=thumbnail_image_url)
                    await bot.send_message(discord.Object(id=log_channel),
                                           embed=raid_embed)

                    print(
                        str(ctx.message.author.name) + ' updated ' +
                        str(raw_raid_level) + ' Egg to ' + str(pokemon_name) +
                        ' Raid at ' + str(gym_name) + ' with ' +
                        str(raw_time_remaining) + ' minutes left.')

                else:
                    cursor.execute(
                        "INSERT INTO raids("
                        "id, external_id, fort_id , level, "
                        "pokemon_id, move_1, move_2, time_spawn, "
                        "time_battle, time_end, cp, reported_by)"
                        "VALUES "
                        "(null, null, " + str(gym_id) + ", " +
                        str(raw_raid_level) + ", " + str(pokemon_id) +
                        ", null, null, "
                        "null, " +
                        str(calendar.timegm(current_time.timetuple())) + ", " +
                        str(remaining_time) + ", null, '" +
                        str(ctx.message.author.name) + "');")
                    await bot.say(
                        'Added ' + str(pokemon_name) + ' Raid' + '\nGym: **' +
                        str(gym_id) + ': ' + str(gym_name) + '**' +
                        '\nRaid Ends: **' + str(
                            time.strftime('%I:%M %p',
                                          time.localtime(remaining_time))) +
                        '**' + '\nTime Left: **' + str(raw_time_remaining) +
                        ' minutes**')

                    raid_embed = discord.Embed(
                        title=str(pokemon_name) + ' Raid',
                        description='Gym: **' + str(gym_name) + '**' +
                        '\nRaid Ends: **' + str(
                            time.strftime('%I:%M %p',
                                          time.localtime(remaining_time))) +
                        '**' + '\nReported by: __' +
                        str(ctx.message.author.name) + '__' +
                        '\n\nhttps://www.google.com/maps?q=loc:' +
                        str(gym_data[0][2]) + ',' + str(gym_data[0][3]),
                        color=get_team_color(gym_team_id))
                    thumbnail_image_url = 'https://bitbucket.org/anzmap/sprites/raw/HEAD/' + str(
                        pokemon_id) + '.png'
                    raid_embed.set_thumbnail(url=thumbnail_image_url)
                    await bot.send_message(discord.Object(id=log_channel),
                                           embed=raid_embed)
                    print(
                        str(ctx.message.author.name) + ' reported a ' +
                        str(pokemon_name) + ' raid at ' + str(gym_name) +
                        ' with ' + str(raw_time_remaining) + ' minutes left.')

            # Check if fort_id exists in fort_sightings.  If so update the entry, otherwise enter as a new entry.
            cursor.execute(
                "SELECT id, fort_id, team FROM fort_sightings WHERE fort_id='"
                + str(gym_id) + "';")
            fs_count = cursor.rowcount
            if (fs_count):
                cursor.execute("UPDATE fort_sightings SET team='" +
                               str(gym_team_id) + "' WHERE fort_id='" +
                               str(gym_id) + "';")
            else:
                cursor.execute(
                    "INSERT INTO fort_sightings(fort_id, team, last_modified) VALUES ("
                    + str(gym_id) + ", " + str(gym_team_id) + ", " +
                    str(calendar.timegm(current_time.timetuple())) + ");")

            database.commit()

        except Exception as e:
            message = e.args[0]
            await bot.say(message)
            print(message)

        except:
            database.rollback()
Example #7
0
async def activeraids(ctx):
    if ctx and ctx.message.channel.id == str(bot_channel):
        database.ping(True)
        current_time = datetime.datetime.utcnow()
        try:
            cursor.execute(
                "SELECT f.id, f.name, r.level, r.pokemon_id, r.time_battle, r.time_end FROM forts f JOIN raids r ON f.id=r.fort_id WHERE r.time_end>'"
                + str(calendar.timegm(current_time.timetuple())) +
                "' ORDER BY r.level DESC, r.time_end;")
            raid_data = cursor.fetchall()
            raid_count = cursor.rowcount

            await bot.say('There are currently ' + str(raid_count) +
                          ' active raids.')
            active_raids_l5 = ''
            active_raids_l4 = ''
            active_raids_l3 = ''
            active_raids_l2 = ''
            active_raids_l1 = ''
            for raid in raid_data:
                fort_id, gym_name, raid_level, raid_pokemon_id, raid_time_battle, raid_time_end = raid
                if (raid_pokemon_id == 0):
                    raid_pokemon_name = 'Egg - Legendary'
                else:
                    raid_pokemon_name = pokejson[str(raid_pokemon_id)]

                if (raid_level == 5):
                    active_raids_l5 += str(
                        time.strftime('%I:%M %p',
                                      time.localtime(raid_time_end))
                    ) + ' : ' + str(raid_pokemon_name) + ' : ' + str(
                        gym_name) + ' Gym (' + str(fort_id) + ')\n'
                elif (raid_level == 4):
                    active_raids_l4 += str(
                        time.strftime('%I:%M %p',
                                      time.localtime(raid_time_end))
                    ) + ' : ' + str(raid_pokemon_name) + ' : ' + str(
                        gym_name) + ' Gym (' + str(fort_id) + ')\n'
                elif (raid_level == 3):
                    active_raids_l3 += str(
                        time.strftime('%I:%M %p',
                                      time.localtime(raid_time_end))
                    ) + ' : ' + str(raid_pokemon_name) + ' : ' + str(
                        gym_name) + ' Gym (' + str(fort_id) + ')\n'
                elif (raid_level == 2):
                    active_raids_l2 += str(
                        time.strftime('%I:%M %p',
                                      time.localtime(raid_time_end))
                    ) + ' : ' + str(raid_pokemon_name) + ' : ' + str(
                        gym_name) + ' Gym (' + str(fort_id) + ')\n'
                else:
                    active_raids_l1 += str(
                        time.strftime('%I:%M %p',
                                      time.localtime(raid_time_end))
                    ) + ' : ' + str(raid_pokemon_name) + ' : ' + str(
                        gym_name) + ' Gym (' + str(fort_id) + ')\n'

            raid_report = ''
            if (active_raids_l5 != ''):
                raid_report += '**Legendary**\n' + active_raids_l5
            if (active_raids_l4 != ''):
                raid_report += '\n**Other**\n' + active_raids_l4
            if (active_raids_l3 != ''):
                raid_report += '\n**LEVEL 3**\n' + active_raids_l3
            if (active_raids_l2 != ''):
                raid_report += '\n**LEVEL 2**\n' + active_raids_l2
            if (active_raids_l1 != ''):
                raid_report += '\n**LEVEL 1**\n' + active_raids_l1

            if (raid_report != ''):
                await bot.say('**Active Raids**\n' + str(raid_report))

            database.commit()
        except:
            database.rollback()
            await bot.say('There are no active raids.')
Example #8
0
async def deleteraid(ctx, fort_id):
    if ctx and ctx.message.channel.id == str(bot_channel):
        try:
            database.ping(True)
            current_time = datetime.datetime.utcnow()
            valid_user_query = "SELECT fort_id FROM raids WHERE fort_id='" + str(
                fort_id) + "' AND time_end>'" + str(
                    calendar.timegm(current_time.timetuple())
                ) + "' AND reported_by='" + str(ctx.message.author.name) + "';"
            print(str(valid_user_query) + " : ")
            cursor.execute(valid_user_query)
            valid_user_count = cursor.rowcount
            print("count - " + str(valid_user_count) + " : ")
            # Check if command is coming from original raid reporter or an admin
            if ((valid_user_count == 0)
                    and (admin_role_id
                         not in [role.id
                                 for role in ctx.message.author.roles])):
                raise Exception(
                    'Raid can only be deleted by original reporter or an Admin.'
                )

            if fort_id.isnumeric():
                print("fort id" + str(fort_id) + " : ")
                cursor.execute(
                    "SELECT id, name, lat, lon FROM forts WHERE id='" +
                    str(fort_id) + "';")
                gym_data = cursor.fetchall()
                count = cursor.rowcount
                fort_id = gym_data[0][0]
                gym_name = gym_data[0][1]
                gym_lat = gym_data[0][2]
                gym_lon = gym_data[0][3]
                # Gym id is valid and returned 1 result

                if (count == 1):
                    print(str(fort_id) + ":" + str(gym_name))
                    cursor.execute(
                        "SELECT id, fort_id, level, pokemon_id, time_battle, time_end FROM raids WHERE fort_id='"
                        + str(fort_id) + "' AND time_end>'" +
                        str(calendar.timegm(current_time.timetuple())) + "';")
                    raid_data = cursor.fetchall()
                    raid_count = cursor.rowcount

                    raid_id, raid_fort_id, raid_level, raid_pokemon_id, raid_time_battle, raid_time_end = raid_data[
                        0]
                    #                    print("raid data " + raid_pokemon_id)
                    if (raid_pokemon_id == 0):
                        raid_pokemon_name = 'Egg (Umkonwn)'
                        thumbnail_image_url = get_egg_url(raid_level)
                    else:
                        raid_pokemon_name = pokejson[str(raid_pokemon_id)]
                        thumbnail_image_url = 'https://bitbucket.org/anzmap/sprites/raw/HEAD/' + str(
                            raid_pokemon_id) + '.png'

                    await bot.say(
                        '**Deleted Raid**' + '\nGym: **' + str(fort_id) +
                        ': ' + str(gym_name) + '**' + '\nPokemon: ** ' +
                        str(raid_pokemon_name).capitalize() + '**' +
                        '\nStart\Hatch Time: **' + str(
                            time.strftime('%I:%M %p',
                                          time.localtime(raid_time_battle))) +
                        '**' + '\nEnd Time: **' + str(
                            time.strftime('%I:%M %p',
                                          time.localtime(raid_time_end))) +
                        '**')
                    delete_raid_query = "DELETE FROM raids WHERE fort_id='" + str(
                        fort_id) + "' AND time_end>'" + str(
                            calendar.timegm(current_time.timetuple())) + "';"
                    cursor.execute(delete_raid_query)

                    gym_team_id = 0
                    raid_embed = discord.Embed(
                        title='~~' + str(raid_pokemon_name).capitalize() +
                        '~~ **RAID DELETED**',
                        description='Gym: ~~' + str(gym_name) + ' Gym~~' +
                        '\nRaid Ends: ~~' + str(
                            time.strftime('%I:%M %p',
                                          time.localtime(raid_time_end))) +
                        '~~' + '\nDeleted by: __' +
                        str(ctx.message.author.name) + '__',
                        color=get_team_color(gym_team_id))
                    raid_embed.set_thumbnail(url=thumbnail_image_url)
                    await bot.send_message(discord.Object(id=log_channel),
                                           embed=raid_embed)

                    print(
                        str(ctx.message.author.name) + ' deleted raid at ' +
                        str(fort_id) + ': ' + str(gym_name) + '.')
                else:
                    raise Exception('Gym ID provided is not valid.')

            else:
                raise Exception(
                    'Enter the numeric ID of the gym where the raid is located.'
                )

            database.commit()
        except Exception as e:
            message = e.args[0]
            await bot.send_message(discord.Object(id=bot_channel), message)
        except:
            database.rollback()
            await bot.say('Raid at **' + str(fort_id) + ': ' + str(gym_name) +
                          '** does not exist.')
Example #9
0
import MySQLdb
import discord
from discord.ext import commands
import asyncio
from pokemonlist import pokemon, pokejson, base_stats, cp_multipliers
from config import bot_channel, token, host, user, password, database, website, log_channel, raids_channel
import datetime
import calendar
import math
import sys
import traceback

bot = commands.Bot(command_prefix='.')  #set prefix to .

database = MySQLdb.connect(host, user, password, database)
database.ping(True)
cursor = database.cursor()


def find_pokemon_id(name):
    if name == 'Nidoran-F':
        return 29
    elif name == 'Nidoran-M':
        return 32
    elif name == 'Mr-Mime':
        return 122
    elif name == 'Ho-Oh':
        return 250
    elif name == 'Mime-Jr':
        return 439
    else:
Example #10
0
async def raid(
    ctx, arg, arg2, arg3, arg4
):  #arg = gym name, arg2 = pokemon name, arg3 = level, arg4 = time remaining
    if ctx and ctx.message.channel.id == str(bot_channel) and str(
            arg2).lower() in pokemon:
        """example: ^raid "Canandagua National Bank Clock Tower" Lugia 5 45"""

        pokemon_id = find_pokemon_id(str(arg2).capitalize())
        pokecp = find_pokecp(str(arg2).capitalize())
        now = datetime.datetime.utcnow() + timedelta(minutes=int(arg4))
        time = datetime.datetime.utcnow() + timedelta()

        try:
            cursor.execute("SELECT gym_id FROM gymdetails WHERE name LIKE '" +
                           str(arg) + "%';")
            gym_id = str(cursor.fetchall())
            gym_id = gym_id.split(',')
            gym_id = gym_id[0].split('((')
            cursor.execute("REPLACE INTO raid("
                           "gym_id, level, spawn, start, "
                           "end, pokemon_id, cp, move_1, "
                           "move_2, last_scanned)"
                           " VALUES (" + str('{}').format(gym_id[1]) + ", " +
                           str(arg3) + ", " + str("'{}'").format(time) + ", " +
                           str("'{}'").format(time) + ", " +
                           str("'{}'").format(now) + ", " + str(pokemon_id) +
                           ", " + str(pokecp) + ", 1, 1, " +
                           str("'{}'").format(time) + ");")
            #"VALUES (%s, %s, "+str("'{}'").format(time)+", "+str("'{}'").format(time)+", "+str("'{}'").format(now)+", %s, %s, 1, 1, "+str("'{}'").format(time)+");", (str(gym_id[1]), str(pokemon_id), str(arg3), str(arg5)))
            cursor.execute("UPDATE gym SET last_modified = '" + str(time) +
                           "', last_scanned = '" + str(time) +
                           "' WHERE gym_id = " + str(gym_id[1]) + ";")
            database.ping(True)
            database.commit()
            await bot.say('Successfully added your raid to the live map.')
            await bot.send_message(
                discord.Object(id=log_channel),
                str(ctx.message.author.name) + ' said there was a ' +
                str(arg2) + ' raid going on at ' + str(arg)) and print(
                    str(ctx.message.author.name) + ' said there was a ' +
                    str(arg2) + ' raid going on at ' + str(arg))
            #await bot.say("VALUES ("+str('{}').format(gym_id[1])+", "+str(arg3)+", "+str("'{}'").format(time)+", "+str("'{}'").format(time)+", "+str("'{}'").format(now)+", "+str(pokemon_id)+", "+str(pokecp)+", 1, 1, "+str("'{}'").format(time)+");")
            #await bot.say("UPDATE gym SET last_modified = '"+str(time)+"', last_scanned = '"+str(time)+"' WHERE gym_id = "+str(gym_id[1])+";")

        except:
            #database.connect()
            database.rollback()
            await bot.say(
                'Unsuccesful in database query, your raid was not added to the live map.'
            )
            await bot.say(
                "Could not find `{}` in my database. Please check your gym name. \nuse `^gym gym-name` to try and look it up"
                .format(arg))
            await bot.say("VALUES (" + str('{}').format(gym_id[1]) + ", " +
                          str(arg3) + ", " + str("'{}'").format(time) + ", " +
                          str("'{}'").format(time) + ", " +
                          str("'{}'").format(now) + ", " + str(pokemon_id) +
                          ", " + str(pokecp) + ", 1, 1, " +
                          str("'{}'").format(time) + ");")
            await bot.say("UPDATE gym SET last_modified = '" + str(time) +
                          "', last_scanned = '" + str(time) +
                          "' WHERE gym_id = " + str(gym_id[1]) + ";")
            tb = traceback.print_exc(file=sys.stdout)
            print(tb)