def set_location(bot: Bot, update: Update, args):
"""
Handles /location command
:param bot:
:param update:
:param args:
:return:
"""
global data
chat_id = update.message.chat_id
if chat_id in data.conversations:
if len(args) < 1:
send_help(bot, chat_id, "set_location", "Please indicate GPS coordinates or the name of a place")
return
else:
send_chat_action(bot=bot, chat_id=chat_id, action=ChatAction.FIND_LOCATION)
r = requests.get("{}{}?format=json&limit=1&bounded=0"
.format(location_search_url, ' '.join([str(x) for x in args])))
try:
conversation = data.conversations[chat_id]
latitude = r.json()[0]["lat"]
longitude = r.json()[0]["lon"]
conversation.session.update_location(latitude, longitude)
send_message(bot, chat_id, "location_updated")
conversation.refresh_users()
send_location(latitude=latitude, longitude=longitude, bot=bot, chat_id=chat_id)
except AttributeError:
send_help(bot, chat_id, "set_location", "Facebook token needs to be set first")
else:
send_error(bot=bot, chat_id=chat_id, name="account_not_setup")
评论列表
文章目录