Message   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
dl 0
loc 12
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 10 1
1
#    Copyright 2017 Starbot Discord Project
2
#
3
#    Licensed under the Apache License, Version 2.0 (the "License");
4
#    you may not use this file except in compliance with the License.
5
#    You may obtain a copy of the License at
6
#
7
#        http://www.apache.org/licenses/LICENSE-2.0
8
#
9
#    Unless required by applicable law or agreed to in writing, software
10
#    distributed under the License is distributed on an "AS IS" BASIS,
11
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
#    See the License for the specific language governing permissions and
13
#    limitations under the License.
14
'''Message class and message splitting'''
15
import textwrap
16
17
class Message:
18
    '''Store data about a message.'''
19
    def __init__(self, body='', file='', embed=None, delete=False, mentions=None, channel=None):
20
        self.command = None
21
        self.author = None
22
        self.server = None
23
        self.body = body
24
        self.file = file
25
        self.embed = embed
26
        self.delete = delete
27
        self.mentions = mentions
28
        self.channel = channel
29
30
# Breaks giant message into chunks.
31
def msg_split(msg, characters: int = 2000):
32
    '''Split a big message into several smaller ones'''
33
    if not msg:
34
        return None
35
36
    # Create message list.
37
    text_list = textwrap.wrap(msg, characters, break_long_words=True, replace_whitespace=False)
38
    if not text_list:
39
        return None
40
41
    # Create message list objects.
42
    msg_list = []
43
    for msg in text_list:
44
        msg_list.append(Message(msg))
45
46
    # Return the list.
47
    return msg_list
48