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

bot.utils.messages.error_message()   A

Complexity

Conditions 1

Size

Total Lines 14
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 4
dl 0
loc 14
rs 10
c 0
b 0
f 0
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