Don't use the event system to get results from other modules - use exports

This commit is contained in:
jesopo 2019-02-09 13:14:45 +00:00
parent 4bc43f686e
commit 730a4e6b87
4 changed files with 12 additions and 12 deletions

View file

@ -47,10 +47,7 @@ class Module(ModuleManager.BaseModule):
ytquery = " - ".join([artist, track_name])
short_url = self.events.on(
"get.searchyoutube").call_for_result(
query=ytquery)
short_url = self.exports.get_one("search-youtube")(ytquery)
short_url = " -- " + short_url if short_url else ""
info_page = utils.http.request(URL_SCROBBLER, get_params={

View file

@ -58,8 +58,10 @@ QUOTES = {
}
class Module(ModuleManager.BaseModule):
@utils.hook("get.quit-quote")
def quote(self, event):
def on_load(self):
self.exports.add("quit-quote", self._quote)
def _quote(self):
quote = random.choice(list(QUOTES.items()))
return (" - " if quote[1] else "").join(quote)

View file

@ -24,8 +24,8 @@ class Module(ModuleManager.BaseModule):
for server in self.bot.servers.values():
reason = "Leaving"
if server.get_setting("quit-quote", True):
reason = self.events.on("get.quit-quote"
).call_for_result(default=reason)
reason = self.exports.get_one("quit-quote",
lambda: reason)()
server.send_quit(reason)
self.events.on("writebuffer.empty").hook(

View file

@ -23,6 +23,9 @@ ARROW_DOWN = "↓"
"help": "Turn safe search off/on",
"validate": utils.bool_or_none})
class Module(ModuleManager.BaseModule):
def on_load(self):
self.exports.add("search-youtube", self._search_youtube)
def get_video_page(self, video_id, part):
return utils.http.request(URL_YOUTUBEVIDEO, get_params={"part": part,
"id": video_id, "key": self.bot.config["google-api-key"]},
@ -58,13 +61,11 @@ class Module(ModuleManager.BaseModule):
video_title, video_duration, video_uploader, "{:,}".format(
int(video_views)), video_opinions, URL_YOUTUBESHORT % video_id)
@utils.hook("get.searchyoutube")
def search_video(self, event):
search = event["query"]
def _search_youtube(self, query):
video_id = ""
search_page = utils.http.request(URL_YOUTUBESEARCH,
get_params={"q": search, "part": "snippet",
get_params={"q": query, "part": "snippet",
"maxResults": "1", "type": "video",
"key": self.bot.config["google-api-key"]},
json=True)