format indenting to 4 spaces (PEP 8)
This commit is contained in:
1 parent
7be76c00c3
commit
6fe6a756bb
1 file changed
+1
-15
+1
-15
@@ -6,16 +6,15 @@ import requests
|
|||||||
import asyncio
|
import asyncio
|
||||||
import os
|
import os
|
||||||
import feedparser
|
import feedparser
|
||||||
import json
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
class Chatbot(commands.Cog):
|
class Chatbot(commands.Cog):
|
||||||
"""Een heuse chatbot. Under construction..."""
|
"""Een heuse chatbot. Under construction..."""
|
||||||
|
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.voice_states = {}
|
|
||||||
self.END_OF_MESSAGE = "<EOM>"
|
self.END_OF_MESSAGE = "<EOM>"
|
||||||
self.START_OF_MESSAGE = "<SOM>"
|
self.START_OF_MESSAGE = "<SOM>"
|
||||||
self.pmLast = datetime(2018, 1, 1, 1, 1, 1)
|
self.pmLast = datetime(2018, 1, 1, 1, 1, 1)
|
||||||
@@ -89,7 +88,6 @@ class Chatbot(commands.Cog):
|
|||||||
def __check(self, ctx):
|
def __check(self, ctx):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
#The "Guus filter"
|
#The "Guus filter"
|
||||||
#Don't allow to learn from very large personal messages
|
#Don't allow to learn from very large personal messages
|
||||||
#Only learn from 10 personal messages per hour at most
|
#Only learn from 10 personal messages per hour at most
|
||||||
@@ -187,8 +185,6 @@ class Chatbot(commands.Cog):
|
|||||||
|
|
||||||
return newRespPairDict
|
return newRespPairDict
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@commands.command(pass_context=True, hidden=True)
|
@commands.command(pass_context=True, hidden=True)
|
||||||
async def trainmarkovchat(self, ctx, channelId=409751773595566081, nrOfMessages=50):
|
async def trainmarkovchat(self, ctx, channelId=409751773595566081, nrOfMessages=50):
|
||||||
"""Train that chain, jermaine
|
"""Train that chain, jermaine
|
||||||
@@ -201,7 +197,6 @@ class Chatbot(commands.Cog):
|
|||||||
|
|
||||||
await ctx.channel.send("Ik heb weer wat nieuwe woordjes geleerd. :slight_smile:")
|
await ctx.channel.send("Ik heb weer wat nieuwe woordjes geleerd. :slight_smile:")
|
||||||
|
|
||||||
|
|
||||||
#Learns from an x number of messages from a certain channel
|
#Learns from an x number of messages from a certain channel
|
||||||
async def learnFromMessagesInChannel(self, channel, nrOfMessages):
|
async def learnFromMessagesInChannel(self, channel, nrOfMessages):
|
||||||
|
|
||||||
@@ -256,7 +251,6 @@ class Chatbot(commands.Cog):
|
|||||||
|
|
||||||
np.save("markov_dict.npy", wordDict)
|
np.save("markov_dict.npy", wordDict)
|
||||||
|
|
||||||
|
|
||||||
@commands.command(pass_context=True, hidden=False)
|
@commands.command(pass_context=True, hidden=False)
|
||||||
async def reageer(self, ctx):
|
async def reageer(self, ctx):
|
||||||
"""Laat Stroop ergens op reageren.
|
"""Laat Stroop ergens op reageren.
|
||||||
@@ -329,7 +323,6 @@ class Chatbot(commands.Cog):
|
|||||||
return self.translateTo("nl", respons)
|
return self.translateTo("nl", respons)
|
||||||
|
|
||||||
def getResponseForMessageLocal(self, wordsToRespondTo):
|
def getResponseForMessageLocal(self, wordsToRespondTo):
|
||||||
|
|
||||||
MAX_N_WORDS = 100 #Don't use more words than this
|
MAX_N_WORDS = 100 #Don't use more words than this
|
||||||
|
|
||||||
#Get dictionary/Markov chain
|
#Get dictionary/Markov chain
|
||||||
@@ -372,7 +365,6 @@ class Chatbot(commands.Cog):
|
|||||||
#Pick a next word:
|
#Pick a next word:
|
||||||
chain.append(self.pickNextWord(pairPossibilities))
|
chain.append(self.pickNextWord(pairPossibilities))
|
||||||
|
|
||||||
|
|
||||||
if chain[0] == self.START_OF_MESSAGE:
|
if chain[0] == self.START_OF_MESSAGE:
|
||||||
chain = chain[1:-1] #remove <SOM> and <EOM>
|
chain = chain[1:-1] #remove <SOM> and <EOM>
|
||||||
else:
|
else:
|
||||||
@@ -389,9 +381,6 @@ class Chatbot(commands.Cog):
|
|||||||
#await ctx.channel.send(' '.join(chain))
|
#await ctx.channel.send(' '.join(chain))
|
||||||
return ' '.join(chain)
|
return ' '.join(chain)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#Try to count the number of syllables in a word
|
#Try to count the number of syllables in a word
|
||||||
#Used to make Haikus
|
#Used to make Haikus
|
||||||
def countSyllables(self, word: str):
|
def countSyllables(self, word: str):
|
||||||
@@ -436,7 +425,6 @@ class Chatbot(commands.Cog):
|
|||||||
#Make a nice Haiku
|
#Make a nice Haiku
|
||||||
def getHaiku(self):
|
def getHaiku(self):
|
||||||
MAX_N_TRIES = 50
|
MAX_N_TRIES = 50
|
||||||
|
|
||||||
#Get dictionary/Markov chain
|
#Get dictionary/Markov chain
|
||||||
wordDict = np.load('markov_dict.npy', allow_pickle=True).item()
|
wordDict = np.load('markov_dict.npy', allow_pickle=True).item()
|
||||||
wordPairDict = wordDict['pairs']
|
wordPairDict = wordDict['pairs']
|
||||||
@@ -462,7 +450,6 @@ class Chatbot(commands.Cog):
|
|||||||
async def haiku(self, ctx):
|
async def haiku(self, ctx):
|
||||||
"""Stroop is een poëet. Laat hem een Haiku maken.
|
"""Stroop is een poëet. Laat hem een Haiku maken.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
response = self.getHaiku()
|
response = self.getHaiku()
|
||||||
await ctx.channel.send(response)
|
await ctx.channel.send(response)
|
||||||
|
|
||||||
@@ -673,7 +660,6 @@ class Chatbot(commands.Cog):
|
|||||||
def get_limerick(self):
|
def get_limerick(self):
|
||||||
MAX_ATTEMPTS = 15
|
MAX_ATTEMPTS = 15
|
||||||
MAX_LINE_TRIES = 5
|
MAX_LINE_TRIES = 5
|
||||||
|
|
||||||
for _ in range(MAX_ATTEMPTS):
|
for _ in range(MAX_ATTEMPTS):
|
||||||
limerick = []
|
limerick = []
|
||||||
used_rhymes = {}
|
used_rhymes = {}
|
||||||
|
|||||||
Reference in new issue
Block a user