Add map location

release-1.0.0
DustyP 8 years ago
parent 09b87e8278
commit f7c4a9f04b

@ -158,7 +158,7 @@ class Fun:
await msg.edit(content=f'{member.mention}{trans*(20-i)}{self.bot.unicode_emojis["left_fist"]}') await msg.edit(content=f'{member.mention}{trans*(20-i)}{self.bot.unicode_emojis["left_fist"]}')
await asyncio.sleep(0.1) await asyncio.sleep(0.1)
await msg.edit(content=f'{self.bot.unicode_emojis["boom"]}') await msg.edit(content=f'{self.bot.unicode_emojis["boom"]}')
await asyncio.sleep(0.1) await asyncio.sleep(0.5)
await msg.edit(content=f'{self.bot.unicode_emojis["boom"]} <---- {member.mention} that was you...') await msg.edit(content=f'{self.bot.unicode_emojis["boom"]} <---- {member.mention} that was you...')

@ -16,6 +16,7 @@ mpl.use('Agg')
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap from mpl_toolkits.basemap import Basemap
from io import BytesIO from io import BytesIO
from itertools import chain
config_dir = 'config/' config_dir = 'config/'
admin_id_file = 'admin_ids' admin_id_file = 'admin_ids'
@ -557,6 +558,53 @@ class Utils:
loc = await response.json() loc = await response.json()
await self.bot.loop.run_in_executor(self.bot.tpe, gen_image, loc) await self.bot.loop.run_in_executor(self.bot.tpe, gen_image, loc)
@commands.command(name='location', aliases=['loc', 'map'])
async def map_location(self, ctx, *, location):
def draw_map(m, scale=1):
# draw a shaded-relief image
m.shadedrelief(scale=scale)
m.fillcontinents(color="#FFDDCC", lake_color='#DDEEFF')
m.drawmapboundary(fill_color="#DDEEFF")
m.drawcoastlines(color='gray')
m.drawcountries(color='gray')
m.drawstates(color='gray')
# lats and longs are returned as a dictionary
lats = m.drawparallels(np.linspace(-90, 90, 30))
lons = m.drawmeridians(np.linspace(-180, 180, 90))
# keys contain the plt.Line2D instances
lat_lines = chain(*(tup[1][0] for tup in lats.items()))
lon_lines = chain(*(tup[1][0] for tup in lons.items()))
all_lines = chain(lat_lines, lon_lines)
# cycle through these lines and set the desired style
for line in all_lines:
line.set(linestyle='-', alpha=0.3, color='gray')
def gen_image(loc):
lat = loc['lat']
lon = loc['lng']
plt.figure(figsize=(4, 4))
m = Basemap(projection='lcc', width=2E6, height=2E6, resolution='i', lat_0=lat, lon_0=lon)
draw_map(m)
x, y = m(lon, lat)
plt.plot(x, y, 'ok', markersize=5, color='red')
plt.text(x, y, ' Palmer', fontsize=12, color='red')
plt.tight_layout()
img = BytesIO()
plt.savefig(img, format='png', transparent=True)
img.seek(0)
self.bot.loop.create_task(ctx.send(file=discord.File(img, f'{location} map.png')))
async with self.bot.aio_session.get(
f'https://api.opencagedata.com/geocode/v1/json?q={location}&key={bot.geo_api}') as result:
data = await result.json()
await self.bot.loop.run_in_executor(self.bot.tpe, gen_image, data['results'][0]['geometry'])
# TODO Create Help command # TODO Create Help command

@ -65,6 +65,7 @@ class Geeksbot(commands.Bot):
self.spam_list = {} self.spam_list = {}
self.gcs_service = build('customsearch', 'v1', developerKey=self.bot_secrets['google_search_key']) self.gcs_service = build('customsearch', 'v1', developerKey=self.bot_secrets['google_search_key'])
self.tpe = futures.ThreadPoolExecutor() self.tpe = futures.ThreadPoolExecutor()
self.geo_api = '2d4e419c2be04c8abe91cb5dd1548c72'
self.unicode_emojis: Dict[str, str] = { self.unicode_emojis: Dict[str, str] = {
'x': '', 'x': '',
'y': '', 'y': '',

Loading…
Cancel
Save