Conditions | 9 |
Total Lines | 56 |
Code Lines | 26 |
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 | """Deals with long message sending""" |
||
13 | |||
14 | **Asynchronous Function** |
||
15 | |||
16 | |||
17 | Log **message** to the admin channels. |
||
18 | |||
19 | :param bot: Discord bot |
||
20 | :type bot: discord.ext.commands.Bot |
||
21 | :param message: Message to log |
||
22 | :type message: str |
||
23 | :param log_status: Will be sent to logging channels (true) |
||
24 | or non logging channels including debug |
||
25 | :type log_status: bool |
||
26 | |||
27 | """ |
||
28 | if len(message) > 2000: |
||
29 | log.warning("Log message length too long, it will not be sent. Length: %s", len(message)) |
||
30 | |||
31 | channels = await select("admin_channels", "id", "log", log_status) |
||
32 | for channel in channels: |
||
33 | to_send = bot.get_channel(channel) |
||
34 | if to_send is None: |
||
35 | log.warning(f"No channel found for id {channel}") |
||
36 | else: |
||
37 | embed = discord.Embed( |
||
38 | title="Log Update:", |
||
39 | description=message, |
||
40 | color=discord.Color(int("FF0000", 16)), |
||
41 | ) |
||
42 | await to_send.send(embed=embed) |
||
43 | return None |
||
44 |