-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
44 lines (43 loc) · 1.59 KB
/
main.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
import discord
from discord.ext import commands
import wikipedia,os
from chatbot import Chat, register_call
prefix = "!"
bot = commands.Bot(command_prefix = prefix)
bot.remove_command("help")
@register_call("whoIs")
def who_is(query, session_id="general"):
try:
return wikipedia.summary(query)
except Exception:
for new_query in wikipedia.search(query):
try:
return wikipedia.summary(new_query)
except Exception:
pass
return "I don't know about "+query
template_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),"chatbotTemplate","chatbottemplate.template")
chat=Chat(template_file_path)
@bot.event
async def on_ready():
print("The bot is ready!")
@bot.command(pass_context = True)
async def sundance(ctx,*,message):
result = chat.respond(message)
if(len(result)<=2048):
embed=discord.Embed(title="Mikasa", description = result, color = (0xF48D1))
await ctx.send(embed=embed)
else:
embedList = []
n=2048
embedList = [result[i:i+n] for i in range(0, len(result), n)]
for num, item in enumerate(embedList, start = 1):
if(num == 1):
embed = discord.Embed(title="ChatBot AI", description = item, color = (0xF48D1))
embed.set_footer(text="Page {}".format(num))
await ctx.send(embed = embed)
else:
embed = discord.Embed(description = item, color = (0xF48D1))
embed.set_footer(text = "Page {}".format(num))
await ctx.send(embed = embed)
bot.run('TOKEN')