Passed
Pull Request — master (#125)
by Cyb3r
01:16
created

bot.utils.messages.list_message()   C

Complexity

Conditions 9

Size

Total Lines 56
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 26
nop 4
dl 0
loc 56
rs 6.6666
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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:

1
"""Deals with long message sending"""
2
import logging
3
4
import discord
5
from discord.ext import commands
6
from .datahandler import select
7
8
log = logging.getLogger("bot")
9
10
11
async def admin_log(bot: commands.Bot, message: str, log_status: bool = True) -> None:
12
    """Admin Log
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