utils.msg

 1import re
 2
 3
 4def clean_message(msg):
 5    """
 6    Function to clean the input discord message and return a lowercase ascii string
 7    :return: processed string
 8    """
 9    # Step 1: Remove non-english words in the text
10    pattern = r'[^\x00-\x7f]'
11    ret = ''
12    for _, element in enumerate(msg):
13        if not re.search(pattern, element):
14            ret += element
15    # Step 2: convert everything to lowercase
16    return ret.lower()
17
18
19def get_msg_template(user_id, reason, warning=False):
20    """
21    Utility Function to generate output Message Template
22    :return: message template
23    """
24    #reason_dict = {"profane": "using profane words"}
25    ret = ""
26    reason_str = ",".join(reason) if isinstance(reason, list) else str(reason)
27    if warning:
28        ret = """ Warning user:<@{0}> for {1}.\n Another attempt will result in a Ban!""".format(user_id, reason_str)
29    else:
30        ret = """ User:<@{0}> has been banned for {1}.""".format(user_id, reason_str)
31    return ret
32
33
34def get_help_message():
35    """
36    Utility Function to generate help options
37    :return: message template
38    """
39    return """
40                Inorder to report a word as profane use the command:
41                !report profane <word>
42           """
def clean_message(msg):
 5def clean_message(msg):
 6    """
 7    Function to clean the input discord message and return a lowercase ascii string
 8    :return: processed string
 9    """
10    # Step 1: Remove non-english words in the text
11    pattern = r'[^\x00-\x7f]'
12    ret = ''
13    for _, element in enumerate(msg):
14        if not re.search(pattern, element):
15            ret += element
16    # Step 2: convert everything to lowercase
17    return ret.lower()

Function to clean the input discord message and return a lowercase ascii string

Returns

processed string

def get_msg_template(user_id, reason, warning=False):
20def get_msg_template(user_id, reason, warning=False):
21    """
22    Utility Function to generate output Message Template
23    :return: message template
24    """
25    #reason_dict = {"profane": "using profane words"}
26    ret = ""
27    reason_str = ",".join(reason) if isinstance(reason, list) else str(reason)
28    if warning:
29        ret = """ Warning user:<@{0}> for {1}.\n Another attempt will result in a Ban!""".format(user_id, reason_str)
30    else:
31        ret = """ User:<@{0}> has been banned for {1}.""".format(user_id, reason_str)
32    return ret

Utility Function to generate output Message Template

Returns

message template

def get_help_message():
35def get_help_message():
36    """
37    Utility Function to generate help options
38    :return: message template
39    """
40    return """
41                Inorder to report a word as profane use the command:
42                !report profane <word>
43           """

Utility Function to generate help options

Returns

message template