diff options
Diffstat (limited to 'wmd')
| -rw-r--r-- | wmd/actions/google.py | 27 | ||||
| -rw-r--r-- | wmd/actions/modules.py | 2 |
2 files changed, 28 insertions, 1 deletions
diff --git a/wmd/actions/google.py b/wmd/actions/google.py new file mode 100644 index 0000000..39c2269 --- /dev/null +++ b/wmd/actions/google.py | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | __author__ = 'jason@zzq.org' | ||
| 2 | __version__ = 1.0 | ||
| 3 | |||
| 4 | import urllib2 | ||
| 5 | import simplejson | ||
| 6 | |||
| 7 | from wmd.actions import Action | ||
| 8 | |||
| 9 | import settings | ||
| 10 | |||
| 11 | class GoogleSearch(Action): | ||
| 12 | def recv_msg(self, irc, obj_data): | ||
| 13 | args = obj_data.params.split(" ") | ||
| 14 | channel = args[0] | ||
| 15 | if channel == settings.NICKNAME: | ||
| 16 | return | ||
| 17 | |||
| 18 | if "PRIVMSG" in obj_data.command and ":!google" in args[1].lower(): | ||
| 19 | search_string = " ".join(args[2:]) | ||
| 20 | url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&start=%d&rsz=large&q=%s"%(0,search_string.replace(" ","%20")) | ||
| 21 | req = urllib2.Request(url) | ||
| 22 | opener = urllib2.build_opener() | ||
| 23 | data = opener.open(req).read() | ||
| 24 | |||
| 25 | data = simplejson.loads(data) | ||
| 26 | result = data['responseData']['results'][0]['url'] | ||
| 27 | irc.privmsg(channel, result) \ No newline at end of file | ||
diff --git a/wmd/actions/modules.py b/wmd/actions/modules.py index eb726c2..e08d24c 100644 --- a/wmd/actions/modules.py +++ b/wmd/actions/modules.py | |||
| @@ -29,7 +29,7 @@ class ReloadModule(Action): | |||
| 29 | class LoadModule(Action): | 29 | class LoadModule(Action): |
| 30 | def recv_msg(self, irc, obj_data): | 30 | def recv_msg(self, irc, obj_data): |
| 31 | username = obj_data.get_username() | 31 | username = obj_data.get_username() |
| 32 | 32 | print obj_data.__dict__ | |
| 33 | if username in settings.ADMINS: | 33 | if username in settings.ADMINS: |
| 34 | args = obj_data.params.split(" ") | 34 | args = obj_data.params.split(" ") |
| 35 | if "PRIVMSG" in obj_data.command and ":LOADMODULE" in args[1].upper(): | 35 | if "PRIVMSG" in obj_data.command and ":LOADMODULE" in args[1].upper(): |