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]) ytquery = " - ".join([artist, track_name])
short_url = self.events.on( short_url = self.exports.get_one("search-youtube")(ytquery)
"get.searchyoutube").call_for_result(
query=ytquery)
short_url = " -- " + short_url if short_url else "" short_url = " -- " + short_url if short_url else ""
info_page = utils.http.request(URL_SCROBBLER, get_params={ info_page = utils.http.request(URL_SCROBBLER, get_params={

View file

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

View file

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

View file

@ -23,6 +23,9 @@ ARROW_DOWN = "↓"
"help": "Turn safe search off/on", "help": "Turn safe search off/on",
"validate": utils.bool_or_none}) "validate": utils.bool_or_none})
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, part): def get_video_page(self, video_id, part):
return utils.http.request(URL_YOUTUBEVIDEO, get_params={"part": part, return utils.http.request(URL_YOUTUBEVIDEO, get_params={"part": part,
"id": video_id, "key": self.bot.config["google-api-key"]}, "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( video_title, video_duration, video_uploader, "{:,}".format(
int(video_views)), video_opinions, URL_YOUTUBESHORT % video_id) int(video_views)), video_opinions, URL_YOUTUBESHORT % video_id)
@utils.hook("get.searchyoutube") def _search_youtube(self, query):
def search_video(self, event):
search = event["query"]
video_id = "" video_id = ""
search_page = utils.http.request(URL_YOUTUBESEARCH, search_page = utils.http.request(URL_YOUTUBESEARCH,
get_params={"q": search, "part": "snippet", get_params={"q": query, "part": "snippet",
"maxResults": "1", "type": "video", "maxResults": "1", "type": "video",
"key": self.bot.config["google-api-key"]}, "key": self.bot.config["google-api-key"]},
json=True) json=True)