diff --git a/announcedaily/announcedaily.py b/announcedaily/announcedaily.py index aa50e6c..98690f7 100644 --- a/announcedaily/announcedaily.py +++ b/announcedaily/announcedaily.py @@ -54,8 +54,7 @@ class AnnounceDaily(Cog): Do `[p]help annd ` for more details """ - if ctx.invoked_subcommand is None: - pass + pass @commands.command() @checks.guildowner() diff --git a/audiotrivia/audiotrivia.py b/audiotrivia/audiotrivia.py index 9617f32..73eca95 100644 --- a/audiotrivia/audiotrivia.py +++ b/audiotrivia/audiotrivia.py @@ -168,7 +168,7 @@ class AudioTrivia(Trivia): @commands.guild_only() async def audiotrivia_list(self, ctx: commands.Context): """List available trivia including audio categories.""" - lists = set(p.stem for p in self._all_audio_lists()) + lists = {p.stem for p in self._all_audio_lists()} if await ctx.embed_requested(): await ctx.send( embed=discord.Embed( diff --git a/ccrole/ccrole.py b/ccrole/ccrole.py index 5248766..e3691f8 100644 --- a/ccrole/ccrole.py +++ b/ccrole/ccrole.py @@ -48,8 +48,7 @@ class CCRole(commands.Cog): """Custom commands management with roles Highly customizable custom commands with role management.""" - if not ctx.invoked_subcommand: - pass + pass @ccrole.command(name="add") @checks.mod_or_permissions(administrator=True) @@ -228,7 +227,8 @@ class CCRole(commands.Cog): if not role_list: return "None" return ", ".join( - [discord.utils.get(ctx.guild.roles, id=roleid).name for roleid in role_list] + discord.utils.get(ctx.guild.roles, id=roleid).name + for roleid in role_list ) embed.add_field(name="Text", value="```{}```".format(cmd["text"]), inline=False) @@ -252,7 +252,7 @@ class CCRole(commands.Cog): ) return - cmd_list = ", ".join([ctx.prefix + c for c in sorted(cmd_list.keys())]) + cmd_list = ", ".join(ctx.prefix + c for c in sorted(cmd_list.keys())) cmd_list = "Custom commands:\n\n" + cmd_list if ( @@ -325,8 +325,8 @@ class CCRole(commands.Cog): async def eval_cc(self, cmd, message: discord.Message, ctx: commands.Context): """Does all the work""" - if cmd["proles"] and not ( - set(role.id for role in message.author.roles) & set(cmd["proles"]) + if cmd["proles"] and not {role.id for role in message.author.roles} & set( + cmd["proles"] ): log.debug(f"{message.author} missing required role to execute {ctx.invoked_with}") return # Not authorized, do nothing diff --git a/chatter/chat.py b/chatter/chat.py index 1419bbf..de0e20a 100644 --- a/chatter/chat.py +++ b/chatter/chat.py @@ -196,8 +196,7 @@ class Chatter(Cog): """ Base command for this cog. Check help for the commands list. """ - if ctx.invoked_subcommand is None: - pass + pass @checks.admin() @chatter.command(name="channel") diff --git a/coglint/coglint.py b/coglint/coglint.py index 6595980..9c4739c 100644 --- a/coglint/coglint.py +++ b/coglint/coglint.py @@ -58,11 +58,7 @@ class CogLint(Cog): future = await self.bot.loop.run_in_executor(None, lint.py_run, path, "return_std=True") - if future: - (pylint_stdout, pylint_stderr) = future - else: - (pylint_stdout, pylint_stderr) = None, None - + (pylint_stdout, pylint_stderr) = future or (None, None) # print(pylint_stderr) # print(pylint_stdout) diff --git a/conquest/conquest.py b/conquest/conquest.py index fdf5e96..fa70911 100644 --- a/conquest/conquest.py +++ b/conquest/conquest.py @@ -67,9 +67,8 @@ class Conquest(commands.Cog): """ Base command for conquest cog. Start with `[p]conquest set map` to select a map. """ - if ctx.invoked_subcommand is None: - if self.current_map is not None: - await self._conquest_current(ctx) + if ctx.invoked_subcommand is None and self.current_map is not None: + await self._conquest_current(ctx) @conquest.command(name="list") async def _conquest_list(self, ctx: commands.Context): @@ -80,14 +79,13 @@ class Conquest(commands.Cog): with maps_json.open() as maps: maps_json = json.load(maps) - map_list = "\n".join(map_name for map_name in maps_json["maps"]) + map_list = "\n".join(maps_json["maps"]) await ctx.maybe_send_embed(f"Current maps:\n{map_list}") @conquest.group(name="set") async def conquest_set(self, ctx: commands.Context): """Base command for admin actions like selecting a map""" - if ctx.invoked_subcommand is None: - pass + pass @conquest_set.command(name="resetzoom") async def _conquest_set_resetzoom(self, ctx: commands.Context): diff --git a/conquest/mapmaker.py b/conquest/mapmaker.py index 0cde96a..5fd90b2 100644 --- a/conquest/mapmaker.py +++ b/conquest/mapmaker.py @@ -30,8 +30,7 @@ class MapMaker(commands.Cog): """ Base command for managing current maps or creating new ones """ - if ctx.invoked_subcommand is None: - pass + pass @mapmaker.command(name="upload") async def _mapmaker_upload(self, ctx: commands.Context, map_path=""): diff --git a/conquest/regioner.py b/conquest/regioner.py index dc77373..b89bc5f 100644 --- a/conquest/regioner.py +++ b/conquest/regioner.py @@ -65,7 +65,7 @@ def floodfill(image, xy, value, border=None, thresh=0) -> set: if border is None: fill = _color_diff(p, background) <= thresh else: - fill = p != value and p != border + fill = p not in [value, border] if fill: pixel[s, t] = value new_edge.add((s, t)) diff --git a/exclusiverole/exclusiverole.py b/exclusiverole/exclusiverole.py index 19635b2..63b7460 100644 --- a/exclusiverole/exclusiverole.py +++ b/exclusiverole/exclusiverole.py @@ -27,8 +27,7 @@ class ExclusiveRole(Cog): async def exclusive(self, ctx): """Base command for managing exclusive roles""" - if not ctx.invoked_subcommand: - pass + pass @exclusive.command(name="add") @checks.mod_or_permissions(administrator=True) @@ -85,7 +84,7 @@ class ExclusiveRole(Cog): if role_set is None: role_set = set(await self.config.guild(member.guild).role_list()) - member_set = set([role.id for role in member.roles]) + member_set = {role.id for role in member.roles} to_remove = (member_set - role_set) - {member.guild.default_role.id} if to_remove and member_set & role_set: @@ -103,7 +102,7 @@ class ExclusiveRole(Cog): await asyncio.sleep(1) role_set = set(await self.config.guild(after.guild).role_list()) - member_set = set([role.id for role in after.roles]) + member_set = {role.id for role in after.roles} if role_set & member_set: try: diff --git a/fifo/fifo.py b/fifo/fifo.py index d152609..24d01f3 100644 --- a/fifo/fifo.py +++ b/fifo/fifo.py @@ -68,10 +68,7 @@ class CapturePrint: self.string = None def write(self, string): - if self.string is None: - self.string = string - else: - self.string = self.string + "\n" + string + self.string = string if self.string is None else self.string + "\n" + string class FIFO(commands.Cog): @@ -197,8 +194,8 @@ class FIFO(commands.Cog): async def _get_tz(self, user: Union[discord.User, discord.Member]) -> Union[None, tzinfo]: if self.tz_cog is None: self.tz_cog = self.bot.get_cog("Timezone") - if self.tz_cog is None: - self.tz_cog = False # only try once to get the timezone cog + if self.tz_cog is None: + self.tz_cog = False # only try once to get the timezone cog if not self.tz_cog: return None @@ -230,8 +227,7 @@ class FIFO(commands.Cog): """ Base command for handling scheduling of tasks """ - if ctx.invoked_subcommand is None: - pass + pass @fifo.command(name="wakeup") async def fifo_wakeup(self, ctx: commands.Context): @@ -522,8 +518,7 @@ class FIFO(commands.Cog): """ Add a new trigger for a task from the current guild. """ - if ctx.invoked_subcommand is None: - pass + pass @fifo_trigger.command(name="interval") async def fifo_trigger_interval( diff --git a/flag/flag.py b/flag/flag.py index 10f0334..e267297 100644 --- a/flag/flag.py +++ b/flag/flag.py @@ -55,8 +55,7 @@ class Flag(Cog): """ Commands for managing Flag settings """ - if ctx.invoked_subcommand is None: - pass + pass @flagset.command(name="expire") async def flagset_expire(self, ctx: commands.Context, days: int): diff --git a/hangman/hangman.py b/hangman/hangman.py index 2b6ab07..d737aea 100644 --- a/hangman/hangman.py +++ b/hangman/hangman.py @@ -147,8 +147,7 @@ class Hangman(Cog): @checks.mod_or_permissions(administrator=True) async def hangset(self, ctx): """Adjust hangman settings""" - if ctx.invoked_subcommand is None: - pass + pass @hangset.command() async def face(self, ctx: commands.Context, theface): @@ -250,7 +249,7 @@ class Hangman(Cog): self.winbool[guild] = True for i in self.the_data[guild]["answer"]: - if i == " " or i == "-": + if i in [" ", "-"]: out_str += i * 2 elif i in self.the_data[guild]["guesses"] or i not in "ABCDEFGHIJKLMNOPQRSTUVWXYZ": out_str += "__" + i + "__ " @@ -262,9 +261,7 @@ class Hangman(Cog): def _guesslist(self, guild): """Returns the current letter list""" - out_str = "" - for i in self.the_data[guild]["guesses"]: - out_str += str(i) + "," + out_str = "".join(str(i) + "," for i in self.the_data[guild]["guesses"]) out_str = out_str[:-1] return out_str diff --git a/infochannel/infochannel.py b/infochannel/infochannel.py index 33e2b10..fe8589f 100644 --- a/infochannel/infochannel.py +++ b/infochannel/infochannel.py @@ -65,9 +65,12 @@ class InfoChannel(Cog): "offline": "Offline: {count}", } - default_channel_ids = {k: None for k in self.default_channel_names.keys()} + default_channel_ids = {k: None for k in self.default_channel_names} # Only members is enabled by default - default_enabled_counts = {k: k == "members" for k in self.default_channel_names.keys()} + default_enabled_counts = { + k: k == "members" for k in self.default_channel_names + } + default_guild = { "category_id": None, @@ -159,8 +162,7 @@ class InfoChannel(Cog): """ Toggle different types of infochannels """ - if not ctx.invoked_subcommand: - pass + pass @infochannelset.command(name="togglechannel") async def _infochannelset_togglechannel( diff --git a/launchlib/launchlib.py b/launchlib/launchlib.py index 3d3eb0e..2a30c3e 100644 --- a/launchlib/launchlib.py +++ b/launchlib/launchlib.py @@ -36,58 +36,6 @@ class LaunchLib(commands.Cog): async def _embed_launch_data(self, launch: ll.AsyncLaunch): - if False: - example_launch = ll.AsyncLaunch( - id="9279744e-46b2-4eca-adea-f1379672ec81", - name="Atlas LV-3A | Samos 2", - tbddate=False, - tbdtime=False, - status={"id": 3, "name": "Success"}, - inhold=False, - windowstart="1961-01-31 20:21:19+00:00", - windowend="1961-01-31 20:21:19+00:00", - net="1961-01-31 20:21:19+00:00", - info_urls=[], - vid_urls=[], - holdreason=None, - failreason=None, - probability=0, - hashtag=None, - agency=None, - changed=None, - pad=ll.Pad( - id=93, - name="Space Launch Complex 3W", - latitude=34.644, - longitude=-120.593, - map_url="http://maps.google.com/maps?q=34.644+N,+120.593+W", - retired=None, - total_launch_count=3, - agency_id=161, - wiki_url=None, - info_url=None, - location=ll.Location( - id=11, - name="Vandenberg AFB, CA, USA", - country_code="USA", - total_launch_count=83, - total_landing_count=3, - pads=None, - ), - map_image="https://spacelaunchnow-prod-east.nyc3.digitaloceanspaces.com/media/launch_images/pad_93_20200803143225.jpg", - ), - rocket=ll.Rocket( - id=2362, - name=None, - default_pads=None, - family=None, - wiki_url=None, - info_url=None, - image_url=None, - ), - missions=None, - ) - # status: ll.AsyncLaunchStatus = await launch.get_status() status = launch.status @@ -102,11 +50,7 @@ class LaunchLib(commands.Cog): if launch.pad: urls += [launch.pad.info_url, launch.pad.wiki_url] - if urls: - url = next((url for url in urls if urls is not None), None) - else: - url = None - + url = next((url for url in urls if urls is not None), None) if urls else None color = discord.Color.green() if status["id"] in [1, 3] else discord.Color.red() em = discord.Embed(title=title, description=description, url=url, color=color) @@ -171,8 +115,7 @@ class LaunchLib(commands.Cog): @commands.group() async def launchlib(self, ctx: commands.Context): """Base command for getting launches""" - if ctx.invoked_subcommand is None: - pass + pass @launchlib.command() async def next(self, ctx: commands.Context, num_launches: int = 1): diff --git a/leaver/leaver.py b/leaver/leaver.py index 0c0d947..76f29f5 100644 --- a/leaver/leaver.py +++ b/leaver/leaver.py @@ -25,8 +25,7 @@ class Leaver(Cog): @checks.mod_or_permissions(administrator=True) async def leaverset(self, ctx): """Adjust leaver settings""" - if ctx.invoked_subcommand is None: - pass + pass @leaverset.command() async def channel(self, ctx: Context): @@ -57,5 +56,3 @@ class Leaver(Cog): ) else: await channel.send(out) - else: - pass diff --git a/lseen/lseen.py b/lseen/lseen.py index 69bcf87..2ddb0e1 100644 --- a/lseen/lseen.py +++ b/lseen/lseen.py @@ -45,14 +45,12 @@ class LastSeen(Cog): @staticmethod def get_date_time(s): - d = dateutil.parser.parse(s) - return d + return dateutil.parser.parse(s) @commands.group(aliases=["setlseen"], name="lseenset") async def lset(self, ctx: commands.Context): """Change settings for lseen""" - if ctx.invoked_subcommand is None: - pass + pass @lset.command(name="toggle") async def lset_toggle(self, ctx: commands.Context): diff --git a/planttycoon/planttycoon.py b/planttycoon/planttycoon.py index 4209b53..54d0119 100644 --- a/planttycoon/planttycoon.py +++ b/planttycoon/planttycoon.py @@ -111,9 +111,8 @@ async def _withdraw_points(gardener: Gardener, amount): if (gardener.points - amount) < 0: return False - else: - gardener.points -= amount - return True + gardener.points -= amount + return True class PlantTycoon(commands.Cog): @@ -245,13 +244,12 @@ class PlantTycoon(commands.Cog): await self._load_plants_products() modifiers = sum( - [ - self.products[product]["modifier"] - for product in gardener.products - if gardener.products[product] > 0 - ] + self.products[product]["modifier"] + for product in gardener.products + if gardener.products[product] > 0 ) + degradation = ( 100 / (gardener.current["time"] / 60) @@ -290,38 +288,33 @@ class PlantTycoon(commands.Cog): product = product.lower() product_category = product_category.lower() if product in self.products and self.products[product]["category"] == product_category: - if product in gardener.products: - if gardener.products[product] > 0: - gardener.current["health"] += self.products[product]["health"] - gardener.products[product] -= 1 - if gardener.products[product] == 0: - del gardener.products[product.lower()] - if product_category == "water": - emoji = ":sweat_drops:" - elif product_category == "fertilizer": - emoji = ":poop:" - # elif product_category == "tool": - else: - emoji = ":scissors:" - message = "Your plant got some health back! {}".format(emoji) - if gardener.current["health"] > gardener.current["threshold"]: - gardener.current["health"] -= self.products[product]["damage"] - if product_category == "tool": - damage_msg = "You used {} too many times!".format(product) - else: - damage_msg = "You gave too much of {}.".format(product) - message = "{} Your plant lost some health. :wilted_rose:".format( - damage_msg - ) - gardener.points += self.defaults["points"]["add_health"] - await gardener.save_gardener() + if product in gardener.products and gardener.products[product] > 0: + gardener.current["health"] += self.products[product]["health"] + gardener.products[product] -= 1 + if gardener.products[product] == 0: + del gardener.products[product.lower()] + if product_category == "fertilizer": + emoji = ":poop:" + elif product_category == "water": + emoji = ":sweat_drops:" else: - message = "You have no {}. Go buy some!".format(product) + emoji = ":scissors:" + message = "Your plant got some health back! {}".format(emoji) + if gardener.current["health"] > gardener.current["threshold"]: + gardener.current["health"] -= self.products[product]["damage"] + if product_category == "tool": + damage_msg = "You used {} too many times!".format(product) + else: + damage_msg = "You gave too much of {}.".format(product) + message = "{} Your plant lost some health. :wilted_rose:".format( + damage_msg + ) + gardener.points += self.defaults["points"]["add_health"] + await gardener.save_gardener() + elif product in gardener.products or product_category != "tool": + message = "You have no {}. Go buy some!".format(product) else: - if product_category == "tool": - message = "You don't have a {}. Go buy one!".format(product) - else: - message = "You have no {}. Go buy some!".format(product) + message = "You don't have a {}. Go buy one!".format(product) else: message = "Are you sure you are using {}?".format(product_category) @@ -412,24 +405,18 @@ class PlantTycoon(commands.Cog): gardener.current = plant await gardener.save_gardener() - em = discord.Embed(description=message, color=discord.Color.green()) else: plant = gardener.current message = "You're already growing {} **{}**, silly.".format( plant["article"], plant["name"] ) - em = discord.Embed(description=message, color=discord.Color.green()) - + em = discord.Embed(description=message, color=discord.Color.green()) await ctx.send(embed=em) @_gardening.command(name="profile") async def _profile(self, ctx: commands.Context, *, member: discord.Member = None): """Check your gardening profile.""" - if member is not None: - author = member - else: - author = ctx.author - + author = member if member is not None else ctx.author gardener = await self._gardener(author) try: await self._apply_degradation(gardener) @@ -440,9 +427,7 @@ class PlantTycoon(commands.Cog): avatar = author.avatar_url if author.avatar else author.default_avatar_url em.set_author(name="Gardening profile of {}".format(author.name), icon_url=avatar) em.add_field(name="**Thneeds**", value=str(gardener.points)) - if not gardener.current: - em.add_field(name="**Currently growing**", value="None") - else: + if gardener.current: em.set_thumbnail(url=gardener.current["image"]) em.add_field( name="**Currently growing**", @@ -450,16 +435,17 @@ class PlantTycoon(commands.Cog): gardener.current["name"], gardener.current["health"] ), ) + else: + em.add_field(name="**Currently growing**", value="None") if not gardener.badges: em.add_field(name="**Badges**", value="None") else: - badges = "" - for badge in gardener.badges: - badges += "{}\n".format(badge.capitalize()) + badges = "".join( + "{}\n".format(badge.capitalize()) for badge in gardener.badges + ) + em.add_field(name="**Badges**", value=badges) - if not gardener.products: - em.add_field(name="**Products**", value="None") - else: + if gardener.products: products = "" for product_name, product_data in gardener.products.items(): if self.products[product_name] is None: @@ -470,6 +456,8 @@ class PlantTycoon(commands.Cog): self.products[product_name]["modifier"], ) em.add_field(name="**Products**", value=products) + else: + em.add_field(name="**Products**", value="None") if gardener.current: degradation = await self._degradation(gardener) die_in = await _die_in(gardener, degradation) @@ -600,7 +588,6 @@ class PlantTycoon(commands.Cog): self.products[pd]["category"], ), ) - await ctx.send(embed=em) else: if amount <= 0: message = "Invalid amount! Must be greater than 1" @@ -629,7 +616,8 @@ class PlantTycoon(commands.Cog): else: message = "I don't have this product." em = discord.Embed(description=message, color=discord.Color.green()) - await ctx.send(embed=em) + + await ctx.send(embed=em) @_gardening.command(name="convert") async def _convert(self, ctx: commands.Context, amount: int): @@ -663,8 +651,7 @@ class PlantTycoon(commands.Cog): else: gardener.current = {} message = "You successfully shovelled your plant out." - if gardener.points < 0: - gardener.points = 0 + gardener.points = max(gardener.points, 0) await gardener.save_gardener() em = discord.Embed(description=message, color=discord.Color.dark_grey()) @@ -681,12 +668,12 @@ class PlantTycoon(commands.Cog): except discord.Forbidden: # Couldn't DM the degradation await ctx.send("ERROR\nYou blocked me, didn't you?") - product = "water" - product_category = "water" if not gardener.current: message = "You're currently not growing a plant." await _send_message(channel, message) else: + product = "water" + product_category = "water" await self._add_health(channel, gardener, product, product_category) @commands.command(name="fertilize") @@ -700,11 +687,11 @@ class PlantTycoon(commands.Cog): await ctx.send("ERROR\nYou blocked me, didn't you?") channel = ctx.channel product = fertilizer - product_category = "fertilizer" if not gardener.current: message = "You're currently not growing a plant." await _send_message(channel, message) else: + product_category = "fertilizer" await self._add_health(channel, gardener, product, product_category) @commands.command(name="prune") @@ -717,12 +704,12 @@ class PlantTycoon(commands.Cog): # Couldn't DM the degradation await ctx.send("ERROR\nYou blocked me, didn't you?") channel = ctx.channel - product = "pruner" - product_category = "tool" if not gardener.current: message = "You're currently not growing a plant." await _send_message(channel, message) else: + product = "pruner" + product_category = "tool" await self._add_health(channel, gardener, product, product_category) # async def check_degradation(self): diff --git a/reactrestrict/reactrestrict.py b/reactrestrict/reactrestrict.py index 79c3c1c..8329c46 100644 --- a/reactrestrict/reactrestrict.py +++ b/reactrestrict/reactrestrict.py @@ -98,9 +98,12 @@ class ReactRestrict(Cog): current_combos = await self.combo_list() to_keep = [ - c for c in current_combos if not (c.message_id == message_id and c.role_id == role.id) + c + for c in current_combos + if c.message_id != message_id or c.role_id != role.id ] + if to_keep != current_combos: await self.set_combo_list(to_keep) @@ -210,8 +213,7 @@ class ReactRestrict(Cog): """ Base command for this cog. Check help for the commands list. """ - if ctx.invoked_subcommand is None: - pass + pass @reactrestrict.command() async def add(self, ctx: commands.Context, message_id: int, *, role: discord.Role): diff --git a/rpsls/rpsls.py b/rpsls/rpsls.py index ed2e1dc..bada2c1 100644 --- a/rpsls/rpsls.py +++ b/rpsls/rpsls.py @@ -69,13 +69,12 @@ class RPSLS(Cog): def get_emote(self, choice): if choice == "rock": - emote = ":moyai:" + return ":moyai:" elif choice == "spock": - emote = ":vulcan:" + return ":vulcan:" elif choice == "paper": - emote = ":page_facing_up:" + return ":page_facing_up:" elif choice in ["scissors", "lizard"]: - emote = ":{}:".format(choice) + return ":{}:".format(choice) else: - emote = None - return emote + return None diff --git a/stealemoji/stealemoji.py b/stealemoji/stealemoji.py index 8f32d74..be9903c 100644 --- a/stealemoji/stealemoji.py +++ b/stealemoji/stealemoji.py @@ -69,8 +69,7 @@ class StealEmoji(Cog): """ Base command for this cog. Check help for the commands list. """ - if ctx.invoked_subcommand is None: - pass + pass @checks.is_owner() @stealemoji.command(name="clearemojis") @@ -268,37 +267,36 @@ class StealEmoji(Cog): break if guildbank is None: - if await self.config.autobank(): - try: - guildbank: discord.Guild = await self.bot.create_guild( - "StealEmoji Guildbank", code="S93bqTqKQ9rM" - ) - except discord.HTTPException: - await self.config.autobank.set(False) - log.exception("Unable to create guilds, disabling autobank") - return - async with self.config.guildbanks() as guildbanks: - guildbanks.append(guildbank.id) - # Track generated guilds for easier deletion - async with self.config.autobanked_guilds() as autobanked_guilds: - autobanked_guilds.append(guildbank.id) - - await asyncio.sleep(2) - - if guildbank.text_channels: - channel = guildbank.text_channels[0] - else: - # Always hits the else. - # Maybe create_guild doesn't return guild object with - # the template channel? - channel = await guildbank.create_text_channel("invite-channel") - invite = await channel.create_invite() - - await self.bot.send_to_owners(invite) - log.info(f"Guild created id {guildbank.id}. Invite: {invite}") - else: + if not await self.config.autobank(): + return + + try: + guildbank: discord.Guild = await self.bot.create_guild( + "StealEmoji Guildbank", code="S93bqTqKQ9rM" + ) + except discord.HTTPException: + await self.config.autobank.set(False) + log.exception("Unable to create guilds, disabling autobank") return + async with self.config.guildbanks() as guildbanks: + guildbanks.append(guildbank.id) + # Track generated guilds for easier deletion + async with self.config.autobanked_guilds() as autobanked_guilds: + autobanked_guilds.append(guildbank.id) + await asyncio.sleep(2) + + if guildbank.text_channels: + channel = guildbank.text_channels[0] + else: + # Always hits the else. + # Maybe create_guild doesn't return guild object with + # the template channel? + channel = await guildbank.create_text_channel("invite-channel") + invite = await channel.create_invite() + + await self.bot.send_to_owners(invite) + log.info(f"Guild created id {guildbank.id}. Invite: {invite}") # Next, have I saved this emoji before (because uploaded emoji != orignal emoji) if str(emoji.id) in await self.config.stolemoji(): diff --git a/timerole/timerole.py b/timerole/timerole.py index 714bcc8..b3fe843 100644 --- a/timerole/timerole.py +++ b/timerole/timerole.py @@ -77,8 +77,7 @@ class Timerole(Cog): @commands.guild_only() async def timerole(self, ctx): """Adjust timerole settings""" - if ctx.invoked_subcommand is None: - pass + pass @timerole.command() async def addrole( @@ -201,7 +200,7 @@ class Timerole(Cog): reapply = all_guilds[guild_id]["reapply"] role_dict = all_guilds[guild_id]["roles"] - if not any(role_data for role_data in role_dict.values()): # No roles + if not any(role_dict.values()): # No roles log.debug(f"No roles are configured for guild: {guild}") continue @@ -232,7 +231,7 @@ class Timerole(Cog): log.debug(f"{member.display_name} - Not time to check again yet") continue member: discord.Member - has_roles = set(r.id for r in member.roles) + has_roles = {r.id for r in member.roles} # Stop if they currently have or don't have the role, and mark had_role if (int(role_id) in has_roles and not role_data["remove"]) or ( diff --git a/unicode/unicode.py b/unicode/unicode.py index 4705f5d..297546b 100644 --- a/unicode/unicode.py +++ b/unicode/unicode.py @@ -19,8 +19,7 @@ class Unicode(Cog): @commands.group(name="unicode", pass_context=True) async def unicode(self, ctx): """Encode/Decode a Unicode character.""" - if ctx.invoked_subcommand is None: - pass + pass @unicode.command() async def decode(self, ctx: commands.Context, character): diff --git a/werewolf/builder.py b/werewolf/builder.py index da85b40..28098be 100644 --- a/werewolf/builder.py +++ b/werewolf/builder.py @@ -90,7 +90,7 @@ async def parse_code(code, game): if len(built) < digits: built += c - if built == "T" or built == "W" or built == "N": + if built in ["T", "W", "N"]: # Random Towns category = built built = "" @@ -116,8 +116,6 @@ async def parse_code(code, game): options = [role for role in ROLE_LIST if 10 + idx in role.category] elif category == "N": options = [role for role in ROLE_LIST if 20 + idx in role.category] - pass - if not options: raise IndexError("No Match Found") @@ -130,11 +128,8 @@ async def parse_code(code, game): async def encode(role_list, rand_roles): """Convert role list to code""" - out_code = "" - digit_sort = sorted(role for role in role_list if role < 10) - for role in digit_sort: - out_code += str(role) + out_code = "".join(str(role) for role in digit_sort) digit_sort = sorted(role for role in role_list if 10 <= role < 100) if digit_sort: diff --git a/werewolf/game.py b/werewolf/game.py index 668bf16..949381c 100644 --- a/werewolf/game.py +++ b/werewolf/game.py @@ -526,9 +526,10 @@ class Game: async def _notify(self, event_name, **kwargs): for i in range(1, 7): # action guide 1-6 (0 is no action) - tasks = [] - for event in self.listeners.get(event_name, {}).get(i, []): - tasks.append(asyncio.create_task(event(**kwargs))) + tasks = [ + asyncio.create_task(event(**kwargs)) + for event in self.listeners.get(event_name, {}).get(i, []) + ] # Run same-priority task simultaneously await asyncio.gather(*tasks) @@ -555,10 +556,7 @@ class Game: async def generate_targets(self, channel, with_roles=False): embed = discord.Embed(title="Remaining Players", description="[ID] - [Name]") for i, player in enumerate(self.players): - if player.alive: - status = "" - else: - status = "*[Dead]*-" + status = "" if player.alive else "*[Dead]*-" if with_roles or not player.alive: embed.add_field( name=f"{i} - {status}{player.member.display_name}", @@ -579,7 +577,7 @@ class Game: if channel_id not in self.p_channels: self.p_channels[channel_id] = self.default_secret_channel.copy() - for x in range(10): # Retry 10 times + for _ in range(10): # Retry 10 times try: await asyncio.sleep(1) # This will have multiple calls self.p_channels[channel_id]["players"].append(role.player) @@ -706,9 +704,7 @@ class Game: if not self.any_votes_remaining: await channel.send("Voting is not allowed right now") return - elif channel.name in self.p_channels: - pass - else: + elif channel.name not in self.p_channels: # Not part of the game await channel.send("Cannot vote in this channel") return @@ -757,14 +753,14 @@ class Game: await self._at_voted(target) async def eval_results(self, target, source=None, method=None): - if method is not None: - out = "**{ID}** - " + method - return out.format(ID=target.id, target=target.member.display_name) - else: + if method is None: return "**{ID}** - {target} the {role} was found dead".format( ID=target.id, target=target.member.display_name, role=await target.role.get_role() ) + out = "**{ID}** - " + method + return out.format(ID=target.id, target=target.member.display_name) + async def _quit(self, player): """ Have player quit the game diff --git a/werewolf/werewolf.py b/werewolf/werewolf.py index a4083a9..903bb54 100644 --- a/werewolf/werewolf.py +++ b/werewolf/werewolf.py @@ -75,8 +75,7 @@ class Werewolf(Cog): """ Base command to adjust settings. Check help for command list. """ - if ctx.invoked_subcommand is None: - pass + pass @commands.guild_only() @wwset.command(name="list") @@ -166,8 +165,7 @@ class Werewolf(Cog): """ Base command for this cog. Check help for the commands list. """ - if ctx.invoked_subcommand is None: - pass + pass @commands.guild_only() @ww.command(name="new") @@ -348,8 +346,7 @@ class Werewolf(Cog): """ Find custom roles by name, alignment, category, or ID """ - if ctx.invoked_subcommand is None or ctx.invoked_subcommand == self.ww_search: - pass + pass @ww_search.command(name="name") async def ww_search_name(self, ctx: commands.Context, *, name):