Conditions | 6 |
Total Lines | 54 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | import discord |
||
113 | @cog_ext.cog_slash(name="mySpottingStats", guild_ids=cogbase.GUILD_IDS, |
||
114 | description="Get detailed spotting stats to your dm", |
||
115 | default_permission=True, |
||
116 | permissions=cogbase.PERMISSION_MODS |
||
117 | ) |
||
118 | async def get_spotting_stats(self, ctx: SlashContext) -> None: |
||
119 | await ctx.send("Generating spots stats", delete_after=5) |
||
120 | |||
121 | # Legendary |
||
122 | leges_list, leges_total = await self.create_spots_list(ctx.author.id, 1) |
||
123 | leges_print = ['\n'.join([elem for elem in sublist]) for sublist in leges_list] |
||
124 | leges_print = "\n".join(leges_print) |
||
125 | |||
126 | leges_color = int(self.hex_to_int % (163, 140, 21), 16) |
||
127 | embed_command = discord.Embed(title=f"Legendary", description=leges_print, color=leges_color) |
||
128 | embed_command.add_field(name="Total", value=f"**{leges_total}**", inline=False) |
||
129 | if self.lege_total != 0: |
||
130 | percentage_leges = round(leges_total / self.lege_total * 100, 2) |
||
131 | embed_command.add_field(name="Server %", value=f"**{percentage_leges}%**", inline=False) |
||
132 | dt_string = self.bot.get_current_time() |
||
133 | embed_command.set_footer(text=f"{dt_string}") |
||
134 | await ctx.author.send(embed=embed_command) |
||
135 | |||
136 | # Rare |
||
137 | rares_list, rares_total = await self.create_spots_list(ctx.author.id, 0) |
||
138 | rares_print = ['\n'.join([elem for elem in sublist]) for sublist in rares_list] |
||
139 | rares_print = "\n".join(rares_print) |
||
140 | |||
141 | rares_color = int(self.hex_to_int % (17, 93, 178), 16) |
||
142 | embed_command = discord.Embed(title=f"Rare", description=rares_print, color=rares_color) |
||
143 | embed_command.add_field(name="Total", value=f"**{rares_total}**", inline=False) |
||
144 | if self.rare_total != 0: |
||
145 | percentage_rares = round(rares_total / self.rare_total * 100, 2) |
||
146 | embed_command.add_field(name="Server %", value=f"**{percentage_rares}%**", inline=False) |
||
147 | dt_string = self.bot.get_current_time() |
||
148 | embed_command.set_footer(text=f"{dt_string}") |
||
149 | await ctx.author.send(embed=embed_command) |
||
150 | |||
151 | # Common |
||
152 | common_ch = self.bot.get_channel(self.bot.ch_common) |
||
153 | common_total = 0 |
||
154 | async for message in common_ch.history(limit=None, oldest_first=True): |
||
155 | self.common_total += 1 |
||
156 | if ctx.author == message.author: |
||
157 | common_total += 1 |
||
158 | embed_command = discord.Embed(title=f"Common") |
||
159 | embed_command.add_field(name="Total", value=f"**{common_total}**", inline=False) |
||
160 | if self.common_total != 0: |
||
161 | percentage_common = round(common_total / self.common_total * 100, 2) |
||
162 | embed_command.add_field(name="Server %", value=f"**{percentage_common}%**", inline=False) |
||
163 | dt_string = self.bot.get_current_time() |
||
164 | embed_command.set_footer(text=f"{dt_string}") |
||
165 | await ctx.author.send(embed=embed_command) |
||
166 | self.create_log_msg(f"Spotting stats created for {ctx.author}") |
||
167 | |||
171 |