-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnltk-chat.py
executable file
·50 lines (36 loc) · 1.27 KB
/
nltk-chat.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
#!/usr/bin/env python3
"""
Example of how to incorporate NLTK chat into Discord bot
"""
import os
import discord
from discord.ext import commands
from dotenv import load_dotenv
from loguru import logger
from nltk.chat.iesha import iesha_chatbot
from nltk.chat.eliza import eliza_chatbot
from nltk.chat.rude import rude_chatbot
from nltk.chat.suntsu import suntsu_chatbot
load_dotenv()
logger.add('logs/chatbot-{time:YYYY-MM-DD}.log',
format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}", level="INFO")
TOKEN = os.getenv('TOKEN')
# CHANNEL = os.getenv('CHANNEL')
# SERVER = os.getenv('SERVER')
# channel_id = bot.get_channel(CHANNEL)
class MyClient(discord.Client):
async def on_ready(self):
logger.info("Logged into Discord as: {}", self.user.name)
async def on_message(self, message):
# we do not want the bot to reply to itself
if message.author.id == self.user.id:
logger.info("Sent msg: {}", message.content)
return
else:
logger.info("Received msg from {}: {}",
message.author, message.content)
response = eliza_chatbot.respond(message.content)
await message.reply(response)
if __name__ == "__main__":
client = MyClient()
client.run(TOKEN)