!bot status rewrite:
- Use time.time() for timestamps to prevent DST from breaking uptime calculations - Remove decimal part of uptime - Use time.ctime() format for date - Get list of bot modules
This commit is contained in:
parent
4ce81ec8f3
commit
c4d075a97f
|
@ -1,12 +1,11 @@
|
||||||
import collections
|
import collections
|
||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
from datetime import datetime
|
from datetime import timedelta
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from modules.common.module import BotModule
|
from modules.common.module import BotModule
|
||||||
|
|
||||||
|
|
||||||
class MatrixModule(BotModule):
|
class MatrixModule(BotModule):
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
|
@ -16,7 +15,7 @@ class MatrixModule(BotModule):
|
||||||
|
|
||||||
def matrix_start(self, bot):
|
def matrix_start(self, bot):
|
||||||
super().matrix_start(bot)
|
super().matrix_start(bot)
|
||||||
self.starttime = datetime.now()
|
self.starttime = time.time()
|
||||||
|
|
||||||
async def matrix_message(self, bot, room, event):
|
async def matrix_message(self, bot, room, event):
|
||||||
args = event.body.split(None, 2)
|
args = event.body.split(None, 2)
|
||||||
|
@ -91,7 +90,6 @@ class MatrixModule(BotModule):
|
||||||
}
|
}
|
||||||
await bot.client.room_send(room.room_id, 'm.room.message', content)
|
await bot.client.room_send(room.room_id, 'm.room.message', content)
|
||||||
|
|
||||||
|
|
||||||
async def leave(self, bot, room, event):
|
async def leave(self, bot, room, event):
|
||||||
bot.must_be_admin(room, event)
|
bot.must_be_admin(room, event)
|
||||||
self.logger.info(f'{event.sender} asked bot to leave room {room.room_id}')
|
self.logger.info(f'{event.sender} asked bot to leave room {room.room_id}')
|
||||||
|
@ -118,9 +116,13 @@ class MatrixModule(BotModule):
|
||||||
f'I\'m seeing {usercount} users in {roomcount} rooms. Top ten homeservers: {homeservers}')
|
f'I\'m seeing {usercount} users in {roomcount} rooms. Top ten homeservers: {homeservers}')
|
||||||
|
|
||||||
async def status(self, bot, room):
|
async def status(self, bot, room):
|
||||||
uptime = datetime.now() - self.starttime
|
systime = time.time()
|
||||||
await bot.send_text(room,
|
uptime = str(timedelta(seconds=(systime - self.starttime))).split('.', 1)[0]
|
||||||
f'Uptime {uptime} - system time is {datetime.now()} - loaded {len(bot.modules)} modules.')
|
systime = time.ctime(systime)
|
||||||
|
enabled = sum(1 for module in bot.modules.values() if module.enabled)
|
||||||
|
|
||||||
|
return await bot.send_text(room, f'Uptime: {uptime} - System time: {systime} '
|
||||||
|
f'- {enabled} modules enabled out of {len(bot.modules)} loaded.')
|
||||||
|
|
||||||
async def reload(self, bot, room, event):
|
async def reload(self, bot, room, event):
|
||||||
bot.must_be_owner(event)
|
bot.must_be_owner(event)
|
||||||
|
|
Loading…
Reference in New Issue