Skip to content

Commit ee54615

Browse files
author
Foxlet
committed
Replacement for the current Chatbot.py
1 parent bac6708 commit ee54615

3 files changed

Lines changed: 41 additions & 181 deletions

File tree

cloudbot/util/cleverbot.py

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

plugins/chatbot.py

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,48 @@
1-
from cloudbot.util import cleverbot
1+
"""
2+
chatbot.py
3+
4+
Ask Cleverbot something via CloudBot! This one is way shorter!
5+
6+
Created By:
7+
- Foxlet <http://furcode.tk/>
8+
9+
License:
10+
GNU General Public License (Version 3)
11+
"""
12+
213
from cloudbot import hook
14+
import requests
15+
import urllib.parse
16+
import hashlib
17+
import collections
18+
import html
19+
20+
SESSION = collections.OrderedDict()
21+
API_URL = "http://www.cleverbot.com/webservicemin/"
322

4-
import urllib
23+
@hook.onload()
24+
def init_vars():
25+
SESSION['stimulus'] = ""
26+
SESSION['sessionid'] = ""
27+
SESSION['start'] = 'y'
28+
SESSION['icognoid'] = 'wsf'
29+
SESSION['fno'] = '0'
30+
SESSION['sub'] = 'Say'
31+
SESSION['islearning'] = '1'
32+
SESSION['cleanslate'] = 'false'
533

34+
def cb_think(text):
35+
SESSION['stimulus'] = text
36+
payload = urllib.parse.urlencode(SESSION)
37+
digest = hashlib.md5(payload[9:35].encode('utf-8')).hexdigest()
38+
target_url = "{}&icognocheck={}".format(payload, digest)
39+
print(target_url)
40+
parsed = requests.post(API_URL, data=target_url)
41+
data = parsed.text.split('\r')
42+
SESSION['sessionid'] = data[1]
43+
return html.unescape(data[0])
644

745
@hook.command("ask", "cleverbot", "cb")
846
def ask(text):
947
""" <question> -- Asks Cleverbot <question> """
10-
session = cleverbot.Session()
11-
attempt = 0
12-
13-
try:
14-
answer = session.ask(text)
15-
while answer.startswith("\n") and attempt < 3:
16-
# Cleverbot tried to advert us
17-
answer = session.ask(text)
18-
attempt += 1
19-
except urllib.error.HTTPError:
20-
return "Could not get response. Cleverbot is angry :("
21-
22-
return answer
48+
return cb_think(text)

plugins/chatbot_new.py

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

0 commit comments

Comments
 (0)