Skip to content

Commit 6595c14

Browse files
authored
Merge pull request CloudBotIRC#140 from linuxdaemon/gonzobot+nick-re-checks
Replace existing nick parsing regexes with calls to is_nick_valid()
2 parents a926189 + 9d47b1a commit 6595c14

2 files changed

Lines changed: 6 additions & 9 deletions

File tree

plugins/core/core_tracker.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22

33
import asyncio
44
import logging
5-
import re
65
from collections import deque
76

87
from cloudbot import hook
98

109
logger = logging.getLogger("cloudbot")
1110

12-
nick_re = re.compile(":(.+?)!")
13-
1411

1512
# functions called for bot state tracking
1613

@@ -48,13 +45,13 @@ def on_kick(conn, chan, target, loop):
4845

4946
@asyncio.coroutine
5047
@hook.irc_raw("NICK")
51-
def on_nick(irc_paramlist, conn, irc_raw):
48+
def on_nick(irc_paramlist, conn, nick):
5249
"""
5350
:type irc_paramlist: list[str]
5451
:type conn: cloudbot.client.Client
55-
:type irc_raw: str
52+
:type nick: str
5653
"""
57-
old_nick = nick_re.search(irc_raw).group(1)
54+
old_nick = nick
5855
new_nick = str(irc_paramlist[0])
5956

6057
# get rid of :

plugins/history.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def resethistory(event, conn):
8383

8484

8585
@hook.command()
86-
def seen(text, nick, chan, db, event):
86+
def seen(text, nick, chan, db, event, is_valid_nick):
8787
"""<nick> <channel> - tells when a nickname was last in active in one of my channels
8888
:type db: sqlalchemy.orm.Session
8989
:type event: cloudbot.event.Event
@@ -95,13 +95,13 @@ def seen(text, nick, chan, db, event):
9595
if text.lower() == nick.lower():
9696
return "Have you looked in a mirror lately?"
9797

98-
if not re.match("^[A-Za-z0-9_|^*`.\-\]\[{\}\\\\]*$", text.lower()):
98+
if not is_valid_nick(text):
9999
return "I can't look up that name, its impossible to use!"
100100

101101
if '_' in text:
102102
text = text.replace("_", "/_")
103103

104-
last_seen = db.execute("select name, time, quote from seen_user where name like :name escape '/' and chan = :chan",
104+
last_seen = db.execute("SELECT name, time, quote FROM seen_user WHERE name LIKE :name ESCAPE '/' AND chan = :chan",
105105
{'name': text, 'chan': chan}).fetchone()
106106

107107
text = text.replace("/", "")

0 commit comments

Comments
 (0)