5
from gozerbot.compat.persist import Persist
7
class Quoteitem(object):
9
""" object representing a quote """
11
def __init__(self, idnr, txt, nick=None, userhost=None, ttime=None):
15
self.userhost = userhost
18
class Quotes(Persist):
20
""" list of quotes """
22
def __init__(self, fname):
23
Persist.__init__(self, fname)
28
""" return nr of quotes """
31
def add(self, nick, userhost, quote):
33
id = nextid.next('quotes')
34
item = Quoteitem(id, quote, nick, userhost, \
36
self.data.append(item)
40
def addnosave(self, nick, userhost, quote, ttime):
41
""" add quote but don't call save """
42
id = nextid.next('quotes')
43
item = Quoteitem(nextid.next('quotes'), quote, nick, userhost, ttime)
44
self.data.append(item)
47
def delete(self, quotenr):
48
""" delete quote with id == nr """
49
for i in range(len(self.data)):
50
if self.data[i].id == quotenr:
56
""" get random quote """
59
quotenr = random.randint(0, len(self.data)-1)
60
return self.data[quotenr]
62
def idquote(self, quotenr):
63
""" get quote by id """
68
def whoquote(self, quotenr):
69
""" get who quoted the quote """
72
return (i.nick, i.time)
75
""" get last quote """
76
return self.data[len(self.data)-nr:]
78
def search(self, what):
83
andre = re.compile('and', re.I)
84
ands = re.split(andre, what)
88
if i.txt.find(item.strip()) == -1:
96
def searchlast(self, what, nr=1):
97
""" search quotes backwards limit to 1"""
101
andre = re.compile('and', re.I)
102
ands = re.split(andre, what)
104
for i in self.data[::-1]:
106
if i.txt.find(item.strip()) == -1: