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"]
|
||||
|
||||
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"])
|
||||
|
||||
if cw:
|
||||
|
|
|
@ -12,7 +12,7 @@ class Server(object):
|
|||
self.username = username
|
||||
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)
|
||||
private_key = ap_security.PrivateKey(self.bot.config["tls-key"], key_id)
|
||||
|
@ -61,7 +61,7 @@ class Server(object):
|
|||
def _toot(self, activity_id):
|
||||
content, timestamp = self.bot.get_setting(
|
||||
"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)
|
||||
activity_url = self._ap_activity_url(url_for, activity_id)
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@ class Module(ModuleManager.BaseModule):
|
|||
|
||||
if url:
|
||||
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
|
||||
output = "%s - %s" % (output, url)
|
||||
|
||||
|
|
|
@ -441,7 +441,7 @@ class GitHub(object):
|
|||
url = ""
|
||||
if 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 = ""
|
||||
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")
|
||||
def account(self, event):
|
||||
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)
|
||||
def channel_id(self, event):
|
||||
|
|
|
@ -18,7 +18,7 @@ class Module(ModuleManager.BaseModule):
|
|||
timestamp, line.message)
|
||||
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,
|
||||
user=event["user"])
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ class Module(ModuleManager.BaseModule):
|
|||
|
||||
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))
|
||||
yt_url_str = ""
|
||||
if yt_url:
|
||||
|
|
|
@ -27,7 +27,7 @@ class Module(ModuleManager.BaseModule):
|
|||
link = entry.get("link", None)
|
||||
if shorten:
|
||||
try:
|
||||
link = self.exports.get_one("shorturl")(server, link)
|
||||
link = self.exports.get("shorturl")(server, link)
|
||||
except:
|
||||
pass
|
||||
link = " - %s" % link if link else ""
|
||||
|
|
|
@ -20,7 +20,7 @@ class Module(ModuleManager.BaseModule):
|
|||
return [s.replace("shorturl-s-", "", 1) for s in shorteners]
|
||||
|
||||
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):
|
||||
shortener = self._get_shortener(shortener_name)
|
||||
if shortener == None:
|
||||
|
|
|
@ -71,7 +71,7 @@ class Module(ModuleManager.BaseModule):
|
|||
return -2, title
|
||||
|
||||
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)
|
||||
return page.code, "%s - %s" % (title, short_url)
|
||||
return page.code, title
|
||||
|
|
|
@ -23,7 +23,7 @@ def _tweet(exports, server, tweet, from_url):
|
|||
|
||||
short_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 ""
|
||||
created_at = _timestamp(tweet.created_at)
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ class Module(ModuleManager.BaseModule):
|
|||
location["timezone"])
|
||||
|
||||
if query:
|
||||
location = self.exports.get_one("get-location")(query)
|
||||
location = self.exports.get("get-location")(query)
|
||||
if location:
|
||||
return (LocationType.NAME, location["name"],
|
||||
location["timezone"])
|
||||
|
|
|
@ -45,7 +45,7 @@ class Module(ModuleManager.BaseModule):
|
|||
|
||||
|
||||
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:
|
||||
location = [location_info["lat"], location_info["lon"],
|
||||
location_info.get("name", None)]
|
||||
|
|
|
@ -66,7 +66,7 @@ class Module(ModuleManager.BaseModule):
|
|||
|
||||
if event["channel"].get_setting("word-tracking-registered",
|
||||
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
|
||||
|
||||
if user.get_setting("first-words", None) == None:
|
||||
|
|
|
@ -35,7 +35,7 @@ class Exports(object):
|
|||
return self._exports.get(setting, []) + sum([
|
||||
exports.get(setting, []) for exports in
|
||||
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]:
|
||||
values = self.get_all(setting)
|
||||
return values[0] if values else default
|
||||
|
@ -60,8 +60,8 @@ class ExportsContext(object):
|
|||
self._parent._context_add(self.context, setting, value)
|
||||
def get_all(self, setting: str) -> typing.List[typing.Any]:
|
||||
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]:
|
||||
return self._parent.get_one(setting, default)
|
||||
return self._parent.get(setting, default)
|
||||
def find(self, setting_prefix: str) -> typing.List[typing.Any]:
|
||||
return self._parent.find(setting_prefix)
|
||||
|
|
|
@ -21,7 +21,7 @@ class Module(ModuleManager.BaseModule):
|
|||
|
||||
|
||||
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))
|
||||
|
||||
return ("*" in user_access or matched) and identified
|
||||
|
|
|
@ -48,7 +48,7 @@ class Module(ModuleManager.BaseModule):
|
|||
if argument_type.type in types.TYPES:
|
||||
func = types.TYPES[argument_type.type]
|
||||
else:
|
||||
func = self.exports.get_one(
|
||||
func = self.exports.get(
|
||||
"command-spec.%s" % argument_type.type)
|
||||
|
||||
if func:
|
||||
|
|
Loading…
Reference in a new issue