Added initial bot module for bot mgmt commands.

This commit is contained in:
Ville Ranki 2020-01-05 00:28:57 +02:00
parent 7ac37e1831
commit 6cf40488d4
3 changed files with 35 additions and 1 deletions

View File

@ -15,6 +15,13 @@ Support room: #hemppa:hacklab.fi - https://matrix.to/#/#hemppa:hacklab.fi
## Module list ## Module list
### Bot
Bot management commands.
* !bot version - print version of the bot
* !bot quit - quit the bot process (Must be done as bot owner)
### Help ### Help
Prints help on existing modules. Prints help on existing modules.
@ -23,14 +30,20 @@ Prints help on existing modules.
Simple example module that just echoes what user said. Simple example module that just echoes what user said.
* !echo Hello, world!
### Metar ### Metar
Aviation weather metar service access. Aviation weather metar service access.
* !metar eftp
### TAF ### TAF
Aviation weather TAF service access. Aviation weather TAF service access.
* !taf eftp
### Uptime ### Uptime
Prints bot uptime. Prints bot uptime.

4
bot.py
View File

@ -234,7 +234,8 @@ class Bot:
if self.join_on_invite: if self.join_on_invite:
print('Note: Bot will join rooms if invited') print('Note: Bot will join rooms if invited')
print('Bot running as', self.client.user, ', owners', self.owners) print('Bot running as', self.client.user, ', owners', self.owners)
await self.client.sync_forever(timeout=30000) self.bot_task = asyncio.create_task(self.client.sync_forever(timeout=30000))
await self.bot_task
else: else:
print('Client was not able to log in, check env variables!') print('Client was not able to log in, check env variables!')
@ -246,5 +247,6 @@ try:
except KeyboardInterrupt: except KeyboardInterrupt:
if bot.poll_task: if bot.poll_task:
bot.poll_task.cancel() bot.poll_task.cancel()
bot.bot_task.cancel()
bot.stop() bot.stop()

19
modules/bot.py Normal file
View File

@ -0,0 +1,19 @@
import urllib.request
class MatrixModule:
async def matrix_message(self, bot, room, event):
args = event.body.split()
if len(args) == 2:
if args[1]=='quit':
bot.must_be_admin(room, event)
await bot.send_text(room, f'Quitting, as requested')
print(f'{event.sender} commanded bot to quit, so quitting..')
bot.bot_task.cancel()
elif args[1]=='version':
await bot.send_text(room, f'Hemppa version {bot.version} - https://github.com/vranki/hemppa')
else:
await bot.send_text(room, 'Unknown command, sorry.')
def help(self):
return('Bot management commands')