Skip to content

Commit 5c326f1

Browse files
committed
Replace existing nick parsing regexes with calls to is_nick_valid()
1 parent 9bfdbca commit 5c326f1

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

plugins/core/core_tracker.py

Lines changed: 3 additions & 7 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

@@ -36,7 +33,6 @@ def on_kick(conn, chan, target, loop):
3633
"""
3734
:type conn: cloudbot.client.Client
3835
:type chan: str
39-
:type nick: str
4036
"""
4137
# if the bot has been kicked, remove from the channel list
4238
if target == conn.nick:
@@ -49,13 +45,13 @@ def on_kick(conn, chan, target, loop):
4945

5046
@asyncio.coroutine
5147
@hook.irc_raw("NICK")
52-
def on_nick(irc_paramlist, conn, irc_raw):
48+
def on_nick(irc_paramlist, conn, nick):
5349
"""
5450
:type irc_paramlist: list[str]
5551
:type conn: cloudbot.client.Client
56-
:type irc_raw: str
52+
:type nick: str
5753
"""
58-
old_nick = nick_re.search(irc_raw).group(1)
54+
old_nick = nick
5955
new_nick = str(irc_paramlist[0])
6056

6157
# get rid of :

plugins/history.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from collections import deque
2-
import time
31
import asyncio
42
import re
3+
import time
4+
from collections import deque
55

66
from sqlalchemy import Table, Column, String, PrimaryKeyConstraint
77

88
from cloudbot import hook
9-
from cloudbot.util import timeformat, database
109
from cloudbot.event import EventType
10+
from cloudbot.util import timeformat, database
1111

1212
table = Table(
1313
'seen_user',
@@ -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
@@ -96,14 +96,14 @@ def seen(text, nick, chan, db, event):
9696
if text.lower() == nick.lower():
9797
return "Have you looked in a mirror lately?"
9898

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

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

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

108108
text = text.replace("/", "")
109109

0 commit comments

Comments
 (0)