Remove notice if using a role command you don't have access to.

This commit is contained in:
Vgr E.Barry 2015-01-02 20:40:15 -05:00
parent 0984f79bd9
commit 41089786d8
3 changed files with 26 additions and 33 deletions

View File

@ -43,9 +43,6 @@ BOLD = "\u0002"
COMMANDS = {} COMMANDS = {}
HOOKS = {} HOOKS = {}
pm = var.pm
is_user_notice = var.is_user_notice
is_fake_nick = var.is_fake_nick
is_admin = var.is_admin is_admin = var.is_admin
is_owner = var.is_owner is_owner = var.is_owner
@ -279,6 +276,21 @@ def mass_mode(cli, md):
arg2 = " ".join(z[1]) # + " " + " ".join([x+"!*@*" for x in z[1]]) arg2 = " ".join(z[1]) # + " " + " ".join([x+"!*@*" for x in z[1]])
cli.mode(botconfig.CHANNEL, arg1, arg2) cli.mode(botconfig.CHANNEL, arg1, arg2)
def pm(cli, target, message): # message either privmsg or notice, depending on user settings
if is_fake_nick(target) and botconfig.DEBUG_MODE:
print("[{0}] Would send message to fake nick {1}: {2}".format(
time.strftime("%d/%b/%Y %H:%M:%S"),
target,
message), file=sys.stderr)
return
if is_user_notice(target):
cli.notice(target, message)
return
cli.msg(target, message)
def log_cmd(raw_nick, command, ptext, text): def log_cmd(raw_nick, command, ptext, text):
(nick, _, user, host) = parse_nick(raw_nick) (nick, _, user, host) = parse_nick(raw_nick)
@ -578,6 +590,14 @@ def mark_prefer_notice(cli, nick, chan, rest):
cli.notice(nick, "The bot will now always NOTICE you.") cli.notice(nick, "The bot will now always NOTICE you.")
def is_user_notice(nick):
if nick in USERS and USERS[nick]["account"] and USERS[nick]["account"] != "*":
if USERS[nick]["account"] in PREFER_NOTICE_ACCS:
return True
if nick in USERS and USERS[nick]["cloak"] in PREFER_NOTICE and not ACCOUNTS_ONLY:
return True
return False
@cmd("away", raw_nick=True, pm=True) @cmd("away", raw_nick=True, pm=True)
def away(cli, nick, chan, rest): def away(cli, nick, chan, rest):
"""Use this to activate your away status (so you aren't pinged).""" """Use this to activate your away status (so you aren't pinged)."""
@ -4138,6 +4158,9 @@ def hvisit(cli, nick, chan, rest):
var.LOGGER.logBare(var.HVISITED[nick], "VISITED", nick) var.LOGGER.logBare(var.HVISITED[nick], "VISITED", nick)
chk_nightdone(cli) chk_nightdone(cli)
def is_fake_nick(who):
return re.match("[0-9]+", who)
@cmd("see", chan=False, pm=True, game=True, playing=True, roles=("seer", "oracle", "augur")) @cmd("see", chan=False, pm=True, game=True, playing=True, roles=("seer", "oracle", "augur"))
def see(cli, nick, chan, rest): def see(cli, nick, chan, rest):
role = var.get_role(nick) role = var.get_role(nick)

View File

@ -245,32 +245,6 @@ PING_IN_ACCS = [] # accounts of people who have opted in for ping
is_role = lambda plyr, rol: rol in ROLES and plyr in ROLES[rol] is_role = lambda plyr, rol: rol in ROLES and plyr in ROLES[rol]
def pm(cli, target, message): # message either privmsg or notice, depending on user settings
if is_fake_nick(target) and botconfig.DEBUG_MODE:
print("[{0}] Would send message to fake nick {1}: {2}".format(
time.strftime("%d/%b/%Y %H:%M:%S"),
target,
message), file=sys.stderr)
return
if is_user_notice(target):
cli.notice(target, message)
return
cli.msg(target, message)
def is_user_notice(nick):
if nick in USERS and USERS[nick]["account"] and USERS[nick]["account"] != "*":
if USERS[nick]["account"] in PREFER_NOTICE_ACCS:
return True
if nick in USERS and USERS[nick]["cloak"] in PREFER_NOTICE and not ACCOUNTS_ONLY:
return True
return False
def is_fake_nick(who):
return re.match("[0-9]+", who)
def is_admin(nick): def is_admin(nick):
if nick not in USERS.keys(): if nick not in USERS.keys():
return False return False

View File

@ -76,10 +76,6 @@ def generate(fdict, permissions=True, **kwargs):
if nick in var.ROLES[role]: if nick in var.ROLES[role]:
break break
else: else:
if len(roles) == 1:
var.pm(largs[0], nick, "Only a{0} {1} may use this command.".format("n" if roles[0][0] in "aeiou" else "", roles[0]))
else:
var.pm(largs[0], nick, "Only a{0} {1} or {2} may use this command.".format("n" if roles[0][0] in "aeiou" else "", ", ".join(roles[:-1]), roles[-1]))
return return
if acc: if acc:
for pattern in var.DENY_ACCOUNTS.keys(): for pattern in var.DENY_ACCOUNTS.keys():