2019-05-25 20:40:06 +00:00
|
|
|
#--depends-on commands
|
|
|
|
#--depends-on location
|
|
|
|
|
2019-04-28 11:12:00 +00:00
|
|
|
import datetime
|
2019-09-05 11:25:17 +00:00
|
|
|
import pytz
|
2019-04-28 11:12:00 +00:00
|
|
|
from src import ModuleManager, utils
|
|
|
|
|
2019-07-27 20:09:45 +00:00
|
|
|
NOLOCATION = "%s doesn't have a location set"
|
2019-04-28 11:12:00 +00:00
|
|
|
|
|
|
|
class Module(ModuleManager.BaseModule):
|
|
|
|
_name = "Time"
|
|
|
|
|
2019-07-27 20:09:45 +00:00
|
|
|
def _find_setting(self, event):
|
2019-04-28 11:12:00 +00:00
|
|
|
target_user = event["user"]
|
2019-07-27 20:09:45 +00:00
|
|
|
|
2019-04-28 11:12:00 +00:00
|
|
|
if event["args"]:
|
|
|
|
target_user = event["server"].get_user(event["args_split"][0])
|
|
|
|
|
2019-07-27 20:09:45 +00:00
|
|
|
return target_user, target_user.get_setting("location", None)
|
2019-04-28 11:12:00 +00:00
|
|
|
|
2019-07-27 20:09:45 +00:00
|
|
|
@utils.hook("received.command.time")
|
|
|
|
@utils.kwarg("help", "Get the time for you or someone else")
|
|
|
|
@utils.kwarg("usage", "[nickname]")
|
|
|
|
@utils.kwarg("require_setting", "location")
|
|
|
|
@utils.kwarg("require_setting_unless", "1")
|
|
|
|
def time(self, event):
|
|
|
|
target_user, location = self._find_setting(event)
|
2019-04-28 11:12:00 +00:00
|
|
|
if not location == None:
|
2019-09-05 11:25:17 +00:00
|
|
|
dt = datetime.datetime.now(tz=pytz.timezone(location["timezone"]))
|
|
|
|
human = utils.datetime_human(dt)
|
|
|
|
event["stdout"].write("Time for %s: %s" % (target_user.nickname,
|
|
|
|
human))
|
2019-04-28 11:12:00 +00:00
|
|
|
else:
|
2019-07-27 20:09:45 +00:00
|
|
|
event["stderr"].write(NOLOCATION % target_user.nickname)
|
|
|
|
|
|
|
|
@utils.hook("received.command.timezone")
|
|
|
|
@utils.kwarg("help", "Get the timezone for you or someone else")
|
|
|
|
@utils.kwarg("usage", "[nickname]")
|
|
|
|
@utils.kwarg("require_setting", "location")
|
|
|
|
@utils.kwarg("require_setting_unless", "1")
|
|
|
|
def timezone(self, event):
|
|
|
|
target_user, location = self._find_setting(event)
|
|
|
|
if not location == None:
|
|
|
|
event["stdout"].write("%s is in %s" % (target_user.nickname,
|
|
|
|
location["timezone"]))
|
|
|
|
else:
|
|
|
|
event["stderr"].write(NOLOCATION % target_user.nickname)
|