def test_get_team_name(self): self.assertEqual(get_team_name(0), 'Unknown') self.assertEqual(get_team_name(1), 'Mystic') self.assertEqual(get_team_name(2), 'Valor') self.assertEqual(get_team_name(3), 'Instinct') self.assertEqual(get_team_name(4), 'Unknown')
async def incubate(ctx, gym_id, remaining_time): channel = discord.Object(id=bot_channel) current_time = datetime.datetime.utcnow() current_epoch_time = calendar.timegm(current_time.timetuple()) sleep_time = remaining_time - current_epoch_time await bot.send_message( channel, '*Incubating Egg at Gym ID: ' + str(gym_id) + '. Will auto hatch in **' + str(sleep_time) + '** seconds.*') print('Auto-incubating Legendary egg at Gym ID: ' + str(gym_id) + '. Will auto hatch in ' + str(sleep_time) + ' seconds.') # Let's pause this thread until hatch time await asyncio.sleep(sleep_time) # Need to check if egg still exists before updating it and posting. Otherwise, someone may have deleted it. cursor.execute("SELECT id FROM raids WHERE fort_id='" + str(gym_id) + "' AND time_end>'" + str(current_epoch_time) + "';") raid_check = cursor.rowcount if (raid_check == 1): cursor.execute("UPDATE raids SET pokemon_id='" + str(legendary_id) + "' WHERE fort_id='" + str(gym_id) + "' AND time_end>'" + str(current_epoch_time) + "';") database.commit() cursor.execute( "SELECT f.id, f.name, f.lat, f.lon, fs.team, r.level, r.pokemon_id, r.time_end FROM forts f JOIN raids r ON f.id=r.fort_id JOIN fort_sightings fs ON f.id = fs.fort_id WHERE f.id='" + str(gym_id) + "' AND r.time_end>'" + str(current_epoch_time) + "';") raid_data = cursor.fetchall() gym_id, gym_name, gym_lat, gym_lon, gym_team_id, raid_level, raid_pokemon_id, time_end = raid_data[ 0] await bot.send_message( channel, 'Auto updated **Level ' + str(raid_level) + ' Egg to ' + str(pokejson[str(raid_pokemon_id)]) + ' Raid' + '**' + '\nGym: **' + str(gym_id) + ': ' + str(gym_name) + ' Gym' + '**' + '\nRaid Ends: **' + str(time.strftime('%I:%M %p', time.localtime(time_end))) + '**' + '\nTeam: **' + str(get_team_name(gym_team_id)) + '**') print('Legendary egg at Gym ID: ' + str(gym_id) + ' hatched into ' + str(pokejson[str(raid_pokemon_id)])) raid_embed = discord.Embed( title='**Level ' + str(raid_level) + ' ' + str(pokejson[str(raid_pokemon_id)]) + ' Raid**', description='Gym: **' + str(gym_name) + ' Gym**' + '\nRaid Ends: **' + str(time.strftime('%I:%M %p', time.localtime(time_end))) + '**' + '\nTeam: **' + str(get_team_name(gym_team_id)) + '**' + '\nReported by: __' + str(ctx.message.author.name) + '__' + '\n\nhttps://www.google.com/maps?q=loc:' + str(gym_lat) + ',' + str(gym_lon), color=get_team_color(gym_team_id)) thumbnail_image_url = 'https://bitbucket.org/anzmap/sprites/raw/HEAD/' + str( raid_pokemon_id) + '.png' raid_embed.set_thumbnail(url=thumbnail_image_url) await bot.send_message(discord.Object(id=log_channel), embed=raid_embed) else: print( 'Auto-hatch cancelled. Egg was not found, possibly deleted before hatch.' )
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 s.player_name FROM raids r JOIN scoreboard s ON r.id = s.raid_id WHERE r.fort_id='" + str( fort_id) + "' AND r.time_end>'" + str( calendar.timegm(current_time.timetuple()) ) + "' AND s.player_name='" + str( ctx.message.author.name) + "';" print(str(valid_user_query)) cursor.execute(valid_user_query) valid_user_count = cursor.rowcount print(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(): 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): cursor.execute( "SELECT r.id, r.fort_id, r.level, r.pokemon_id, r.time_battle, r.time_end, fs.team FROM raids r JOIN fort_sightings fs ON r.fort_id = fs.fort_id WHERE r.fort_id='" + str(fort_id) + "' AND r.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_gym_team = raid_data[ 0] if (raid_pokemon_id == 0): raid_pokemon_name = 'Unknown (Egg)' 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 the following raid**' + '\nGym: **' + str(fort_id) + ': ' + str(gym_name) + ' Gym**' + '\nLevel: **' + str(raid_level) + '**' + '\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) # Deduct the points bot.loop.create_task(deduct_it(ctx, raid_id)) raid_embed = discord.Embed( title='~~Level ' + str(raid_level) + ' ' + str(raid_pokemon_name).capitalize() + ' Raid~~ **RAID DELETED**', description='Gym: ~~' + str(gym_name) + ' Gym~~' + '\nRaid Ends: ~~' + str( time.strftime('%I:%M %p', time.localtime(raid_time_end))) + '~~' + '\nTeam: ~~' + str(get_team_name(raid_gym_team)) + '~~' + '\nDeleted by: __' + str(ctx.message.author.name) + '__', color=get_team_color(raid_gym_team)) 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 the Level ' + str(raid_level) + ' Raid at the ' + str(fort_id) + ': ' + str(gym_name) + ' Gym.') 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 the **' + str(fort_id) + ': ' + str(gym_name) + ' Gym** does not exist.')
async def raid(ctx, raw_gym_name, raw_pokemon_name, raw_raid_level, raw_time_remaining, raw_team): 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 = get_team_id(raw_team) database.ping(True) try: if ((int(raw_raid_level) < 1) or (int(raw_raid_level) > 5)): raise Exception( 'Invalid raid level entered. Enter value between 1-5.') 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( 'Unsuccesful add to the map. 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( 'Unsuccesful add to the map. !raid "*gym_name*" *pokemon_name* *raid_level* *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))) + '**' + '\nTeam: **' + str(get_team_name(gym_team_id)) + '**' + '\n\n`No points were scored because raid was already reported.`' ) 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)" "VALUES " "(null, null, " + str(gym_id) + ", " + str(raw_raid_level) + ", " + str(pokemon_id) + ", null, null, " "null, " + str(remaining_time) + ", " + str(est_end_time) + ", null);") await bot.say( 'Added new **Level ' + str(raw_raid_level) + ' ' + str(pokemon_name) + '**' + '\nGym: **' + 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))) + '**' + '\nTime Left Until Hatch: **' + str(raw_time_remaining) + ' minutes**' + '\nTeam: **' + str(get_team_name(gym_team_id)) + '**') raid_embed = discord.Embed( title='**Level ' + str(raw_raid_level) + ' Egg**', description='Gym: **' + 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))) + '**' + '\nTeam: **' + str(get_team_name(gym_team_id)) + '**' + '\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_channel), embed=raid_embed) print( str(ctx.message.author.name) + ' reported a ' + str(pokemon_name) + ' at ' + str(gym_id) + ': ' + str(gym_name) + ' gym with ' + str(raw_time_remaining) + ' minutes left.') bot.loop.create_task( score_it(ctx, gym_id, est_end_time, ADDED_EGG)) 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 **Level ' + str(raw_raid_level) + ' Egg to ' + str(pokemon_name) + ' Raid' + '**' + '\nGym: **' + str(gym_id) + ': ' + str(gym_name) + ' Gym' + '**' + '\nRaid Ends: **' + str( time.strftime('%I:%M %p', time.localtime(remaining_time))) + '**' + '\nTeam: **' + str(get_team_name(gym_team_id)) + '**') raid_embed = discord.Embed( title='**Level ' + str(raw_raid_level) + ' ' + str(pokemon_name) + ' Raid**', description='Gym: **' + str(gym_name) + ' Gym**' + '\nRaid Ends: **' + str( time.strftime('%I:%M %p', time.localtime(remaining_time))) + '**' + '\nTeam: **' + str(get_team_name(gym_team_id)) + '**' + '\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 the ' + str(raw_raid_level) + ' Egg to ' + str(pokemon_name) + ' Raid at ' + str(gym_name) + ' gym (' + str(get_team_name(gym_team_id)) + ') with ' + str(raw_time_remaining) + ' minutes left.') bot.loop.create_task( score_it(ctx, gym_id, remaining_time, HATCHED_EGG)) 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)" "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);") await bot.say( 'Added new **Level ' + str(raw_raid_level) + ' ' + str(pokemon_name) + ' Raid' + '**' + '\nGym: **' + str(gym_id) + ': ' + str(gym_name) + ' Gym**' + '\nRaid Ends: **' + str( time.strftime('%I:%M %p', time.localtime(remaining_time))) + '**' + '\nTime Left: **' + str(raw_time_remaining) + ' minutes**' + '\nTeam: **' + str(get_team_name(gym_team_id)) + '**') raid_embed = discord.Embed( title='**Level ' + str(raw_raid_level) + ' ' + str(pokemon_name) + ' Raid**', description='Gym: **' + str(gym_name) + ' Gym**' + '\nRaid Ends: **' + str( time.strftime('%I:%M %p', time.localtime(remaining_time))) + '**' + '\nTeam: **' + str(get_team_name(gym_team_id)) + '**' + '\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) + ' gym (' + str(get_team_name(gym_team_id)) + ') with ' + str(raw_time_remaining) + ' minutes left.') bot.loop.create_task( score_it(ctx, gym_id, remaining_time, ADDED_BOSS)) # 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()