From c94ead0429cc3e2705d229b40843852ac0e59a79 Mon Sep 17 00:00:00 2001 From: aikaterna <20862007+aikaterna@users.noreply.github.com> Date: Wed, 9 Sep 2020 10:17:01 -0700 Subject: [PATCH] [Dictionary] Pagify results --- dictionary/dictionary.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/dictionary/dictionary.py b/dictionary/dictionary.py index dd09c65..4a4d009 100644 --- a/dictionary/dictionary.py +++ b/dictionary/dictionary.py @@ -3,6 +3,7 @@ from bs4 import BeautifulSoup import logging import re from redbot.core import commands +from redbot.core.utils.chat_formatting import pagify log = logging.getLogger("red.aikaterna.dictionary") @@ -34,14 +35,16 @@ class Dictionary(commands.Cog): @commands.command() async def antonym(self, ctx, *, word: str): """Displays antonyms for a given word.""" - search_msg = await ctx.send("Searching...") search_term = word.split(" ", 1)[0] result = await self._antonym(ctx, search_term) if not result: - return await search_msg.edit(content="This word is not in the dictionary.") + await ctx.send("This word is not in the dictionary.") + return result_text = "*, *".join(result) - await search_msg.edit(content=f"Antonyms for **{search_term}**: *{result_text}*") + msg = f"Antonyms for **{search_term}**: *{result_text}*" + for page in pagify(msg, delims=["\n"]): + await ctx.send(page) async def _antonym(self, ctx, word): data = await self._get_soup_object(f"http://www.thesaurus.com/browse/{word}") @@ -64,7 +67,9 @@ class Dictionary(commands.Cog): result = await self._definition(ctx, search_term) str_buffer = "" if not result: - return await search_msg.edit(content="This word is not in the dictionary.") + await search_msg.delete() + await ctx.send("This word is not in the dictionary.") + return for key in result: str_buffer += f"\n**{key}**: \n" counter = 1 @@ -81,7 +86,9 @@ class Dictionary(commands.Cog): else: str_buffer += f"{str(counter)}. {val}\n" counter += 1 - await search_msg.edit(content=str_buffer) + await search_msg.delete() + for page in pagify(str_buffer, delims=["\n"]): + await ctx.send(page) async def _definition(self, ctx, word): data = await self._get_soup_object(f"http://wordnetweb.princeton.edu/perl/webwn?s={word}") @@ -121,11 +128,13 @@ class Dictionary(commands.Cog): @commands.command() async def synonym(self, ctx, *, word: str): """Displays synonyms for a given word.""" - search_msg = await ctx.send("Searching...") search_term = word.split(" ", 1)[0] result = await self._synonym(ctx, search_term) if not result: - return await search_msg.edit(content="This word is not in the dictionary.") + await ctx.send("This word is not in the dictionary.") + return result_text = "*, *".join(result) - await search_msg.edit(content=f"Synonyms for **{search_term}**: *{result_text}*") + msg = f"Synonyms for **{search_term}**: *{result_text}*" + for page in pagify(msg, delims=["\n"]): + await ctx.send(page)