77from cloudbot import hook
88
99search_pages = defaultdict (list )
10+ search_page_indexes = {}
1011
1112user_url = "http://reddit.com/user/{}/"
1213subreddit_url = "http://reddit.com/r/{}/"
@@ -20,7 +21,7 @@ def two_lines(bigstring, chan):
2021 temp = bigstring .split ('\n ' )
2122 for i in range (0 , len (temp ), 2 ):
2223 search_pages [chan ].append ('\n ' .join (temp [i :i + 2 ]))
23- search_pages [chan + "index" ] = 0
24+ search_page_indexes [chan ] = 0
2425 return search_pages [chan ][0 ]
2526
2627
@@ -61,9 +62,9 @@ def moremod(text, chan):
6162 else :
6263 return "{}(page {}/{})" .format (search_pages [chan ][index - 1 ], index , len (search_pages [chan ]))
6364 else :
64- search_pages [chan + "index" ] += 1
65- if search_pages [chan + "index" ] < len (search_pages [chan ]):
66- return "{}(page {}/{})" .format (search_pages [chan ][search_pages [chan + "index" ]], search_pages [chan + "index" ] + 1 , len (search_pages [chan ]))
65+ search_page_indexes [chan ] += 1
66+ if search_page_indexes [chan ] < len (search_pages [chan ]):
67+ return "{}(page {}/{})" .format (search_pages [chan ][search_page_indexes [chan ]], search_page_indexes [chan ] + 1 , len (search_pages [chan ]))
6768 else :
6869 return "All pages have been shown."
6970
@@ -74,7 +75,7 @@ def moderates(text, chan):
7475 #This command was written using concepts from FurCode http://github.com/FurCode.
7576 global search_pages
7677 search_pages [chan ] = []
77- search_pages [chan + "index" ] = 0
78+ search_page_indexes [chan ] = 0
7879 user = text
7980 r = requests .get (user_url .format (user ), headers = agent )
8081 if r .status_code != 200 :
@@ -93,7 +94,7 @@ def moderates(text, chan):
9394 out = smart_truncate (out )
9495 if len (out .split ('\n ' )) > 2 :
9596 out = two_lines (out , chan )
96- return "{}(page {}/{}) .moremod" .format (out , search_pages [chan + "index" ] + 1 , len (search_pages [chan ]))
97+ return "{}(page {}/{}) .moremod" .format (out , search_page_indexes [chan ] + 1 , len (search_pages [chan ]))
9798 return out
9899
99100
@@ -122,7 +123,7 @@ def karma(text):
122123 if age == 1 :
123124 out += "redditor for {} year." .format (age )
124125 else :
125- out += "redditor for {} years." .format (age )
126+ out += "redditor for {} years." .format (age )
126127 else :
127128 out += "redditor for {} days." .format (account_age .days )
128129 return out
@@ -164,7 +165,7 @@ def submods(text, chan):
164165 """submods <subreddit> prints the moderators of the specified subreddit. Do not include /r/ when specifying a subreddit."""
165166 global search_pages
166167 search_pages [chan ] = []
167- search_pages [chan + "index" ] = 0
168+ search_page_indexes [chan ] = 0
168169 sub = text
169170 url = subreddit_url + "about/moderators.json"
170171 r = requests .get (url .format (sub ), headers = agent )
@@ -183,7 +184,7 @@ def submods(text, chan):
183184 out = out [:- 3 ]
184185 if len (out .split ('\n ' )) > 2 :
185186 out = two_lines (out , chan )
186- return "{}(page {}/{}) .moremod" .format (out , search_pages [chan + "index" ] + 1 , len (search_pages [chan ]))
187+ return "{}(page {}/{}) .moremod" .format (out , search_page_indexes [chan ] + 1 , len (search_pages [chan ]))
187188 return out
188189
189190@hook .command ("subinfo" ,"subreddit" , "sub" , "rinfo" , singlethreaded = True )
0 commit comments