Skip to content
This repository has been archived by the owner on Jul 12, 2018. It is now read-only.

Commit

Permalink
Merge pull request #26 from dandesousa/address_detection
Browse files Browse the repository at this point in the history
$map command
  • Loading branch information
dandesousa committed Sep 4, 2017
2 parents 4bed071 + d0e10b5 commit 04a710d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/raid_coordinator/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
import traceback
import pytz
import urllib.parse
from datetime import datetime, timedelta


Expand Down Expand Up @@ -243,6 +244,7 @@ def get_raid_summary_embed(creator, channel_name, expiration_dt, text):
embed.add_field(name="$leaveraid", value="Removes you from this raid.", inline=False)
embed.add_field(name="$listraid", value="Shows all current members of this raid channel.", inline=False)
embed.add_field(name="$endraid", value="Ends the raid and closes the channel.", inline=False)
embed.add_field(name="$map <address>", value="Gets a link to directions for the address provided.", inline=False)
embed.set_footer(text='You can also leave the raid with the {} reaction below.'.format(get_leave_emoji()))
embed.color = discord.Color.green()
return embed
Expand Down Expand Up @@ -458,6 +460,23 @@ async def uninvite_user_from_raid(channel, user):
await client.remove_reaction(announcement_message, get_join_emoji(), user)


async def post_google_maps_directions(channel, address):
"""Simplified post that sends a google maps url to the server.
Uses the address posted by the user using the map url api. This api
is preferrable to geocoding for raids, since it has no api limits and
handle informal addresses and geocoding on google's side.
"""
url_data = {
'api': '1',
'destination': address
}
query = urllib.parse.urlencode(url_data)
base_url = 'https://www.google.com/maps/dir/?'
url = base_url + query
await client.send_message(channel, embed=get_success_embed("Directions: {}".format(url)))


async def list_raid_members(channel):
"""Lists the members of a raid channel in the channel."""
members = get_raid_members(channel)
Expand Down Expand Up @@ -645,6 +664,10 @@ async def on_message(message):
elif is_raid_channel(channel) and message.content.startswith('$leaveraid'):
await uninvite_user_from_raid(channel, user)

elif is_raid_channel(channel) and message.content.startswith('$map'):
address = message.content.replace('$map', '', 1)
await post_google_maps_directions(channel, address)

elif is_raid_channel(channel) and message.content.startswith('$listraid'):
await list_raid_members(channel)

Expand Down

0 comments on commit 04a710d

Please sign in to comment.