Skip to content

Commit 676fcb5

Browse files
committed
Escape IRC nick to prevent self-pinging
1 parent 35e6450 commit 676fcb5

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

discordc.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from asyncio import coroutines
55
import concurrent.futures
66
from asyncio import futures
7+
from text_util import toMathSans
78

89
logging.basicConfig(level=logging.INFO)
910

@@ -81,7 +82,10 @@ async def on_message(message):
8182
if len(message.attachments) > 0:
8283
content += ' ' + message.attachments[0].url
8384

84-
irc.send_my_message("%s: %s" % (message.author.name, content))
85+
# Note(jpc) for nick escaping
86+
authorName = toMathSans(message.author.name)
87+
irc.send_my_message("%s: %s" % (authorName, content))
88+
8589

8690
@client.event
8791
async def on_ready():

text_util.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def toMathSans(text):
2+
# convert alphabetic characters to Math Sans, for nick escaping
3+
result = ''
4+
for c in text:
5+
o = ord(c)
6+
if o >= 0x0061 and o <= 0x007a:
7+
result += chr(o - 0x0061 + 0x1d5ba)
8+
elif o >= 0x0041 and o <= 0x005a:
9+
result += chr(o - 0x0041 + 0x1d5a0)
10+
else:
11+
result += c
12+
return result

0 commit comments

Comments
 (0)