-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgb.py
More file actions
38 lines (30 loc) · 1.02 KB
/
gb.py
File metadata and controls
38 lines (30 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
import plugin
from urllib import request
from random import choice
import re
class Plugin(plugin.Plugin):
def register_commands(self):
self.commands = [
('gb', self.gb)
]
def gb(self, message, args):
"""
Pull a quote from the [Giant Bomb Quoter](http://www.deertier.com/gb/).
"""
lines = request.urlopen('http://www.deertier.com/gb/quotes.js')
quotes = []
for line in lines:
line = line.decode('utf-8')
match = re.match(
r'\s*{name:\s*"([^"]+)",\s*quote:\s*"([^"]+)"},', line)
if match:
quotation = re.sub('<[^>]+?>', '\x02', match.group(2))
quote = {
'quote': quotation,
'author': match.group(1),
}
quotes.append(quote)
quote = choice(quotes)
quotation = '“%s” -%s' % (quote['quote'], quote['author'])
self.irc.privmsg(message.source, quotation)