-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathparseUtil.py
More file actions
58 lines (45 loc) · 1.48 KB
/
parseUtil.py
File metadata and controls
58 lines (45 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import re
emoteRegex = [
# Emotes starting with underscores, retrieve group 2
re.compile(r"^(_{1,2}\*{0,3}([^_*]*)\*{0,3}_{1,2})$"),
# Emotes starting with asterisks, retrieve group 2
re.compile(r"^(\*{1}|\*{3})_{0,2}([^_*]*)_{0,2}(\*{1}|\*{3})$"),
]
def convertEmote(msgIn):
if emoteRegex[0].match(msgIn):
# Emote starts with underscore
msgOut = "_" + emoteRegex[0].match(msgIn).group(2) + "_"
elif emoteRegex[1].match(msgIn):
# Emote starts with asterisk
msgOut = "_" + emoteRegex[1].match(msgIn).group(2) + "_"
elif msgIn.startswith("/me "):
msgOut = "_" + msgIn[4:] + "_"
else:
# Ain't no emote
msgOut = msgIn
return msgOut
def escapeFormatting(msgIn):
# Escape things like :
# bold (*), italics (_), spoilers (|), strikethrough (~), quote (>), and code (`)
msgOut = (
msgIn.replace("_", r"\_")
.replace("*", r"\*")
.replace("|", r"\|")
.replace("~", r"\~")
.replace(">", r"\>")
.replace("`", r"\`")
)
return msgOut
def mentionToSelfVar(msgIn, botRole, botID):
msgOut = msgIn
# Nick ping
nick = "<@" + str(botID) + ">"
msgOut = msgOut.replace("!", "").replace(nick, "$self")
# Role ping
role = "<@&" + str(botRole) + ">"
msgOut = msgOut.replace(role, "$self")
return msgOut
def selfVarToMention(msgIn, botID):
nick = "<@" + str(botID) + ">"
msgOut = msgIn.replace("$self", nick)
return msgOut