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 |
||
115 | @cog_ext.cog_slash(name="mySpottingStats", guild_ids=cogbase.GUILD_IDS, |
||
116 | description=" ", |
||
117 | default_permission=True, |
||
118 | permissions=cogbase.PERMISSION_MODS |
||
119 | ) |
||
120 | async def get_spotting_stats(self, ctx): |
||
121 | await ctx.send("Generating spots stats", delete_after=5) |
||
122 | |||
123 | # Legendary |
||
124 | leges_list, leges_total = await self.create_spots_list(1) |
||
125 | leges_print = ['\n'.join([elem for elem in sublist]) for sublist in leges_list] |
||
126 | leges_print = "\n".join(leges_print) |
||
127 | |||
128 | leges_color = int(self.hex_to_int % (163, 140, 21), 16) |
||
129 | embed_command = discord.Embed(title=f"Legendary", description=leges_print, color=leges_color) |
||
130 | embed_command.add_field(name="Total", value=f"**{leges_total}**", inline=False) |
||
131 | if self.lege_total != 0: |
||
132 | percentage_leges = round(leges_total / self.lege_total * 100, 2) |
||
133 | embed_command.add_field(name="Server %", value=f"**{percentage_leges}%**", inline=False) |
||
134 | dt_string = self.bot.get_current_time() |
||
135 | embed_command.set_footer(text=f"{dt_string}") |
||
136 | await ctx.author.send(embed=embed_command) |
||
137 | |||
138 | # Rare |
||
139 | rares_list, rares_total = await self.create_spots_list(0) |
||
140 | rares_print = ['\n'.join([elem for elem in sublist]) for sublist in rares_list] |
||
141 | rares_print = "\n".join(rares_print) |
||
142 | |||
143 | rares_color = int(self.hex_to_int % (17, 93, 178), 16) |
||
144 | embed_command = discord.Embed(title=f"Rare", description=rares_print, color=rares_color) |
||
145 | embed_command.add_field(name="Total", value=f"**{rares_total}**", inline=False) |
||
146 | if self.rare_total != 0: |
||
147 | percentage_rares = round(rares_total / self.rare_total * 100, 2) |
||
148 | embed_command.add_field(name="Server %", value=f"**{percentage_rares}%**", inline=False) |
||
149 | dt_string = self.bot.get_current_time() |
||
150 | embed_command.set_footer(text=f"{dt_string}") |
||
151 | await ctx.author.send(embed=embed_command) |
||
152 | |||
153 | # Common |
||
154 | common_ch = self.bot.get_channel(self.bot.ch_common) |
||
155 | common_total = 0 |
||
156 | async for message in common_ch.history(limit=None, oldest_first=True): |
||
157 | self.common_total += 1 |
||
158 | if ctx.author == message.author: |
||
159 | common_total += 1 |
||
160 | embed_command = discord.Embed(title=f"Common") |
||
161 | embed_command.add_field(name="Total", value=f"**{common_total}**", inline=False) |
||
162 | if self.common_total != 0: |
||
163 | percentage_common = round(common_total / self.common_total * 100, 2) |
||
164 | embed_command.add_field(name="Server %", value=f"**{percentage_common}%**", inline=False) |
||
165 | dt_string = self.bot.get_current_time() |
||
166 | embed_command.set_footer(text=f"{dt_string}") |
||
167 | await ctx.author.send(embed=embed_command) |
||
168 | self.create_log_msg(f"Spotting stats created for {ctx.author}") |
||
169 | |||
173 |