diff --git a/Chatbot.py b/Chatbot.py index a71303a..83ba5f5 100644 --- a/Chatbot.py +++ b/Chatbot.py @@ -20,6 +20,7 @@ class Chatbot(commands.Cog): self.START_OF_MESSAGE = "" 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" ] - 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)) - response = await self.getResponseForMessage(artikel.title, gptChance=0.5) - await ctx.channel.send(response + '\n' + artikel.link) + 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(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)