Added initial bot module for bot mgmt commands.
This commit is contained in:
parent
7ac37e1831
commit
6cf40488d4
13
README.md
13
README.md
|
@ -15,6 +15,13 @@ Support room: #hemppa:hacklab.fi - https://matrix.to/#/#hemppa:hacklab.fi
|
|||
|
||||
## 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
|
||||
|
||||
Prints help on existing modules.
|
||||
|
@ -23,14 +30,20 @@ Prints help on existing modules.
|
|||
|
||||
Simple example module that just echoes what user said.
|
||||
|
||||
* !echo Hello, world!
|
||||
|
||||
### Metar
|
||||
|
||||
Aviation weather metar service access.
|
||||
|
||||
* !metar eftp
|
||||
|
||||
### TAF
|
||||
|
||||
Aviation weather TAF service access.
|
||||
|
||||
* !taf eftp
|
||||
|
||||
### Uptime
|
||||
|
||||
Prints bot uptime.
|
||||
|
|
4
bot.py
4
bot.py
|
@ -234,7 +234,8 @@ class Bot:
|
|||
if self.join_on_invite:
|
||||
print('Note: Bot will join rooms if invited')
|
||||
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:
|
||||
print('Client was not able to log in, check env variables!')
|
||||
|
||||
|
@ -246,5 +247,6 @@ try:
|
|||
except KeyboardInterrupt:
|
||||
if bot.poll_task:
|
||||
bot.poll_task.cancel()
|
||||
bot.bot_task.cancel()
|
||||
|
||||
bot.stop()
|
||||
|
|
|
@ -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')
|
Loading…
Reference in New Issue