/
console.py
56 lines (46 loc) · 2.22 KB
/
console.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Copyright New-dev0 2022
# https://github.com/New-dev0/BING-CHATBOT
print(
"""
░█████╗░██╗░░██╗░█████╗░████████╗██████╗░░█████╗░████████╗
██╔══██╗██║░░██║██╔══██╗╚══██╔══╝██╔══██╗██╔══██╗╚══██╔══╝
██║░░╚═╝███████║███████║░░░██║░░░██████╦╝██║░░██║░░░██║░░░
██║░░██╗██╔══██║██╔══██║░░░██║░░░██╔══██╗██║░░██║░░░██║░░░
╚█████╔╝██║░░██║██║░░██║░░░██║░░░██████╦╝╚█████╔╝░░░██║░░░
░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝░░░╚═╝░░░╚═════╝░░╚════╝░░░░╚═╝░░░
\n\n"""
)
try:
import requests
except ImportError:
print("'requests' module not installed.")
print("Install it to run the console bot.")
exit()
print("Enter 'exit anytime to exit the chatbot..")
CV_HNDLR = {}
print("Enter Message.")
def main(inpt):
if inpt == "'exit":
exit()
json = {"userMessageText": inpt}
if CV_HNDLR:
json.update({"conversationId": CV_HNDLR["_"]})
_ = requests.post("https://services.bingapis.com/sydney/chat", json=json).json()
if not _.get("messages") and "has expired." in _["result"]["message"]:
del CV_HNDLR["_"]
main(inpt)
return
for msg in _["messages"]:
if msg["author"] == "bot":
print(">>", msg["text"])
if msg.get("hiddenText"):
print("\n\n>>", msg["hiddenText"])
if msg.get("sourceName"):
print(">>\n-", msg["sourceName"], "\n-", msg["sourceUrl"])
if msg.get("linkUrl"):
print(">> -", msg["linkUrl"])
if not CV_HNDLR:
CV_HNDLR["_"] = _["conversationId"]
while True:
inpt = input("> ")
main(inpt)