add apod bot commands help, stats and clear

This commit is contained in:
Frank Becker 2020-03-15 18:11:00 +01:00
parent fb10d73f61
commit facec3111d
2 changed files with 35 additions and 5 deletions

View File

@ -226,6 +226,10 @@ See https://apod.nasa.gov/apod/astropix.html
Command: Command:
* !apod - Sends latest Astronomy Picture of the Day to the room * !apod - Sends latest Astronomy Picture of the Day to the room
* !apod YYYY-MM-DD - date of the APOD image to retrieve (ex. !apod 2020-03-15)
* !apod stats - show information about uri cache
* !apod clear - clear uri cache (Must be done as admin)
* !apod help - show command help
API Key: API Key:

View File

@ -48,6 +48,14 @@ class MatrixModule(BotModule):
if len(args) == 1: if len(args) == 1:
await self.send_apod(bot, room, self.apod_api_url) await self.send_apod(bot, room, self.apod_api_url)
if len(args) == 2: if len(args) == 2:
if args[1] == "stats":
await self.send_stats(bot, room)
elif args[1] == "clear":
bot.must_be_admin(room, event)
await self.clear_uri_cache(bot, room)
elif args[1] == "help":
await self.command_help(bot, room)
else:
date = args[1] date = args[1]
if re.match(self.APOD_DATE_PATTERN, date) is not None: if re.match(self.APOD_DATE_PATTERN, date) is not None:
uri = self.apod_by_date_pi_url + date uri = self.apod_by_date_pi_url + date
@ -125,3 +133,21 @@ class MatrixModule(BotModule):
def help(self): def help(self):
return 'Sends latest Astronomy Picture of the Day to the room. (https://apod.nasa.gov/apod/astropix.html)' return 'Sends latest Astronomy Picture of the Day to the room. (https://apod.nasa.gov/apod/astropix.html)'
async def send_stats(self, bot, room):
msg = f"collected {len(self.matrix_uri_cache)} upload matrix uri's"
await bot.send_text(room, msg)
async def clear_uri_cache(self, bot, room):
self.matrix_uri_cache.clear()
bot.save_settings()
await bot.send_text(room, "cleared uri cache")
async def command_help(self, bot, room):
msg = """commands:
- YYYY-MM-DD - date of the APOD image to retrieve (ex. 2020-03-15)
- stats - show information about uri cache
- clear - clear uri cache (Must be done as admin)
- help - show command help
"""
await bot.send_text(room, msg)