84 lines
2.2 KiB
Python
Executable File
84 lines
2.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
How long the bot has been running.
|
|
"""
|
|
import datetime
|
|
|
|
from twisted.internet import defer
|
|
|
|
from module import commands
|
|
import tools.time
|
|
|
|
|
|
def setup(bot):
|
|
if "uptime" not in bot.memory:
|
|
bot.memory["uptime"] = datetime.datetime.now()
|
|
bot.memory["idle_callbacks"] = {}
|
|
|
|
|
|
@commands('uptime')
|
|
def uptime(bot, trigger):
|
|
""".uptime - Returns the uptime of Fulvia."""
|
|
delta = datetime.timedelta(seconds=round((datetime.datetime.now() -
|
|
bot.memory["uptime"]).total_seconds()))
|
|
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 len(trigger.args) < 2:
|
|
if trigger.args[1] in bot.users:
|
|
d = defer.Deferred()
|
|
d.addCallback(idleTime, bot)
|
|
bot.memory["idle_callbacks"][trigger.args[1]] = d
|
|
bot.whois(trigger.args[1])
|
|
else:
|
|
delta = datetime.datetime.now() - bot.memory["uptime"]
|
|
bot.msg("8" + "="*delta.days + "D")
|
|
|
|
|
|
@commands('upwulf')
|
|
def upwulf(bot, trigger):
|
|
""".upwulf - Returns the uptime of Fulvia, measured in Adalwulfs."""
|
|
if len(trigger.args) < 2:
|
|
if trigger.args[1] in bot.users:
|
|
d = defer.Deferred()
|
|
d.addCallback(idleTime, bot)
|
|
bot.memory["idle_callbacks"][trigger.args[1]] = d
|
|
bot.whois(trigger.args[1])
|
|
else:
|
|
delta = datetime.datetime.now() - bot.memory["uptime"]
|
|
bot.msg("Adalwulf" + "_"*delta.days)
|
|
|
|
|
|
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
|
|
bot.msg("8" + "="*delta.days + "D")
|
|
|
|
|
|
def idleTimeWulf(result, bot):
|
|
"""
|
|
result - tuple containing (nick, idle, signon)
|
|
"""
|
|
nick, idle, signon = result
|
|
t = datetime.datetime.fromtimestamp(int(signon))
|
|
delta = datetime.datetime.now() - t
|
|
bot.msg("Adalwulf" + "_"*delta.days)
|
|
|
|
|
|
@commands('unix')
|
|
def unixtolocal(bot, trigger):
|
|
"""Converts the given timestamp from unix time to local time."""
|
|
if len(trigger.args) < 2:
|
|
return bot.reply("Unix what?")
|
|
unix = int(trigger.args[1])
|
|
dt = datetime.datetime.utcfromtimestamp(unix)
|
|
dt = dt.replace(tzinfo=datetime.timezone.utc)
|
|
bot.msg(dt.astimezone(tz=None).strftime('%Y-%m-%d %H:%M:%S'))
|