summaryrefslogtreecommitdiffstats
path: root/modules/search.py
diff options
context:
space:
mode:
Diffstat (limited to 'modules/search.py')
-rwxr-xr-xmodules/search.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/modules/search.py b/modules/search.py
index 2751bb5..c8f9a6a 100755
--- a/modules/search.py
+++ b/modules/search.py
@@ -129,5 +129,24 @@ def bing(phenny, input):
bing.commands = ['bing']
bing.example = '.bing swhack'
+r_ddg = re.compile(r'nofollow" class="[^"]+" href="(.*?)">')
+
+def ddg(phenny, input):
+ query = input.group(2)
+ if not query: return phenny.reply('.ddg what?')
+
+ query = web.urllib.quote(query.encode('utf-8'))
+ uri = 'http://duckduckgo.com/html/?q=%s&kl=uk-en' % query
+ bytes = web.get(uri)
+ m = r_ddg.search(bytes)
+ if m:
+ uri = m.group(1)
+ phenny.reply(uri)
+ if not hasattr(phenny.bot, 'last_seen_uri'):
+ phenny.bot.last_seen_uri = {}
+ phenny.bot.last_seen_uri[input.sender] = uri
+ else: phenny.reply("No results found for '%s'." % query)
+ddg.commands = ['ddg']
+
if __name__ == '__main__':
print __doc__.strip()