2018-03-16 03:13:43 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
"""
|
|
|
|
How long the bot has been running.
|
|
|
|
"""
|
|
|
|
import datetime
|
|
|
|
|
2018-05-29 17:41:47 -04:00
|
|
|
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()
|
2018-05-29 17:41:47 -04:00
|
|
|
bot.memory["idle_callbacks"] = {}
|
2018-03-16 03:13:43 -04:00
|
|
|
|
|
|
|
|
|
|
|
@commands('uptime')
|
|
|
|
def uptime(bot, trigger):
|
2018-03-25 14:27:40 -04:00
|
|
|
""".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!")
|
2018-03-25 14:27:40 -04:00
|
|
|
|
|
|
|
|
|
|
|
@commands('updick')
|
|
|
|
def updick(bot, trigger):
|
|
|
|
""".updick - Returns the uptime of Fulvia, measured in dicks."""
|
2021-11-12 09:41:11 -05:00
|
|
|
if len(trigger.args) > 1:
|
|
|
|
if trigger.args[1] in bot.channels[trigger.channel].users:
|
2018-05-29 17:41:47 -04:00
|
|
|
d = defer.Deferred()
|
|
|
|
d.addCallback(idleTime, bot)
|
2020-01-07 18:58:19 -05:00
|
|
|
bot.memory["idle_callbacks"][trigger.args[1]] = d
|
|
|
|
bot.whois(trigger.args[1])
|
2018-05-29 17:41:47 -04:00
|
|
|
else:
|
|
|
|
delta = datetime.datetime.now() - bot.memory["uptime"]
|
|
|
|
bot.msg("8" + "="*delta.days + "D")
|
|
|
|
|
|
|
|
|
2019-03-21 07:55:05 -04:00
|
|
|
@commands('upwulf')
|
2019-09-06 12:43:39 -04:00
|
|
|
def upwulf(bot, trigger):
|
2019-03-21 07:55:05 -04:00
|
|
|
""".upwulf - Returns the uptime of Fulvia, measured in Adalwulfs."""
|
2021-11-12 09:41:11 -05:00
|
|
|
if len(trigger.args) > 1:
|
|
|
|
if trigger.args[1] in bot.channels[trigger.channel].users:
|
2019-03-21 07:55:05 -04:00
|
|
|
d = defer.Deferred()
|
2021-11-12 09:41:11 -05:00
|
|
|
d.addCallback(idleTimeWulf, bot)
|
2020-01-07 18:58:19 -05:00
|
|
|
bot.memory["idle_callbacks"][trigger.args[1]] = d
|
|
|
|
bot.whois(trigger.args[1])
|
2019-03-21 07:55:05 -04:00
|
|
|
else:
|
|
|
|
delta = datetime.datetime.now() - bot.memory["uptime"]
|
|
|
|
bot.msg("Adalwulf" + "_"*delta.days)
|
|
|
|
|
|
|
|
|
2018-05-29 17:41:47 -04:00
|
|
|
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")
|
2019-03-21 07:55:05 -04:00
|
|
|
|
|
|
|
|
|
|
|
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)
|
2019-11-02 17:40:25 -04:00
|
|
|
|
|
|
|
|
|
|
|
@commands('unix')
|
|
|
|
def unixtolocal(bot, trigger):
|
|
|
|
"""Converts the given timestamp from unix time to local time."""
|
2020-01-07 18:58:19 -05:00
|
|
|
if len(trigger.args) < 2:
|
|
|
|
return bot.reply("Unix what?")
|
|
|
|
unix = int(trigger.args[1])
|
2019-11-02 18:22:06 -04:00
|
|
|
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'))
|