|
|
|
@ -4,6 +4,7 @@ import random
|
|
|
|
|
from nltk.tokenize import sent_tokenize, word_tokenize
|
|
|
|
|
import json
|
|
|
|
|
#from thread import start_new_thread
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
r= Rake()
|
|
|
|
|
|
|
|
|
@ -14,12 +15,14 @@ def chunks(l, n):
|
|
|
|
|
|
|
|
|
|
class HelloBot(irc.bot.SingleServerIRCBot):
|
|
|
|
|
def __init__(self, channel, nickname, server, port=6667, index=None):
|
|
|
|
|
print("connecting to chatroom...")
|
|
|
|
|
irc.bot.SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
|
|
|
|
|
self.channel = channel
|
|
|
|
|
self.index = index
|
|
|
|
|
|
|
|
|
|
def on_welcome(self, c, e):
|
|
|
|
|
c.join(self.channel)
|
|
|
|
|
print("joined chatroom")
|
|
|
|
|
|
|
|
|
|
def on_privmsg(self, c, e):
|
|
|
|
|
pass
|
|
|
|
@ -27,10 +30,15 @@ class HelloBot(irc.bot.SingleServerIRCBot):
|
|
|
|
|
def on_pubmsg(self, c, e):
|
|
|
|
|
print(e.arguments, e.source)
|
|
|
|
|
msg=e.arguments[0]
|
|
|
|
|
incoming_msg = e.arguments[0]
|
|
|
|
|
print(incoming_msg)
|
|
|
|
|
r.extract_keywords_from_text(msg)
|
|
|
|
|
#r.get_ranked_phrases_with_scores()
|
|
|
|
|
listOfKeys = r.get_ranked_phrases()
|
|
|
|
|
|
|
|
|
|
msg_where = ""
|
|
|
|
|
|
|
|
|
|
if incoming_msg != "I don't know anything about that":
|
|
|
|
|
for keyWord in listOfKeys:
|
|
|
|
|
if keyWord in self.index:
|
|
|
|
|
msg = (index.get(keyWord)[0].get('sentence'))
|
|
|
|
@ -41,6 +49,7 @@ class HelloBot(irc.bot.SingleServerIRCBot):
|
|
|
|
|
|
|
|
|
|
for chunk in chunks(msg, 400):
|
|
|
|
|
c.privmsg(self.channel, chunk)
|
|
|
|
|
print(chunk)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
c.privmsg(self.channel, msg_where)
|
|
|
|
@ -68,6 +77,8 @@ if __name__ == "__main__":
|
|
|
|
|
index={}
|
|
|
|
|
|
|
|
|
|
#print(index)
|
|
|
|
|
myhost = os.uname()[1]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bot = HelloBot(args.channel, args.nickname, args.server, args.port, index)
|
|
|
|
|
bot = HelloBot(args.channel, "{0}-{1}-bot".format(myhost, len(index)), args.server, args.port, index)
|
|
|
|
|
bot.start()
|
|
|
|
|