1- import re
21from datetime import datetime
3- from sqlalchemy import Table , Column , String , Boolean , DateTime
42
3+ from sqlalchemy import Table , Column , String , Boolean , DateTime
54from sqlalchemy .sql import select
65
76from cloudbot import hook
8- from cloudbot .util import timeformat , database
97from cloudbot .event import EventType
8+ from cloudbot .util import timeformat , database
109
1110table = Table (
1211 'tells' ,
2019 Column ('time_read' , DateTime )
2120)
2221
22+
2323@hook .on_start
2424def load_cache (db ):
2525 """
@@ -62,6 +62,7 @@ def read_all_tells(db, server, target):
6262 db .commit ()
6363 load_cache (db )
6464
65+
6566def read_tell (db , server , target , message ):
6667 query = table .update () \
6768 .where (table .c .connection == server .lower ()) \
@@ -86,13 +87,15 @@ def add_tell(db, server, sender, target, message):
8687 db .commit ()
8788 load_cache (db )
8889
90+
8991def tell_check (conn , nick ):
9092 for _conn , _target in tell_cache :
9193 if (conn , nick .lower ()) == (_conn , _target ):
9294 return True
9395 else :
9496 continue
9597
98+
9699@hook .event (EventType .message , singlethread = True )
97100def tellinput (event , conn , db , nick , notice ):
98101 """
@@ -127,7 +130,7 @@ def tellinput(event, conn, db, nick, notice):
127130
128131@hook .command (autohelp = False )
129132def showtells (nick , notice , db , conn ):
130- """showtells - - View all pending tell messages (sent in a notice)."""
133+ """- View all pending tell messages (sent in a notice)."""
131134
132135 tells = get_unread (db , conn .name , nick )
133136
@@ -144,14 +147,13 @@ def showtells(nick, notice, db, conn):
144147
145148
146149@hook .command ("tell" )
147- def tell_cmd (text , nick , db , notice , conn ):
148- """tell <nick> <message> - - Relay <message> to <nick> when <nick> is around."""
150+ def tell_cmd (text , nick , db , notice , conn , notice_doc , is_nick_valid ):
151+ """<nick> <message> - Relay <message> to <nick> when <nick> is around."""
149152 query = text .split (' ' , 1 )
150153 if query [0 ].lower () == "paradox" :
151154 return "Paradox doesn't want to hear from me. Just send him a fucking message."
152155 if len (query ) != 2 :
153- prefix = conn .config ("command_prefix" )
154- notice (prefix [0 ] + tell_cmd .__doc__ )
156+ notice_doc ()
155157 return
156158
157159 target = query [0 ]
@@ -162,12 +164,7 @@ def tell_cmd(text, nick, db, notice, conn):
162164 notice ("Have you looked in a mirror lately?" )
163165 return
164166
165- if target .lower () == conn .nick .lower ():
166- # we can't send messages to ourselves
167- notice ("Invalid nick '{}'." .format (target ))
168- return
169-
170- if not re .match ("^[a-z0-9_|.\-\`\]\[]*$" , target .lower ()):
167+ if not is_nick_valid (target .lower ()) or target .lower () == conn .nick .lower ():
171168 notice ("Invalid nick '{}'." .format (target ))
172169 return
173170
0 commit comments