Skip to content

Commit a69fbd6

Browse files
committed
Fixed issue with pagination indexes in grab.py
1 parent 3b564d5 commit a69fbd6

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

plugins/grab.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from cloudbot.util import database
99

1010
search_pages = defaultdict(list)
11+
search_page_indexes = {}
1112

1213
table = Table(
1314
'grab',
@@ -42,7 +43,7 @@ def two_lines(bigstring, chan):
4243
temp = bigstring.split('\n')
4344
for i in range(0, len(temp), 2):
4445
search_pages[chan].append('\n'.join(temp[i:i+2]))
45-
search_pages[chan+"index"] = 0
46+
search_page_indexes[chan] = 0
4647
return search_pages[chan][0]
4748

4849

@@ -69,9 +70,9 @@ def moregrab(text, chan):
6970
else:
7071
return "{}(page {}/{})".format(search_pages[chan][index-1], index, len(search_pages[chan]))
7172
else:
72-
search_pages[chan+"index"] += 1
73-
if search_pages[chan+"index"] < len(search_pages[chan]):
74-
return "{}(page {}/{})".format(search_pages[chan][search_pages[chan+"index"]], search_pages[chan+"index"] + 1, len(search_pages[chan]))
73+
search_page_indexes[chan] += 1
74+
if search_page_indexes[chan] < len(search_pages[chan]):
75+
return "{}(page {}/{})".format(search_pages[chan][search_page_indexes[chan]], search_page_indexes[chan] + 1, len(search_pages[chan]))
7576
else:
7677
return "All pages have been shown you can specify a page number or do a new search."
7778

@@ -97,7 +98,7 @@ def grab(text, nick, chan, db, conn):
9798
specified nick and adds it to the quote database"""
9899
if text.lower() == nick.lower():
99100
return "Didn't your mother teach you not to grab yourself?"
100-
101+
101102
for item in conn.history[chan].__reversed__():
102103
name, timestamp, msg = item
103104
if text.lower() == name.lower():
@@ -106,7 +107,7 @@ def grab(text, nick, chan, db, conn):
106107
return "I already have that quote from {} in the database".format(text)
107108
break
108109
else:
109-
# the quote is new so add it to the db.
110+
# the quote is new so add it to the db.
110111
grab_add(name.lower(),timestamp, msg, chan, db, conn)
111112
if check_grabs(name.lower(), msg, chan):
112113
return "the operation succeeded."
@@ -169,7 +170,7 @@ def grabsearch(text, chan):
169170
out = ""
170171
result = []
171172
search_pages[chan] = []
172-
search_pages[chan+"index"] = 0
173+
search_page_indexes[chan] = 0
173174
try:
174175
quotes = grab_cache[chan][text.lower()]
175176
for grab in quotes:
@@ -192,7 +193,7 @@ def grabsearch(text, chan):
192193
out = out[:-2]
193194
out = two_lines(out, chan)
194195
if len(search_pages[chan]) > 1:
195-
return "{}(page {}/{}) .moregrab".format(out, search_pages[chan+"index"] + 1 , len(search_pages[chan]))
196+
return "{}(page {}/{}) .moregrab".format(out, search_page_indexes[chan] + 1, len(search_pages[chan]))
196197
return out
197198
else:
198199
return "I couldn't find any matches for {}.".format(text)

0 commit comments

Comments
 (0)