Update tell.py to support multiple connections
This commit is contained in:
parent
21d06ae4f0
commit
7cf3d88c96
1 changed files with 13 additions and 14 deletions
|
@ -6,19 +6,18 @@ import re
|
||||||
|
|
||||||
from util import hook, timesince
|
from util import hook, timesince
|
||||||
|
|
||||||
db_ready = False
|
db_ready = []
|
||||||
|
|
||||||
def db_init(db):
|
|
||||||
"""check to see that our db has the tell table and return a dbection."""
|
def db_init(db, conn):
|
||||||
|
"""Check that our db has the tell table, create it if not."""
|
||||||
global db_ready
|
global db_ready
|
||||||
if not db_ready:
|
if not conn.name in db_ready:
|
||||||
db.execute("create table if not exists tell"
|
db.execute("create table if not exists tell"
|
||||||
"(user_to, user_from, message, chan, time,"
|
"(user_to, user_from, message, chan, time,"
|
||||||
"primary key(user_to, message))")
|
"primary key(user_to, message))")
|
||||||
db.commit()
|
db.commit()
|
||||||
db_ready = True
|
db_ready.append(conn.name)
|
||||||
|
|
||||||
return db
|
|
||||||
|
|
||||||
|
|
||||||
def get_tells(db, user_to):
|
def get_tells(db, user_to):
|
||||||
|
@ -29,11 +28,11 @@ def get_tells(db, user_to):
|
||||||
|
|
||||||
@hook.singlethread
|
@hook.singlethread
|
||||||
@hook.event('PRIVMSG')
|
@hook.event('PRIVMSG')
|
||||||
def tellinput(paraml, input=None, notice=None, db=None, bot=None, nick=None, conn=None):
|
def tellinput(inp, input=None, notice=None, db=None, nick=None, conn=None):
|
||||||
if 'showtells' in input.msg.lower():
|
if 'showtells' in input.msg.lower():
|
||||||
return
|
return
|
||||||
|
|
||||||
db_init(db)
|
db_init(db, conn)
|
||||||
|
|
||||||
tells = get_tells(db, nick)
|
tells = get_tells(db, nick)
|
||||||
|
|
||||||
|
@ -53,10 +52,10 @@ def tellinput(paraml, input=None, notice=None, db=None, bot=None, nick=None, con
|
||||||
|
|
||||||
|
|
||||||
@hook.command(autohelp=False)
|
@hook.command(autohelp=False)
|
||||||
def showtells(inp, nick='', chan='', notice=None, db=None):
|
def showtells(inp, nick='', chan='', notice=None, db=None, conn=None):
|
||||||
"""showtells -- View all pending tell messages (sent in a notice)."""
|
"""showtells -- View all pending tell messages (sent in a notice)."""
|
||||||
|
|
||||||
db_init(db)
|
db_init(db, conn)
|
||||||
|
|
||||||
tells = get_tells(db, nick)
|
tells = get_tells(db, nick)
|
||||||
|
|
||||||
|
@ -75,7 +74,7 @@ def showtells(inp, nick='', chan='', notice=None, db=None):
|
||||||
|
|
||||||
|
|
||||||
@hook.command
|
@hook.command
|
||||||
def tell(inp, nick='', chan='', db=None, input=None, notice=None):
|
def tell(inp, nick='', chan='', db=None, input=None, notice=None, conn=None):
|
||||||
"""tell <nick> <message> -- Relay <message> to <nick> when <nick> is around."""
|
"""tell <nick> <message> -- Relay <message> to <nick> when <nick> is around."""
|
||||||
query = inp.split(' ', 1)
|
query = inp.split(' ', 1)
|
||||||
|
|
||||||
|
@ -100,10 +99,10 @@ def tell(inp, nick='', chan='', db=None, input=None, notice=None):
|
||||||
return
|
return
|
||||||
|
|
||||||
if not re.match("^[A-Za-z0-9_|.\-\]\[]*$", user_to.lower()):
|
if not re.match("^[A-Za-z0-9_|.\-\]\[]*$", user_to.lower()):
|
||||||
notice("I cant send a message to that user!")
|
notice("I can't send a message to that user!")
|
||||||
return
|
return
|
||||||
|
|
||||||
db_init(db)
|
db_init(db, conn)
|
||||||
|
|
||||||
if db.execute("select count() from tell where user_to=?",
|
if db.execute("select count() from tell where user_to=?",
|
||||||
(user_to,)).fetchone()[0] >= 10:
|
(user_to,)).fetchone()[0] >= 10:
|
||||||
|
|
Reference in a new issue