diff options
| author | 2018-12-15 22:53:27 +0000 | |
|---|---|---|
| committer | 2018-12-15 22:53:27 +0000 | |
| commit | 9658d0285e56a0879b7fe639c1f8bcf2f983fef9 (patch) | |
| tree | 8515090a5d867b0500b0a37b78737c7f1704f94c /modules/google.py | |
| parent | If a request to git.io times out, fall back to full url (diff) | |
| signature | ||
Support turning safe search on/off in google.py
Diffstat (limited to 'modules/google.py')
| -rw-r--r-- | modules/google.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/modules/google.py b/modules/google.py index dc6e8700..0e486f5f 100644 --- a/modules/google.py +++ b/modules/google.py @@ -7,6 +7,9 @@ from src import ModuleManager, utils URL_GOOGLESEARCH = "https://www.googleapis.com/customsearch/v1" URL_GOOGLESUGGEST = "http://google.com/complete/search" +@utils.export("channelset", {"setting": "google-safesearch", + "help": "Turn safe search off/on", + "validate": utils.bool_or_none}) class Module(ModuleManager.BaseModule): @utils.hook("received.command.g", alias_of="google") @utils.hook("received.command.google") @@ -15,13 +18,18 @@ class Module(ModuleManager.BaseModule): :help: Get first Google result for a given search term :usage: [search term] """ + phrase = event["args"] or event["target"].buffer.get() if phrase: + safe_setting = event["channel"].get_setting("google-safesearch", + True) + safe = "active" if safe_setting else "off" + page = utils.http.request(URL_GOOGLESEARCH, get_params={ "q": phrase, "key": self.bot.config[ "google-api-key"], "cx": self.bot.config[ "google-search-id"], "prettyPrint": "true", - "num": 1, "gl": "gb"}, json=True) + "num": 1, "gl": "gb", "safe": safe}, json=True) if page: if "items" in page.data and len(page.data["items"]): event["stdout"].write( |
