Skip to content

Commit 593ff63

Browse files
committed
Fix ireplace loop @GonZo
1 parent ac1a45b commit 593ff63

3 files changed

Lines changed: 22 additions & 53 deletions

File tree

cloudbot/util/dictionaries.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

cloudbot/util/formatting.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ def ireplace(text, old, new, count=None):
173173
old replaced by new. If the optional argument count is given, only the first count
174174
occurrences are replaced.
175175
"""
176+
last_idx = 0
176177
idx = 0
177178
num = 0
178179
while idx < len(text):
@@ -185,6 +186,10 @@ def ireplace(text, old, new, count=None):
185186
num += 1
186187
if count and num >= count:
187188
break
189+
# if the function is just looping, end it
190+
if idx == last_idx:
191+
break
192+
last_idx = int(idx)
188193
return text
189194

190195

plugins/chatbot.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,30 @@
1010
GNU General Public License (Version 3)
1111
"""
1212

13-
from cloudbot import hook
14-
import requests
1513
import urllib.parse
1614
import hashlib
1715
import collections
1816
import html
1917

18+
import requests
19+
20+
from cloudbot import hook
21+
22+
2023
SESSION = collections.OrderedDict()
2124
API_URL = "http://www.cleverbot.com/webservicemin/"
2225

2326
HEADERS = {
24-
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
25-
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
26-
'Accept-Language': 'en-us;q=0.8,en;q=0.5',
27-
'Pragma': 'no-cache',
28-
'Referer': 'http://www.cleverbot.com',
29-
'User-Agent': 'Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19',
30-
'X-Moz': 'prefetch'
31-
}
27+
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
28+
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
29+
'Accept-Language': 'en-us;q=0.8,en;q=0.5',
30+
'Pragma': 'no-cache',
31+
'Referer': 'http://www.cleverbot.com',
32+
'User-Agent': 'Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like '
33+
'Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19',
34+
'X-Moz': 'prefetch'
35+
}
36+
3237

3338
@hook.on_start()
3439
def init_vars():
@@ -41,6 +46,7 @@ def init_vars():
4146
SESSION['islearning'] = '1'
4247
SESSION['cleanslate'] = 'false'
4348

49+
4450
def cb_think(text):
4551
SESSION['stimulus'] = text
4652
payload = urllib.parse.urlencode(SESSION)
@@ -51,6 +57,7 @@ def cb_think(text):
5157
SESSION['sessionid'] = data[1]
5258
return html.unescape(str(data[0]))
5359

60+
5461
@hook.command("ask", "cleverbot", "cb")
5562
def ask(text):
5663
""" <question> -- Asks Cleverbot <question> """

0 commit comments

Comments
 (0)