fulvia/modules/uptime.py

48 lines
1.2 KiB
Python
Raw Normal View History

2018-03-16 03:13:43 -04:00
#!/usr/bin/env python3
"""
How long the bot has been running.
"""
import datetime
from twisted.internet import defer
2018-03-16 03:13:43 -04:00
from module import commands
def setup(bot):
if "uptime" not in bot.memory:
bot.memory["uptime"] = datetime.datetime.now()
bot.memory["idle_callbacks"] = {}
2018-03-16 03:13:43 -04:00
@commands('uptime')
def uptime(bot, trigger):
""".uptime - Returns the uptime of Fulvia."""
2018-03-16 03:13:43 -04:00
delta = datetime.timedelta(seconds=round((datetime.datetime.now() -
bot.memory["uptime"]).total_seconds()))
2018-05-25 15:21:18 -04:00
bot.msg(f"I've been sitting here for {delta} and I keep going!")
@commands('updick')
def updick(bot, trigger):
""".updick - Returns the uptime of Fulvia, measured in dicks."""
if trigger.group(2):
if trigger.group(2) in bot.users:
d = defer.Deferred()
d.addCallback(idleTime, bot)
bot.memory["idle_callbacks"][trigger.group(2)] = d
bot.whois(trigger.group(2))
else:
delta = datetime.datetime.now() - bot.memory["uptime"]
bot.msg("8" + "="*delta.days + "D")
def idleTime(result, bot):
"""
result - tuple containing (nick, idle, signon)
"""
nick, idle, signon = result
t = datetime.datetime.fromtimestamp(int(signon))
delta = datetime.datetime.now() - t
2018-05-25 15:21:18 -04:00
bot.msg("8" + "="*delta.days + "D")