| Total Complexity | 5 | 
| Total Lines | 48 | 
| Duplicated Lines | 0 % | 
| Changes | 0 | ||
| 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.guild = 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 |