Skip to content

Commit

Permalink
Merge pull request #251 from european-epc-competence-center/status_mo…
Browse files Browse the repository at this point in the history
…dule_improved

Status module improved
  • Loading branch information
vranki authored Jun 20, 2024
2 parents 7c39f98 + 8aae392 commit 1f44f1a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions modules/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async def matrix_message(self, bot, room, event):
args = event.body.split()
args.pop(0)
if len(args) < 1 or args[0] == "help":
await bot.send_text(room, self.help())
await self.command_help(bot, room)
elif args[0] == "show":
if len(args) > 1:
await self.send_status(bot=bot, room=room, user=args[1])
Expand All @@ -31,7 +31,7 @@ async def matrix_message(self, bot, room, event):
bot.must_be_admin(room, event)
self.status = dict()
else:
if(event.sender in self.status.keys()):
if (event.sender in self.status.keys()):
self.status.pop(event.sender)
bot.save_settings()
await bot.send_text(room, f"Cleared status of {event.sender}")
Expand All @@ -49,9 +49,9 @@ async def matrix_message(self, bot, room, event):
def drop_old_messages(self):
"Drop all messages which are older than the current TTL."
self.logger.debug(f"status messages: {self.status}")
dropping = [x for x in self.status.keys() if type(self.status[x]) is not tuple or len(self.status[x]) < 2 or time.time() > self.status[x][1] + self.ttl]
dropping = [x for x in self.status.keys() if type(self.status[x]) is str or len(self.status[x]) < 2 or time.time() > self.status[x][1] + self.ttl]
for x in dropping:
self.logger.debug(f"Dropping old status message {self.status[x]} for user {x}")
self.logger.info(f"Dropping old status message {self.status[x]} for user {x}. (now = {time.time()}, ttl = {self.ttl})")
self.status.pop(x)

async def send_status(self, bot, room, user=None):
Expand Down Expand Up @@ -79,8 +79,8 @@ def set_settings(self, data):
if data.get("user_status_list_ttl"):
self.ttl = data["user_status_list_ttl"]

def help(self):
return """
async def command_help(self, bot, room):
msg = """
Store a status message per user and display them.
Usage:
!status clear - clear my status
Expand All @@ -90,3 +90,7 @@ def help(self):
!status help - show this text
!status [status] - set your status
"""
await bot.send_html(room, msg, "Status module help")

def help(self):
return "Save a custom (status) message for users and allows to query them."

0 comments on commit 1f44f1a

Please sign in to comment.