This repository was archived by the owner on Jun 4, 2021. It is now read-only.
forked from jagrosh/FrostCleverbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrost.py
58 lines (51 loc) · 2.16 KB
/
frost.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
57
58
import asyncio
import aiohttp
import json
import discord
client = discord.Client()
user = 'CLEVERBOT.IO API USER'
key = 'CLEVERBOT.IO API KEY'
client.session = aiohttp.ClientSession()
client.ready = False
@client.event
async def on_ready():
print('Starting...')
payload = {'data': json.dumps({'user': user,
'key': key,
'nick': client.user.name}),
'headers': {'content-type': 'application/json'}}
async with client.session.post(r'https://cleverbot.io/1.0/create', **payload) as r:
j = await r.json()
if j['status'] != 'success':
print('Something went wrong with cleverbot.io login!')
print(j['status'])
client.session.close()
return await client.logout()
print('Logged into cleverbot.io successfully!')
client.ready = True
print('Logged in as {0.user.name} (ID: {0.user.id} ) | {1} servers'
.format(client, str(len(client.servers))))
await client.change_presence(game=discord.Game(name='chat with me!'))
@client.event
async def on_message(message):
if not client.ready or message.author.bot:
return
if not message.server or client.user in message.mentions:
await client.send_typing(message.channel)
text = message.content.replace(client.user.mention, '')
payload = {'data': json.dumps({'user': user,
'key': key,
'text': text,
'nick': client.user.name}),
'headers': {'content-type': 'application/json'},
'timeout':10}
try:
async with client.session.post(r'https://cleverbot.io/1.0/ask', **payload) as r:
if r.status == 200:
j = await r.json()
if j['status'] == 'success':
print(j['response'])
await client.send_message(message.channel, j['response'])
except asyncio.TimeoutError:
await client.send_message(message.channel, 'Request timed out!')
client.run('DISCORD BOT TOKEN')