From 540f98c8f2e890061884c70c62f38d9cfa64beff Mon Sep 17 00:00:00 2001 From: Numerlor <25886452+Numerlor@users.noreply.github.com> Date: Sun, 17 May 2020 23:31:00 +0200 Subject: Set ayncio event loop to Selector on windows. Python 3.8 set the default asyncio event loop on windows to Proactor, which is not supported in aiodns. Co-authored-by: MarkKoz --- bot/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'bot/__init__.py') diff --git a/bot/__init__.py b/bot/__init__.py index 4729e50c..6976e089 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -1,3 +1,4 @@ +import asyncio import logging import logging.handlers import os @@ -63,3 +64,8 @@ logging.basicConfig( handlers=[console_handler, file_handler] ) logging.getLogger().info('Logging initialization complete') + + +# On Windows, the selector event loop is required for aiodns. +if os.name == "nt": + asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) -- cgit v1.2.3 From a06d6127f62cd1dd48086c9cd117f049aa3c77f2 Mon Sep 17 00:00:00 2001 From: Anubhav1603 Date: Sun, 6 Sep 2020 18:12:26 +0530 Subject: corrected index error and solve issue spam issue of wiki command --- bot/__init__.py | 2 +- bot/bot.py | 1 + bot/exts/evergreen/wikipedia.py | 28 +++++++++++++++++++--------- 3 files changed, 21 insertions(+), 10 deletions(-) (limited to 'bot/__init__.py') 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 diff --git a/bot/bot.py b/bot/bot.py index ffaf4284..b94013bc 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -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: -- cgit v1.2.3