exports.get_one() -> exports.get()
This commit is contained in:
parent
69be51e502
commit
49d9cbdb87
17 changed files with 20 additions and 20 deletions
|
@ -95,7 +95,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
note = note["object"]
|
note = note["object"]
|
||||||
|
|
||||||
cw, author, content, url = ap_utils.parse_note(actor, note, type)
|
cw, author, content, url = ap_utils.parse_note(actor, note, type)
|
||||||
shorturl = self.exports.get_one("shorturl")(event["server"], url,
|
shorturl = self.exports.get("shorturl")(event["server"], url,
|
||||||
context=event["target"])
|
context=event["target"])
|
||||||
|
|
||||||
if cw:
|
if cw:
|
||||||
|
|
|
@ -12,7 +12,7 @@ class Server(object):
|
||||||
self.username = username
|
self.username = username
|
||||||
self.instance = instance
|
self.instance = instance
|
||||||
|
|
||||||
url_for = self.exports.get_one("url-for")
|
url_for = self.exports.get("url-for")
|
||||||
|
|
||||||
key_id = self._ap_keyid_url(url_for)
|
key_id = self._ap_keyid_url(url_for)
|
||||||
private_key = ap_security.PrivateKey(self.bot.config["tls-key"], key_id)
|
private_key = ap_security.PrivateKey(self.bot.config["tls-key"], key_id)
|
||||||
|
@ -61,7 +61,7 @@ class Server(object):
|
||||||
def _toot(self, activity_id):
|
def _toot(self, activity_id):
|
||||||
content, timestamp = self.bot.get_setting(
|
content, timestamp = self.bot.get_setting(
|
||||||
"ap-activity-%s" % activity_id)
|
"ap-activity-%s" % activity_id)
|
||||||
url_for = self.exports.get_one("url-for")
|
url_for = self.exports.get("url-for")
|
||||||
self_id = self._ap_self_url(url_for)
|
self_id = self._ap_self_url(url_for)
|
||||||
activity_url = self._ap_activity_url(url_for, activity_id)
|
activity_url = self._ap_activity_url(url_for, activity_id)
|
||||||
|
|
||||||
|
|
|
@ -138,7 +138,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
|
|
||||||
if url:
|
if url:
|
||||||
if channel.get_setting("git-shorten-urls", False):
|
if channel.get_setting("git-shorten-urls", False):
|
||||||
url = self.exports.get_one("shorturl")(server, url,
|
url = self.exports.get("shorturl")(server, url,
|
||||||
context=channel) or url
|
context=channel) or url
|
||||||
output = "%s - %s" % (output, url)
|
output = "%s - %s" % (output, url)
|
||||||
|
|
||||||
|
|
|
@ -441,7 +441,7 @@ class GitHub(object):
|
||||||
url = ""
|
url = ""
|
||||||
if data["check_run"]["details_url"]:
|
if data["check_run"]["details_url"]:
|
||||||
url = data["check_run"]["details_url"]
|
url = data["check_run"]["details_url"]
|
||||||
url = " - %s" % self.exports.get_one("shorturl-any")(url)
|
url = " - %s" % self.exports.get("shorturl-any")(url)
|
||||||
|
|
||||||
duration = ""
|
duration = ""
|
||||||
if data["check_run"]["completed_at"]:
|
if data["check_run"]["completed_at"]:
|
||||||
|
|
|
@ -16,7 +16,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
@utils.kwarg("help", "Show what I think your account name is")
|
@utils.kwarg("help", "Show what I think your account name is")
|
||||||
def account(self, event):
|
def account(self, event):
|
||||||
event["stdout"].write("%s: %s" % (event["user"].nickname,
|
event["stdout"].write("%s: %s" % (event["user"].nickname,
|
||||||
self.exports.get_one("account-name")(event["user"])))
|
self.exports.get("account-name")(event["user"])))
|
||||||
|
|
||||||
@utils.hook("received.command.channelid", channel_only=True)
|
@utils.hook("received.command.channelid", channel_only=True)
|
||||||
def channel_id(self, event):
|
def channel_id(self, event):
|
||||||
|
|
|
@ -18,7 +18,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
timestamp, line.message)
|
timestamp, line.message)
|
||||||
line = "- %s" % minimal
|
line = "- %s" % minimal
|
||||||
|
|
||||||
self.exports.get_one("format")("delete", event["server"], line,
|
self.exports.get("format")("delete", event["server"], line,
|
||||||
event["target_str"], minimal=minimal, channel=channel,
|
event["target_str"], minimal=minimal, channel=channel,
|
||||||
user=event["user"])
|
user=event["user"])
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
|
|
||||||
time_language = "is listening to" if np else "last listened to"
|
time_language = "is listening to" if np else "last listened to"
|
||||||
|
|
||||||
yt_url = self.exports.get_one("search-youtube")(
|
yt_url = self.exports.get("search-youtube")(
|
||||||
"%s - %s" % (artist, track_name))
|
"%s - %s" % (artist, track_name))
|
||||||
yt_url_str = ""
|
yt_url_str = ""
|
||||||
if yt_url:
|
if yt_url:
|
||||||
|
|
|
@ -27,7 +27,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
link = entry.get("link", None)
|
link = entry.get("link", None)
|
||||||
if shorten:
|
if shorten:
|
||||||
try:
|
try:
|
||||||
link = self.exports.get_one("shorturl")(server, link)
|
link = self.exports.get("shorturl")(server, link)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
link = " - %s" % link if link else ""
|
link = " - %s" % link if link else ""
|
||||||
|
|
|
@ -20,7 +20,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
return [s.replace("shorturl-s-", "", 1) for s in shorteners]
|
return [s.replace("shorturl-s-", "", 1) for s in shorteners]
|
||||||
|
|
||||||
def _get_shortener(self, name):
|
def _get_shortener(self, name):
|
||||||
return self.exports.get_one("shorturl-s-%s" % name, None)
|
return self.exports.get("shorturl-s-%s" % name, None)
|
||||||
def _call_shortener(self, shortener_name, url):
|
def _call_shortener(self, shortener_name, url):
|
||||||
shortener = self._get_shortener(shortener_name)
|
shortener = self._get_shortener(shortener_name)
|
||||||
if shortener == None:
|
if shortener == None:
|
||||||
|
|
|
@ -71,7 +71,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
return -2, title
|
return -2, title
|
||||||
|
|
||||||
if channel.get_setting("title-shorten", False):
|
if channel.get_setting("title-shorten", False):
|
||||||
short_url = self.exports.get_one("shorturl")(server, url,
|
short_url = self.exports.get("shorturl")(server, url,
|
||||||
context=channel)
|
context=channel)
|
||||||
return page.code, "%s - %s" % (title, short_url)
|
return page.code, "%s - %s" % (title, short_url)
|
||||||
return page.code, title
|
return page.code, title
|
||||||
|
|
|
@ -23,7 +23,7 @@ def _tweet(exports, server, tweet, from_url):
|
||||||
|
|
||||||
short_url = ""
|
short_url = ""
|
||||||
if not from_url:
|
if not from_url:
|
||||||
short_url = exports.get_one("shorturl")(server, tweet_link)
|
short_url = exports.get("shorturl")(server, tweet_link)
|
||||||
short_url = " - %s" % short_url if short_url else ""
|
short_url = " - %s" % short_url if short_url else ""
|
||||||
created_at = _timestamp(tweet.created_at)
|
created_at = _timestamp(tweet.created_at)
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
location["timezone"])
|
location["timezone"])
|
||||||
|
|
||||||
if query:
|
if query:
|
||||||
location = self.exports.get_one("get-location")(query)
|
location = self.exports.get("get-location")(query)
|
||||||
if location:
|
if location:
|
||||||
return (LocationType.NAME, location["name"],
|
return (LocationType.NAME, location["name"],
|
||||||
location["timezone"])
|
location["timezone"])
|
||||||
|
|
|
@ -45,7 +45,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
|
|
||||||
|
|
||||||
if location == None and query:
|
if location == None and query:
|
||||||
location_info = self.exports.get_one("get-location")(query)
|
location_info = self.exports.get("get-location")(query)
|
||||||
if not location_info == None:
|
if not location_info == None:
|
||||||
location = [location_info["lat"], location_info["lon"],
|
location = [location_info["lat"], location_info["lon"],
|
||||||
location_info.get("name", None)]
|
location_info.get("name", None)]
|
||||||
|
|
|
@ -66,7 +66,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
|
|
||||||
if event["channel"].get_setting("word-tracking-registered",
|
if event["channel"].get_setting("word-tracking-registered",
|
||||||
event["server"].get_setting("word-tracking-registered", False)):
|
event["server"].get_setting("word-tracking-registered", False)):
|
||||||
if not self.exports.get_one("is-identified")(event["user"]):
|
if not self.exports.get("is-identified")(event["user"]):
|
||||||
return
|
return
|
||||||
|
|
||||||
if user.get_setting("first-words", None) == None:
|
if user.get_setting("first-words", None) == None:
|
||||||
|
|
|
@ -35,7 +35,7 @@ class Exports(object):
|
||||||
return self._exports.get(setting, []) + sum([
|
return self._exports.get(setting, []) + sum([
|
||||||
exports.get(setting, []) for exports in
|
exports.get(setting, []) for exports in
|
||||||
self._context_exports.values()], [])
|
self._context_exports.values()], [])
|
||||||
def get_one(self, setting: str, default: typing.Any=None
|
def get(self, setting: str, default: typing.Any=None
|
||||||
) -> typing.Optional[typing.Any]:
|
) -> typing.Optional[typing.Any]:
|
||||||
values = self.get_all(setting)
|
values = self.get_all(setting)
|
||||||
return values[0] if values else default
|
return values[0] if values else default
|
||||||
|
@ -60,8 +60,8 @@ class ExportsContext(object):
|
||||||
self._parent._context_add(self.context, setting, value)
|
self._parent._context_add(self.context, setting, value)
|
||||||
def get_all(self, setting: str) -> typing.List[typing.Any]:
|
def get_all(self, setting: str) -> typing.List[typing.Any]:
|
||||||
return self._parent.get_all(setting)
|
return self._parent.get_all(setting)
|
||||||
def get_one(self, setting: str, default: typing.Any=None
|
def get(self, setting: str, default: typing.Any=None
|
||||||
) -> typing.Optional[typing.Any]:
|
) -> typing.Optional[typing.Any]:
|
||||||
return self._parent.get_one(setting, default)
|
return self._parent.get(setting, default)
|
||||||
def find(self, setting_prefix: str) -> typing.List[typing.Any]:
|
def find(self, setting_prefix: str) -> typing.List[typing.Any]:
|
||||||
return self._parent.find(setting_prefix)
|
return self._parent.find(setting_prefix)
|
||||||
|
|
|
@ -21,7 +21,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
|
|
||||||
|
|
||||||
user_access = target.get_user_setting(user.get_id(), "access", [])
|
user_access = target.get_user_setting(user.get_id(), "access", [])
|
||||||
identified = self.exports.get_one("is-identified")(user)
|
identified = self.exports.get("is-identified")(user)
|
||||||
matched = list(set(required_access)&set(user_access))
|
matched = list(set(required_access)&set(user_access))
|
||||||
|
|
||||||
return ("*" in user_access or matched) and identified
|
return ("*" in user_access or matched) and identified
|
||||||
|
|
|
@ -48,7 +48,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
if argument_type.type in types.TYPES:
|
if argument_type.type in types.TYPES:
|
||||||
func = types.TYPES[argument_type.type]
|
func = types.TYPES[argument_type.type]
|
||||||
else:
|
else:
|
||||||
func = self.exports.get_one(
|
func = self.exports.get(
|
||||||
"command-spec.%s" % argument_type.type)
|
"command-spec.%s" % argument_type.type)
|
||||||
|
|
||||||
if func:
|
if func:
|
||||||
|
|
Loading…
Reference in a new issue