diff options
author | 2020-09-06 18:12:26 +0530 | |
---|---|---|
committer | 2020-09-06 18:12:26 +0530 | |
commit | a06d6127f62cd1dd48086c9cd117f049aa3c77f2 (patch) | |
tree | c09adf8b9478c1f633d994b001d3f48d0a0a4ceb | |
parent | corrected indexing problem (diff) |
corrected index error and solve issue spam issue of wiki command
-rw-r--r-- | bot/__init__.py | 2 | ||||
-rw-r--r-- | bot/bot.py | 1 | ||||
-rw-r--r-- | bot/exts/evergreen/wikipedia.py | 28 |
3 files changed, 21 insertions, 10 deletions
diff --git a/bot/__init__.py b/bot/__init__.py index 6976e089..a9a0865e 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -37,7 +37,7 @@ os.makedirs(log_dir, exist_ok=True) # File handler rotates logs every 5 MB file_handler = logging.handlers.RotatingFileHandler( - log_file, maxBytes=5*(2**20), backupCount=10) + log_file, maxBytes=5 * (2**20), backupCount=10) file_handler.setLevel(logging.TRACE if Client.debug else logging.DEBUG) # Console handler prints to terminal @@ -69,6 +69,7 @@ class SeasonalBot(commands.Bot): """Check command errors for UserInputError and reset the cooldown if thrown.""" if isinstance(exception, commands.UserInputError): context.command.reset_cooldown(context) + else: await super().on_command_error(context, exception) diff --git a/bot/exts/evergreen/wikipedia.py b/bot/exts/evergreen/wikipedia.py index 05bfbe66..b6714747 100644 --- a/bot/exts/evergreen/wikipedia.py +++ b/bot/exts/evergreen/wikipedia.py @@ -1,7 +1,7 @@ import asyncio import datetime import logging -from typing import Optional +from typing import Optional, List from discord import Color, Embed, Member from discord.ext import commands @@ -38,10 +38,11 @@ class WikipediaCog(commands.Cog): log.info("appening titles") return page + @commands.cooldown(1, 10, commands.BucketType.user) @commands.command(name="wikipedia", aliases=["wiki"]) async def w_pedia(self, ctx: commands.Context, *, search: str) -> None: - """Gives list of item.""" - final = [] + """Returns list of your search query from wikipedia.""" + titles_no_underscore: List[str] = [] s_desc = '' titles = await self.search_wikipedia(search) @@ -53,9 +54,9 @@ class WikipediaCog(commands.Cog): await ctx.send("Sorry, we could not find a wikipedia article using that search term") return - for i in titles: - t = i.replace(" ", "_") # wikipedia uses "_" as spaces - final.append(t) + for title in titles: + title_for_creating_link = title.replace(" ", "_") # wikipedia uses "_" as spaces + titles_no_underscore.append(title_for_creating_link) async with ctx.typing(): for index, title in enumerate(titles, start=1): @@ -69,18 +70,27 @@ class WikipediaCog(commands.Cog): try: user = await ctx.bot.wait_for('message', timeout=60.0, check=check) + response = await self.bot.get_context(user) + + if response.command: + return + response = int(user.content) + if response <= 0: - await ctx.send("Please enter a valid response") + await ctx.send("You cant send negative Index buddy") else: - await ctx.send(WIKIPEDIA_URL.format(title=final[response - 1])) + await ctx.send(WIKIPEDIA_URL.format(title=titles_no_underscore[response - 1])) except asyncio.TimeoutError: embed = Embed(colour=Color.red(), description=f"Time's up {ctx.author.mention}") await msg.edit(embed=embed) except ValueError: - await ctx.send("I am sorry but that isn't int value") + await ctx.send("sorry u cant do that I will only accept int") + + except IndexError: + await ctx.send("sorry but you are exceeding the limit please select from above list") def setup(bot: commands.Bot) -> None: |