Voorkomt nos reposts. fixes #28
This commit is contained in:
+18
-2
@@ -20,6 +20,7 @@ class Chatbot(commands.Cog):
|
||||
self.START_OF_MESSAGE = "<SOM>"
|
||||
self.pmLast = datetime(2018, 1, 1, 1, 1, 1)
|
||||
self.pmCount = 0
|
||||
self.nosPosts = []
|
||||
try:
|
||||
np.load('markov_dict.npy', allow_pickle=True)
|
||||
except FileNotFoundError:
|
||||
@@ -223,6 +224,11 @@ class Chatbot(commands.Cog):
|
||||
pass # Dit is een commando. Negeer.
|
||||
elif "```" in messageContent:
|
||||
pass # Daar zit een codeblok in. Negeer.
|
||||
elif "http" in messageContent and "nos" in messageContent:
|
||||
# NOS link
|
||||
nosIds = re.findall(r'\d+', messageContent)
|
||||
if nosIds:
|
||||
self.nosPosts.append(nosIds[0])
|
||||
elif messageContent[0:7] == "http://" or messageContent[0:8] == "https://":
|
||||
pass # Een link. Negeer. TODO: post af en toe een random link die geen repost is
|
||||
else:
|
||||
@@ -496,13 +502,23 @@ class Chatbot(commands.Cog):
|
||||
"cultuurenmedia",
|
||||
"tech"
|
||||
]
|
||||
artikel = None
|
||||
tries = 0
|
||||
while artikel is None:
|
||||
tries += 1
|
||||
if not categorie:
|
||||
categorie = random.choice(opties)
|
||||
categorie = categorie.lower()
|
||||
if categorie in opties:
|
||||
artikelen = feedparser.parse("https://feeds.nos.nl/nosnieuws" + categorie).entries
|
||||
artikel = random.choice(artikelen)
|
||||
#print(artikel)
|
||||
print(json.dumps(artikel, indent=4))
|
||||
#print(json.dumps(artikel, indent=4))
|
||||
nosId = re.findall(r'\d+', artikel.id)[0]
|
||||
if nosId not in self.nosPosts:
|
||||
self.nosPosts.append(nosId)
|
||||
response = await self.getResponseForMessage(artikel.title, gptChance=0.5)
|
||||
elif tries > 100:
|
||||
print("Oneindige loop voorkomen. Damn.")
|
||||
else:
|
||||
artikel = None
|
||||
await ctx.channel.send(response + '\n' + artikel.link)
|
||||
|
||||
Reference in New Issue
Block a user