Skip to content
This repository has been archived by the owner on Oct 23, 2019. It is now read-only.

Commit

Permalink
Merge pull request #84 from linuxdaemon/gonzobot+tell-fix
Browse files Browse the repository at this point in the history
Fix issues in tell plugin
  • Loading branch information
edwardslabs authored Nov 26, 2017
2 parents 1439829 + 5658df5 commit c2bbbe1
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions plugins/tell.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import re
from datetime import datetime
from sqlalchemy import Table, Column, String, Boolean, DateTime

from sqlalchemy import Table, Column, String, Boolean, DateTime
from sqlalchemy.sql import select

from cloudbot import hook
from cloudbot.util import timeformat, database
from cloudbot.event import EventType
from cloudbot.util import timeformat, database

table = Table(
'tells',
Expand All @@ -20,6 +19,7 @@
Column('time_read', DateTime)
)


@hook.on_start
def load_cache(db):
"""
Expand Down Expand Up @@ -62,6 +62,7 @@ def read_all_tells(db, server, target):
db.commit()
load_cache(db)


def read_tell(db, server, target, message):
query = table.update() \
.where(table.c.connection == server.lower()) \
Expand All @@ -86,13 +87,15 @@ def add_tell(db, server, sender, target, message):
db.commit()
load_cache(db)


def tell_check(conn, nick):
for _conn, _target in tell_cache:
if (conn, nick.lower()) == (_conn, _target):
return True
else:
continue


@hook.event(EventType.message, singlethread=True)
def tellinput(event, conn, db, nick, notice):
"""
Expand Down Expand Up @@ -127,7 +130,7 @@ def tellinput(event, conn, db, nick, notice):

@hook.command(autohelp=False)
def showtells(nick, notice, db, conn):
"""showtells -- View all pending tell messages (sent in a notice)."""
"""- View all pending tell messages (sent in a notice)."""

tells = get_unread(db, conn.name, nick)

Expand All @@ -144,14 +147,13 @@ def showtells(nick, notice, db, conn):


@hook.command("tell")
def tell_cmd(text, nick, db, notice, conn):
"""tell <nick> <message> -- Relay <message> to <nick> when <nick> is around."""
def tell_cmd(text, nick, db, notice, conn, notice_doc, is_nick_valid):
"""<nick> <message> - Relay <message> to <nick> when <nick> is around."""
query = text.split(' ', 1)
if query[0].lower() == "paradox":
return "Paradox doesn't want to hear from me. Just send him a fucking message."
if len(query) != 2:
prefix = conn.config("command_prefix")
notice(prefix[0] + tell_cmd.__doc__)
notice_doc()
return

target = query[0]
Expand All @@ -162,12 +164,7 @@ def tell_cmd(text, nick, db, notice, conn):
notice("Have you looked in a mirror lately?")
return

if target.lower() == conn.nick.lower():
# we can't send messages to ourselves
notice("Invalid nick '{}'.".format(target))
return

if not re.match("^[a-z0-9_|.\-\`\]\[]*$", target.lower()):
if not is_nick_valid(target.lower()) or target.lower() == conn.nick.lower():
notice("Invalid nick '{}'.".format(target))
return

Expand Down

0 comments on commit c2bbbe1

Please sign in to comment.