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