add !timezone
This commit is contained in:
parent
944f32befb
commit
047a21629f
1 changed files with 25 additions and 11 deletions
|
@ -5,24 +5,26 @@ import datetime
|
||||||
from src import ModuleManager, utils
|
from src import ModuleManager, utils
|
||||||
|
|
||||||
API = "http://worldtimeapi.org/api/timezone/%s"
|
API = "http://worldtimeapi.org/api/timezone/%s"
|
||||||
|
NOLOCATION = "%s doesn't have a location set"
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
_name = "Time"
|
_name = "Time"
|
||||||
|
|
||||||
@utils.hook("received.command.time")
|
def _find_setting(self, event):
|
||||||
def time(self, event):
|
|
||||||
"""
|
|
||||||
:help: Get the time for you or someone else
|
|
||||||
:usage: [nickname]
|
|
||||||
:require_setting: location
|
|
||||||
:require_setting_unless: 1
|
|
||||||
"""
|
|
||||||
target_user = event["user"]
|
target_user = event["user"]
|
||||||
|
|
||||||
if event["args"]:
|
if event["args"]:
|
||||||
target_user = event["server"].get_user(event["args_split"][0])
|
target_user = event["server"].get_user(event["args_split"][0])
|
||||||
|
|
||||||
location = target_user.get_setting("location", None)
|
return target_user, target_user.get_setting("location", None)
|
||||||
|
|
||||||
|
@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)
|
||||||
if not location == None:
|
if not location == None:
|
||||||
page = utils.http.request(API % location["timezone"], json=True)
|
page = utils.http.request(API % location["timezone"], json=True)
|
||||||
|
|
||||||
|
@ -35,5 +37,17 @@ class Module(ModuleManager.BaseModule):
|
||||||
else:
|
else:
|
||||||
raise utils.EventsResultsError()
|
raise utils.EventsResultsError()
|
||||||
else:
|
else:
|
||||||
event["stderr"].write("%s doesn't have a location set" %
|
event["stderr"].write(NOLOCATION % target_user.nickname)
|
||||||
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)
|
||||||
|
|
Loading…
Reference in a new issue