Skip to content

Escape IRC nick to prevent self-pinging #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion discordc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from asyncio import coroutines
import concurrent.futures
from asyncio import futures
from text_util import toMathSans

logging.basicConfig(level=logging.INFO)

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

irc.send_my_message("%s: %s" % (message.author.name, content))
# Note(jpc) for nick escaping
authorName = toMathSans(message.author.name)
irc.send_my_message("%s: %s" % (authorName, content))


@client.event
async def on_ready():
Expand Down
12 changes: 12 additions & 0 deletions text_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def toMathSans(text):
# convert alphabetic characters to Math Sans, for nick escaping
result = ''
for c in text:
o = ord(c)
if o >= 0x0061 and o <= 0x007a:
result += chr(o - 0x0061 + 0x1d5ba)
elif o >= 0x0041 and o <= 0x005a:
result += chr(o - 0x0041 + 0x1d5a0)
else:
result += c
return result