Start modules in run(), loc tuning
This commit is contained in:
parent
a773efb7af
commit
680af79fd8
20
bot.py
20
bot.py
|
@ -157,16 +157,6 @@ class Bot:
|
|||
|
||||
self.get_modules()
|
||||
|
||||
print(f'Starting {len(self.modules)} modules..')
|
||||
|
||||
for modulename, moduleobject in self.modules.items():
|
||||
print('Starting', modulename, '..')
|
||||
if "matrix_start" in dir(moduleobject):
|
||||
try:
|
||||
moduleobject.matrix_start(bot)
|
||||
except:
|
||||
traceback.print_exc(file=sys.stderr)
|
||||
|
||||
def stop(self):
|
||||
print(f'Stopping {len(self.modules)} modules..')
|
||||
for modulename, moduleobject in self.modules.items():
|
||||
|
@ -183,6 +173,16 @@ class Bot:
|
|||
print("Logged in with password, access token:", self.client.access_token)
|
||||
|
||||
await self.client.sync()
|
||||
|
||||
print(f'Starting {len(self.modules)} modules..')
|
||||
for modulename, moduleobject in self.modules.items():
|
||||
print('Starting', modulename, '..')
|
||||
if "matrix_start" in dir(moduleobject):
|
||||
try:
|
||||
moduleobject.matrix_start(bot)
|
||||
except:
|
||||
traceback.print_exc(file=sys.stderr)
|
||||
|
||||
self.poll_task = asyncio.get_event_loop().create_task(self.poll_timer())
|
||||
|
||||
if self.client.logged_in:
|
||||
|
|
|
@ -10,7 +10,6 @@ class MatrixModule:
|
|||
async def unknown_cb(self, room, event):
|
||||
if event.msgtype != 'm.location':
|
||||
return
|
||||
|
||||
location_text = event.content['body']
|
||||
|
||||
# Fallback if body is empty
|
||||
|
@ -29,15 +28,14 @@ class MatrixModule:
|
|||
|
||||
osm_link = 'https://www.openstreetmap.org/?mlat=' + latlon[0] + "&mlon=" + latlon[1]
|
||||
|
||||
plain = sender + ' - ' + osm_link
|
||||
html = f'{sender} - <a href={osm_link}>{location_text}</a>'
|
||||
plain = sender + ' 🚩 ' + osm_link
|
||||
html = f'{sender} 🚩 <a href={osm_link}>{location_text}</a>'
|
||||
|
||||
await self.bot.send_html(room, html, plain)
|
||||
|
||||
async def matrix_message(self, bot, room, event):
|
||||
args = event.body.split()
|
||||
args.pop(0)
|
||||
|
||||
if len(args) == 0:
|
||||
await bot.send_text(room, 'Usage: !loc <location name>')
|
||||
if len(args) == 1:
|
||||
|
@ -46,13 +44,11 @@ class MatrixModule:
|
|||
location = geolocator.geocode(query)
|
||||
if location:
|
||||
locationmsg = {
|
||||
"body": "Tampere, Finland",
|
||||
"geo_uri": "geo:61.5,23.766667",
|
||||
"body": str(location.address),
|
||||
"geo_uri": 'geo:' + str(location.latitude) + ',' + str(location.longitude),
|
||||
"msgtype": "m.location",
|
||||
}
|
||||
locationmsg['body'] = location.address
|
||||
locationmsg['geo_uri'] = 'geo:' + str(location.latitude) + ',' + str(location.longitude)
|
||||
await bot.client.room_send(bot.get_room_id(room), 'm.room.message', locationmsg)
|
||||
await bot.client.room_send(room.room_id, 'm.room.message', locationmsg)
|
||||
else:
|
||||
await bot.send_text(room, "Can't find " + query + " on map!")
|
||||
|
||||
|
|
Loading…
Reference in New Issue