utilise @utils.export for function exporting in more places
This commit is contained in:
parent
70db97f64e
commit
3453479235
8 changed files with 11 additions and 23 deletions
|
@ -7,8 +7,7 @@ RE_HUMAN_FORMAT = re.compile(r"(\d\d\d\d)-(\d?\d)-(\d?\d)")
|
||||||
HUMAN_FORMAT_HELP = "year-month-day (e.g. 2018-12-29)"
|
HUMAN_FORMAT_HELP = "year-month-day (e.g. 2018-12-29)"
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
def on_load(self):
|
@utils.export("command-spec.marginstring")
|
||||||
self.exports.add("command-spec.marginstring", self._marginstring_spec)
|
|
||||||
def _marginstring_spec(self, server, channel, user, args):
|
def _marginstring_spec(self, server, channel, user, args):
|
||||||
if len(args) > 1:
|
if len(args) > 1:
|
||||||
new_args = args[:-1]
|
new_args = args[:-1]
|
||||||
|
|
|
@ -11,8 +11,8 @@ class Module(ModuleManager.BaseModule):
|
||||||
setting = utils.FunctionSetting(self._get_location, "location",
|
setting = utils.FunctionSetting(self._get_location, "location",
|
||||||
"Set your location", example="London, GB")
|
"Set your location", example="London, GB")
|
||||||
self.exports.add("set", setting)
|
self.exports.add("set", setting)
|
||||||
self.exports.add("get-location", self._get_location)
|
|
||||||
|
|
||||||
|
@utils.export("get-location")
|
||||||
def _get_location(self, s):
|
def _get_location(self, s):
|
||||||
page = utils.http.request(URL_OPENCAGE, get_params={"limit": "1",
|
page = utils.http.request(URL_OPENCAGE, get_params={"limit": "1",
|
||||||
"q": s, "key": self.bot.config["opencagedata-api-key"]}).json()
|
"q": s, "key": self.bot.config["opencagedata-api-key"]}).json()
|
||||||
|
|
|
@ -171,8 +171,6 @@ class Module(ModuleManager.BaseModule):
|
||||||
global _log
|
global _log
|
||||||
_log = self.log
|
_log = self.log
|
||||||
|
|
||||||
self.exports.add("url-for", self._url_for)
|
|
||||||
|
|
||||||
self.httpd = None
|
self.httpd = None
|
||||||
if self.bot.get_setting("rest-api", False):
|
if self.bot.get_setting("rest-api", False):
|
||||||
self._start_httpd()
|
self._start_httpd()
|
||||||
|
@ -246,6 +244,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
else:
|
else:
|
||||||
event["stderr"].write("Count not find API key '%s'" % alias)
|
event["stderr"].write("Count not find API key '%s'" % alias)
|
||||||
|
|
||||||
|
@utils.export("url-for")
|
||||||
def _url_for(self, route, endpoint, args=[], get_params={},
|
def _url_for(self, route, endpoint, args=[], get_params={},
|
||||||
host_override=None):
|
host_override=None):
|
||||||
host = host_override or self.bot.get_setting("rest-api-host", None)
|
host = host_override or self.bot.get_setting("rest-api-host", None)
|
||||||
|
|
|
@ -8,11 +8,6 @@ URL_BITLYSHORTEN = "https://api-ssl.bitly.com/v3/shorten"
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
def on_load(self):
|
def on_load(self):
|
||||||
self.exports.add("shorturl", self._shorturl)
|
|
||||||
self.exports.add("shorturl-any", self._shorturl_any)
|
|
||||||
|
|
||||||
self.exports.add("shorturl-s-bitly", self._bitly)
|
|
||||||
|
|
||||||
setting = utils.OptionsSetting([], "url-shortener",
|
setting = utils.OptionsSetting([], "url-shortener",
|
||||||
"Set URL shortener service",
|
"Set URL shortener service",
|
||||||
options_factory=self._shorturl_options_factory)
|
options_factory=self._shorturl_options_factory)
|
||||||
|
@ -35,9 +30,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
return None
|
return None
|
||||||
return short_url
|
return short_url
|
||||||
|
|
||||||
|
@utils.export("shorturl-any")
|
||||||
def _shorturl_any(self, url):
|
def _shorturl_any(self, url):
|
||||||
return self._call_shortener("bitly", url) or url
|
return self._call_shortener("bitly", url) or url
|
||||||
|
|
||||||
|
@utils.export("shorturl")
|
||||||
def _shorturl(self, server, url, context=None):
|
def _shorturl(self, server, url, context=None):
|
||||||
shortener_name = None
|
shortener_name = None
|
||||||
if context:
|
if context:
|
||||||
|
@ -50,6 +47,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
return url
|
return url
|
||||||
return self._call_shortener(shortener_name, url) or url
|
return self._call_shortener(shortener_name, url) or url
|
||||||
|
|
||||||
|
@utils.export("shorturl-s-bitly")
|
||||||
def _bitly(self, url):
|
def _bitly(self, url):
|
||||||
if len(url) < 22:
|
if len(url) < 22:
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -15,9 +15,6 @@ class LocationType(enum.Enum):
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
_name = "Time"
|
_name = "Time"
|
||||||
|
|
||||||
def on_load(self):
|
|
||||||
self.exports.add("time-localise", self.time_localise)
|
|
||||||
|
|
||||||
def _find_setting(self, event):
|
def _find_setting(self, event):
|
||||||
query = None
|
query = None
|
||||||
target_user = None
|
target_user = None
|
||||||
|
@ -80,6 +77,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
|
|
||||||
event["stderr"].write(out % name)
|
event["stderr"].write(out % name)
|
||||||
|
|
||||||
|
@utils.export("time-localise")
|
||||||
def time_localise(self, user, dt):
|
def time_localise(self, user, dt):
|
||||||
location = user.get_setting("location", None)
|
location = user.get_setting("location", None)
|
||||||
timezone = "UTC"
|
timezone = "UTC"
|
||||||
|
|
|
@ -24,9 +24,6 @@ ARROW_DOWN = "↓"
|
||||||
@utils.export("channelset", utils.BoolSetting("youtube-safesearch",
|
@utils.export("channelset", utils.BoolSetting("youtube-safesearch",
|
||||||
"Turn safe search off/on"))
|
"Turn safe search off/on"))
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
def on_load(self):
|
|
||||||
self.exports.add("search-youtube", self._search_youtube)
|
|
||||||
|
|
||||||
def get_video_page(self, video_id):
|
def get_video_page(self, video_id):
|
||||||
return utils.http.request(URL_YOUTUBEVIDEO, get_params={
|
return utils.http.request(URL_YOUTUBEVIDEO, get_params={
|
||||||
"part": "contentDetails,snippet,statistics",
|
"part": "contentDetails,snippet,statistics",
|
||||||
|
@ -115,6 +112,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
elif parsed.path == "/playlist" and "list" in query:
|
elif parsed.path == "/playlist" and "list" in query:
|
||||||
return self.playlist_details(query["list"][0])
|
return self.playlist_details(query["list"][0])
|
||||||
|
|
||||||
|
@utils.export("search-youtube")
|
||||||
def _search_youtube(self, query):
|
def _search_youtube(self, query):
|
||||||
video_id = ""
|
video_id = ""
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,10 @@ import datetime
|
||||||
from src import EventManager, ModuleManager, utils
|
from src import EventManager, ModuleManager, utils
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
def on_load(self):
|
|
||||||
self.exports.add("format", self._event)
|
|
||||||
|
|
||||||
def _color(self, nickname):
|
def _color(self, nickname):
|
||||||
return utils.irc.hash_colorize(nickname)
|
return utils.irc.hash_colorize(nickname)
|
||||||
|
|
||||||
|
@utils.export("format")
|
||||||
def _event(self, type, server, line, context, minimal=None, channel=None,
|
def _event(self, type, server, line, context, minimal=None, channel=None,
|
||||||
user=None, formatting={}, **kwargs):
|
user=None, formatting={}, **kwargs):
|
||||||
pretty = line
|
pretty = line
|
||||||
|
|
|
@ -9,10 +9,6 @@ NO_PERMISSION = "You do not have permission to do that"
|
||||||
ACCOUNT_TAG = utils.irc.MessageTag("account")
|
ACCOUNT_TAG = utils.irc.MessageTag("account")
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
def on_load(self):
|
|
||||||
self.exports.add("is-identified", self._is_identified)
|
|
||||||
self.exports.add("account-name", self._account_name)
|
|
||||||
|
|
||||||
@utils.hook("new.server")
|
@utils.hook("new.server")
|
||||||
def new_server(self, event):
|
def new_server(self, event):
|
||||||
event["server"]._hostmasks = {}
|
event["server"]._hostmasks = {}
|
||||||
|
@ -59,6 +55,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
user._id_override = server.get_user_id(account)
|
user._id_override = server.get_user_id(account)
|
||||||
self.events.on("internal.identified").call(server=server, user=user,
|
self.events.on("internal.identified").call(server=server, user=user,
|
||||||
accunt=account)
|
accunt=account)
|
||||||
|
@utils.export("is-identified")
|
||||||
def _is_identified(self, user):
|
def _is_identified(self, user):
|
||||||
return not user._id_override == None
|
return not user._id_override == None
|
||||||
def _signout(self, user):
|
def _signout(self, user):
|
||||||
|
@ -79,6 +76,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
user._hostmask_account = (hostmask, account)
|
user._hostmask_account = (hostmask, account)
|
||||||
self._has_identified(server, user, account)
|
self._has_identified(server, user, account)
|
||||||
|
|
||||||
|
@utils.export("account-name")
|
||||||
def _account_name(self, user):
|
def _account_name(self, user):
|
||||||
if not user.account == None:
|
if not user.account == None:
|
||||||
return user.account
|
return user.account
|
||||||
|
|
Loading…
Reference in a new issue