diff --git a/jarvis/cogs/jokes.py b/jarvis/cogs/jokes.py index bcbf7ca..979e2b4 100644 --- a/jarvis/cogs/jokes.py +++ b/jarvis/cogs/jokes.py @@ -39,27 +39,27 @@ class JokeCog(commands.Cog): {"$match": {"score": {"$gt": threshold}}}, {"$sample": {"size": 1}}, ] - result = Joke.objects().aggregate(pipeline).first() - while result.body in ["[removed]", "[deleted]"]: - result = Joke.objects().aggregate(pipeline).first() + result = Joke.objects().aggregate(pipeline).next() + while result["body"] in ["[removed]", "[deleted]"]: + result = Joke.objects().aggregate(pipeline).next() if result is None: await ctx.send( "Humor module failed. Please try again later.", hidden=True ) return - emotes = re.findall(r"(&#x[a-fA-F0-9]*;)", result.body) + emotes = re.findall(r"(&#x[a-fA-F0-9]*;)", result["body"]) for match in emotes: - result.body = result.body.replace(match, html.unescape(match)) - emotes = re.findall(r"(&#x[a-fA-F0-9]*;)", result.title) + result["body"] = result["body"].replace(match, html.unescape(match)) + emotes = re.findall(r"(&#x[a-fA-F0-9]*;)", result["title"]) for match in emotes: - result.title = result.title.replace( + result["title"] = result["title"].replace( match, html.unescape(match) ) body_chunks = [] body = "" - for word in result.body.split(" "): + for word in result["body"].split(" "): if len(body) + 1 + len(word) > 1024: body_chunks.append(Field("​", body, False)) body = "" @@ -71,7 +71,7 @@ class JokeCog(commands.Cog): body += " " + word desc = "" - title = result.title + title = result["title"] if len(title) > 256: new_title = "" limit = False @@ -88,18 +88,18 @@ class JokeCog(commands.Cog): body_chunks.append(Field("​", body, False)) fields = body_chunks - fields.append(Field("Score", result.score)) + fields.append(Field("Score", result["score"])) # Field( # "Created At", # str(datetime.fromtimestamp(result["created_utc"])), # ), - fields.append(Field("ID", result.id)) + fields.append(Field("ID", result["rid"])) embed = build_embed( title=title, description=desc, fields=fields, - url=f"https://reddit.com/r/jokes/comments/{result.rid}", - timestamp=datetime.fromtimestamp(result.created_utc), + url=f"https://reddit.com/r/jokes/comments/{result['rid']}", + timestamp=datetime.fromtimestamp(result["created_utc"]), ) await ctx.send(embed=embed) except Exception: