Sat, 29 Nov 2014 10:11:42 -0500
- .update removed, no longer necessary
65
20bd76353eb5
- modularized the configuration and made it more systematic
Teemu Piippo <crimsondusk64@gmail.com>
parents:
63
diff
changeset
|
1 | from modulecore import command_error |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | import hgapi |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | import urllib |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | import urllib2 |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | import json |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | ModuleData = { |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | 'commands': |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | [ |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | { |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | 'name': 'idgames', |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | 'description': 'Searches doomworld.com/idgames for wads', |
63
a1a864c25e42
- fixed: .cset didn't operate properly with dates
Teemu Piippo <crimsondusk64@gmail.com>
parents:
62
diff
changeset
|
13 | 'args': '<wad...>', |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | 'level': 'normal', |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | }, |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | ] |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | } |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | g_idgamesSearchURL = 'http://www.doomworld.com/idgames/api/api.php?action=search&query=%s&type=title&sort=date&out=json' |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | def cmd_idgames (bot, args, replyto, **rest): |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | try: |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | url = g_idgamesSearchURL % urllib.quote (args['wad']) |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | response = urllib2.urlopen (url).read() |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | data = json.loads (response) |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | if 'content' in data and 'file' in data['content']: |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | if type (data['content']['file']) is list: |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | files = data['content']['file'] |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | else: |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | files = [data['content']['file']] |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | i = 0 |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | for filedata in files: |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | if i >= 5: |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | break |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | bot.privmsg (replyto, '- %s: \'%s\' by \'%s\', rating: %s: %s' % \ |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | (filedata['filename'], filedata['title'], filedata['author'], filedata['rating'], filedata['url'])) |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | i += 1 |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | #done |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | bot.privmsg (replyto, "(%d / %d results posted)" % (i, len(files))) |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | elif 'warning' in data and 'message' in data['warning']: |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | command_error (data['warning']['message']) |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | elif 'error' in data and 'message' in data['error']: |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | command_error (data['error']['message']) |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | else: |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | command_error ("Incomplete JSON response from doomworld.com/idgames") |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | except Exception as e: |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | command_error ('search failed: %s' % str (e)) |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | #tried |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | #enddef |