add reply() command, cleans up some logic with deciding where to send messages
This also easily fixes the bug where commands in alternate channels would be sent to a /notice
This commit is contained in:
parent
44d1173c20
commit
c350603ea0
@ -62,7 +62,8 @@ def mass_privmsg(cli, targets, msg, notice=False, privmsg=False):
|
|||||||
else:
|
else:
|
||||||
cli.msg(bgs, msg)
|
cli.msg(bgs, msg)
|
||||||
|
|
||||||
def pm(cli, target, message): # message either privmsg or notice, depending on user settings
|
# message either privmsg or notice, depending on user settings
|
||||||
|
def pm(cli, target, message):
|
||||||
if is_fake_nick(target) and botconfig.DEBUG_MODE:
|
if is_fake_nick(target) and botconfig.DEBUG_MODE:
|
||||||
debuglog("Would message fake nick {0}: {1!r}".format(target, message))
|
debuglog("Would message fake nick {0}: {1!r}".format(target, message))
|
||||||
return
|
return
|
||||||
@ -73,6 +74,15 @@ def pm(cli, target, message): # message either privmsg or notice, depending on
|
|||||||
|
|
||||||
cli.msg(target, message)
|
cli.msg(target, message)
|
||||||
|
|
||||||
|
# Decide how to reply to a user, depending on the channel / query it was called in, and whether a game is running and they are playing
|
||||||
|
def reply(cli, nick, chan, msg, private=False):
|
||||||
|
if chan == nick:
|
||||||
|
pm(cli, nick, msg)
|
||||||
|
elif private or (nick not in var.list_players() and var.PHASE not in ("none", "join") and chan == botconfig.CHANNEL):
|
||||||
|
cli.notice(nick, msg)
|
||||||
|
else:
|
||||||
|
cli.msg(chan, msg)
|
||||||
|
|
||||||
def is_user_simple(nick):
|
def is_user_simple(nick):
|
||||||
if nick in var.USERS:
|
if nick in var.USERS:
|
||||||
ident = var.USERS[nick]["ident"]
|
ident = var.USERS[nick]["ident"]
|
||||||
|
138
src/wolfgame.py
138
src/wolfgame.py
@ -608,12 +608,7 @@ def restart_program(cli, nick, chan, rest):
|
|||||||
@cmd("ping", pm=True)
|
@cmd("ping", pm=True)
|
||||||
def pinger(cli, nick, chan, rest):
|
def pinger(cli, nick, chan, rest):
|
||||||
"""Check if you or the bot is still connected."""
|
"""Check if you or the bot is still connected."""
|
||||||
message = random.choice(var.PING_MESSAGES).format(nick=nick)
|
reply(cli, nick, chan, random.choice(var.PING_MESSAGES).format(nick=nick))
|
||||||
|
|
||||||
if chan == nick:
|
|
||||||
pm(cli, nick, message)
|
|
||||||
else:
|
|
||||||
cli.msg(chan, message)
|
|
||||||
|
|
||||||
@cmd("simple", raw_nick=True, pm=True)
|
@cmd("simple", raw_nick=True, pm=True)
|
||||||
def mark_simple_notify(cli, nick, chan, rest):
|
def mark_simple_notify(cli, nick, chan, rest):
|
||||||
@ -814,17 +809,11 @@ def altpinger(cli, nick, chan, rest):
|
|||||||
host = var.USERS[nick]["host"]
|
host = var.USERS[nick]["host"]
|
||||||
acc = var.USERS[nick]["account"]
|
acc = var.USERS[nick]["account"]
|
||||||
else:
|
else:
|
||||||
if chan == nick:
|
reply(cli, nick, chan, "You need to be in {0} to use that command.".format(botconfig.CHANNEL), True)
|
||||||
pm(cli, nick, "You need to be in {0} to use that command.".format(botconfig.CHANNEL))
|
|
||||||
else: # former message: "You won the lottery! This is a bug though, so report it to the admins."
|
|
||||||
cli.notice(nick, "You need to be in {0} to use that command.".format(botconfig.CHANNEL))
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if (not acc or acc == "*") and var.ACCOUNTS_ONLY:
|
if (not acc or acc == "*") and var.ACCOUNTS_ONLY:
|
||||||
if chan == nick:
|
reply(cli, nick, chan, "You are not logged in to NickServ.", True)
|
||||||
pm(cli, nick, "You are not logged in to NickServ.")
|
|
||||||
else:
|
|
||||||
cli.notice(nick, "You are not logged in to NickServ.")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
msg = []
|
msg = []
|
||||||
@ -863,10 +852,7 @@ def altpinger(cli, nick, chan, rest):
|
|||||||
else:
|
else:
|
||||||
msg.append("Invalid parameter. Please enter a non-negative integer or a valid preference.")
|
msg.append("Invalid parameter. Please enter a non-negative integer or a valid preference.")
|
||||||
|
|
||||||
if chan == nick:
|
reply(cli, nick, chan, "\n".join(msg), True)
|
||||||
pm(cli, nick, "\n".join(msg))
|
|
||||||
else:
|
|
||||||
cli.notice(nick, "\n".join(msg))
|
|
||||||
|
|
||||||
def is_user_altpinged(nick):
|
def is_user_altpinged(nick):
|
||||||
if nick in var.USERS.keys():
|
if nick in var.USERS.keys():
|
||||||
@ -1094,17 +1080,11 @@ def deadchat_pref(cli, nick, chan, rest):
|
|||||||
host = var.USERS[nick]["host"]
|
host = var.USERS[nick]["host"]
|
||||||
acc = var.USERS[nick]["account"]
|
acc = var.USERS[nick]["account"]
|
||||||
else:
|
else:
|
||||||
if chan == nick:
|
reply(cli, nick, chan, "You need to be in {0} to use that command.".format(botconfig.CHANNEL), True)
|
||||||
pm(cli, nick, "You need to be in {0} to use that command.".format(botconfig.CHANNEL))
|
|
||||||
else:
|
|
||||||
cli.notice(nick, "You need to be in {0} to use that command.".format(botconfig.CHANNEL))
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if (not acc or acc == "*") and var.ACCOUNTS_ONLY:
|
if (not acc or acc == "*") and var.ACCOUNTS_ONLY:
|
||||||
if chan == nick:
|
reply(cli, nick, chan, "You are not logged in to NickServ.", True)
|
||||||
pm(cli, nick, "You are not logged in to NickServ.")
|
|
||||||
else:
|
|
||||||
cli.notice(nick, "You are not logged in to NickServ.")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if acc and acc != "*":
|
if acc and acc != "*":
|
||||||
@ -1124,10 +1104,7 @@ def deadchat_pref(cli, nick, chan, rest):
|
|||||||
variable.add(value)
|
variable.add(value)
|
||||||
var.add_deadchat_pref(value, value == acc)
|
var.add_deadchat_pref(value, value == acc)
|
||||||
|
|
||||||
if chan == nick:
|
reply(cli, nick, chan, msg, True)
|
||||||
pm(cli, nick, msg)
|
|
||||||
else:
|
|
||||||
cli.notice(nick, msg)
|
|
||||||
|
|
||||||
@cmd("join", "j", pm=True)
|
@cmd("join", "j", pm=True)
|
||||||
def join(cli, nick, chan, rest):
|
def join(cli, nick, chan, rest):
|
||||||
@ -1509,13 +1486,7 @@ def stats(cli, nick, chan, rest):
|
|||||||
else:
|
else:
|
||||||
msg = "{0}\u00021\u0002 player: {1}".format(_nick, pl[0])
|
msg = "{0}\u00021\u0002 player: {1}".format(_nick, pl[0])
|
||||||
|
|
||||||
if nick == chan:
|
reply(cli, nick, chan, msg)
|
||||||
pm(cli, nick, msg)
|
|
||||||
else:
|
|
||||||
if nick in pl or var.PHASE == "join":
|
|
||||||
cli.msg(chan, msg)
|
|
||||||
else:
|
|
||||||
cli.notice(nick, msg)
|
|
||||||
|
|
||||||
if var.PHASE == "join" or var.STATS_TYPE == "disabled":
|
if var.PHASE == "join" or var.STATS_TYPE == "disabled":
|
||||||
return
|
return
|
||||||
@ -2029,13 +2000,7 @@ def stats(cli, nick, chan, rest):
|
|||||||
message[-1],
|
message[-1],
|
||||||
vb,
|
vb,
|
||||||
var.PHASE)
|
var.PHASE)
|
||||||
if nick == chan:
|
reply(cli, nick, chan, stats_mssg)
|
||||||
pm(cli, nick, stats_mssg)
|
|
||||||
else:
|
|
||||||
if nick in pl or var.PHASE == "join":
|
|
||||||
cli.msg(chan, stats_mssg)
|
|
||||||
else:
|
|
||||||
cli.notice(nick, stats_mssg)
|
|
||||||
|
|
||||||
def hurry_up(cli, gameid, change):
|
def hurry_up(cli, gameid, change):
|
||||||
if var.PHASE != "day": return
|
if var.PHASE != "day": return
|
||||||
@ -2340,12 +2305,7 @@ def show_votes(cli, nick, chan, rest):
|
|||||||
for votee in var.VOTES.keys()]
|
for votee in var.VOTES.keys()]
|
||||||
msg = "{0}{1}".format(_nick, ", ".join(votelist))
|
msg = "{0}{1}".format(_nick, ", ".join(votelist))
|
||||||
|
|
||||||
if chan == nick:
|
reply(cli, nick, chan, msg)
|
||||||
pm(cli, nick, msg)
|
|
||||||
elif nick not in pl and var.PHASE not in ("none", "join"):
|
|
||||||
cli.notice(nick, msg)
|
|
||||||
else:
|
|
||||||
cli.msg(chan, msg)
|
|
||||||
|
|
||||||
pl = var.list_players()
|
pl = var.list_players()
|
||||||
avail = len(pl) - len(var.WOUNDED | var.ASLEEP | var.CONSECRATING | var.SICK)
|
avail = len(pl) - len(var.WOUNDED | var.ASLEEP | var.CONSECRATING | var.SICK)
|
||||||
@ -2361,12 +2321,7 @@ def show_votes(cli, nick, chan, rest):
|
|||||||
if var.ABSTAIN_ENABLED:
|
if var.ABSTAIN_ENABLED:
|
||||||
the_message += " \u0002{0}\u0002 player{1} refrained from voting.".format(not_voting, plural)
|
the_message += " \u0002{0}\u0002 player{1} refrained from voting.".format(not_voting, plural)
|
||||||
|
|
||||||
if chan == nick:
|
reply(cli, nick, chan, the_message)
|
||||||
pm(cli, nick, the_message)
|
|
||||||
elif nick not in pl and var.PHASE != "join":
|
|
||||||
cli.notice(nick, the_message)
|
|
||||||
else:
|
|
||||||
cli.msg(chan, the_message)
|
|
||||||
|
|
||||||
def chk_traitor(cli):
|
def chk_traitor(cli):
|
||||||
realwolves = var.WOLF_ROLES - {"wolf cub"}
|
realwolves = var.WOLF_ROLES - {"wolf cub"}
|
||||||
@ -8636,11 +8591,7 @@ def show_admins(cli, nick, chan, rest):
|
|||||||
def coin(cli, nick, chan, rest):
|
def coin(cli, nick, chan, rest):
|
||||||
"""It's a bad idea to base any decisions on this command."""
|
"""It's a bad idea to base any decisions on this command."""
|
||||||
|
|
||||||
if var.PHASE in ("day", "night") and nick not in var.list_players() and chan == botconfig.CHANNEL:
|
reply(cli, nick, chan, "\2{0}\2 tosses a coin into the air...".format(nick))
|
||||||
cli.notice(nick, "You may not use this command right now.")
|
|
||||||
return
|
|
||||||
|
|
||||||
cli.msg(chan, "\2{0}\2 tosses a coin into the air...".format(nick))
|
|
||||||
coin = random.choice(("heads", "tails"))
|
coin = random.choice(("heads", "tails"))
|
||||||
specialty = random.randrange(0,10)
|
specialty = random.randrange(0,10)
|
||||||
if specialty == 0:
|
if specialty == 0:
|
||||||
@ -8648,20 +8599,16 @@ def coin(cli, nick, chan, rest):
|
|||||||
if specialty == 1:
|
if specialty == 1:
|
||||||
coin = botconfig.NICK
|
coin = botconfig.NICK
|
||||||
cmsg = "The coin lands on \2{0}\2.".format(coin)
|
cmsg = "The coin lands on \2{0}\2.".format(coin)
|
||||||
cli.msg(chan, cmsg)
|
reply(cli, nick, chan, cmsg)
|
||||||
|
|
||||||
@cmd("pony", pm=True)
|
@cmd("pony", pm=True)
|
||||||
def pony(cli, nick, chan, rest):
|
def pony(cli, nick, chan, rest):
|
||||||
"""For entertaining bronies."""
|
"""For entertaining bronies."""
|
||||||
|
|
||||||
if var.PHASE in ("day", "night") and nick not in var.list_players() and chan == botconfig.CHANNEL:
|
reply(cli, nick, chan, "\2{0}\2 tosses a pony into the air...".format(nick))
|
||||||
cli.notice(nick, "You may not use this command right now.")
|
|
||||||
return
|
|
||||||
|
|
||||||
cli.msg(chan, "\2{0}\2 tosses a pony into the air...".format(nick))
|
|
||||||
pony = random.choice(("hoof", "plot"))
|
pony = random.choice(("hoof", "plot"))
|
||||||
cmsg = "The pony lands on \2{0}\2.".format(pony)
|
cmsg = "The pony lands on \2{0}\2.".format(pony)
|
||||||
cli.msg(chan, cmsg)
|
reply(cli, nick, chan, cmsg)
|
||||||
|
|
||||||
@cmd("time", pm=True, phases=("join", "day", "night"))
|
@cmd("time", pm=True, phases=("join", "day", "night"))
|
||||||
def timeleft(cli, nick, chan, rest):
|
def timeleft(cli, nick, chan, rest):
|
||||||
@ -8685,10 +8632,7 @@ def timeleft(cli, nick, chan, rest):
|
|||||||
msg = "There is \u00021\u0002 second remaining until the game may be started."
|
msg = "There is \u00021\u0002 second remaining until the game may be started."
|
||||||
|
|
||||||
if msg is not None:
|
if msg is not None:
|
||||||
if nick == chan:
|
reply(cli, nick, chan, msg)
|
||||||
pm(cli, nick, msg)
|
|
||||||
else:
|
|
||||||
cli.msg(chan, msg)
|
|
||||||
|
|
||||||
if var.PHASE in var.TIMERS:
|
if var.PHASE in var.TIMERS:
|
||||||
remaining = timeleft_internal(var.PHASE)
|
remaining = timeleft_internal(var.PHASE)
|
||||||
@ -8702,12 +8646,7 @@ def timeleft(cli, nick, chan, rest):
|
|||||||
else:
|
else:
|
||||||
msg = "{0} timers are currently disabled.".format(var.PHASE.capitalize())
|
msg = "{0} timers are currently disabled.".format(var.PHASE.capitalize())
|
||||||
|
|
||||||
if nick == chan:
|
reply(cli, nick, chan, msg)
|
||||||
pm(cli, nick, msg)
|
|
||||||
elif nick not in var.list_players() and var.PHASE not in ("none", "join"):
|
|
||||||
cli.notice(nick, msg)
|
|
||||||
else:
|
|
||||||
cli.msg(chan, msg)
|
|
||||||
|
|
||||||
def timeleft_internal(phase):
|
def timeleft_internal(phase):
|
||||||
return int((var.TIMERS[phase][1] + var.TIMERS[phase][2]) - time.time()) if phase in var.TIMERS else -1
|
return int((var.TIMERS[phase][1] + var.TIMERS[phase][2]) - time.time()) if phase in var.TIMERS else -1
|
||||||
@ -8794,14 +8733,7 @@ def listroles(cli, nick, chan, rest):
|
|||||||
if not msg:
|
if not msg:
|
||||||
msg = ["No roles are defined for {0}p games.".format(index)]
|
msg = ["No roles are defined for {0}p games.".format(index)]
|
||||||
|
|
||||||
msg = " ".join(msg)
|
reply(cli, nick, chan, " ".join(msg))
|
||||||
|
|
||||||
if chan == nick:
|
|
||||||
pm(cli, nick, msg)
|
|
||||||
elif nick not in var.list_players() and var.PHASE not in ("none", "join"):
|
|
||||||
cli.notice(nick, msg)
|
|
||||||
else:
|
|
||||||
cli.msg(chan, msg)
|
|
||||||
|
|
||||||
@cmd("myrole", pm=True, phases=("day", "night"))
|
@cmd("myrole", pm=True, phases=("day", "night"))
|
||||||
def myrole(cli, nick, chan, rest):
|
def myrole(cli, nick, chan, rest):
|
||||||
@ -8991,16 +8923,10 @@ def game_stats(cli, nick, chan, rest):
|
|||||||
|
|
||||||
# List all games sizes and totals if no size is given
|
# List all games sizes and totals if no size is given
|
||||||
if not gamesize:
|
if not gamesize:
|
||||||
if chan == nick:
|
reply(cli, nick, chan, var.get_game_totals(gamemode))
|
||||||
pm(cli, nick, var.get_game_totals(gamemode))
|
|
||||||
else:
|
|
||||||
cli.msg(chan, var.get_game_totals(gamemode))
|
|
||||||
else:
|
else:
|
||||||
# Attempt to find game stats for the given game size
|
# Attempt to find game stats for the given game size
|
||||||
if chan == nick:
|
reply(cli, nick, chan, var.get_game_stats(gamemode, gamesize))
|
||||||
pm(cli, nick, var.get_game_stats(gamemode, gamesize))
|
|
||||||
else:
|
|
||||||
cli.msg(chan, var.get_game_stats(gamemode, gamesize))
|
|
||||||
|
|
||||||
@cmd("playerstats", "pstats", "player", "p", pm=True)
|
@cmd("playerstats", "pstats", "player", "p", pm=True)
|
||||||
def player_stats(cli, nick, chan, rest):
|
def player_stats(cli, nick, chan, rest):
|
||||||
@ -9012,6 +8938,10 @@ def player_stats(cli, nick, chan, rest):
|
|||||||
"before using it again."))
|
"before using it again."))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if chan != nick and chan == botconfig.CHANNEL and var.PHASE not in ("none", "join"):
|
||||||
|
cli.notice(nick, "You cannot use this command in channel right now")
|
||||||
|
return
|
||||||
|
|
||||||
if chan != nick:
|
if chan != nick:
|
||||||
var.LAST_PSTATS = datetime.now()
|
var.LAST_PSTATS = datetime.now()
|
||||||
|
|
||||||
@ -9040,22 +8970,11 @@ def player_stats(cli, nick, chan, rest):
|
|||||||
|
|
||||||
# List the player's total games for all roles if no role is given
|
# List the player's total games for all roles if no role is given
|
||||||
if len(params) < 2:
|
if len(params) < 2:
|
||||||
message = var.get_player_totals(acc)
|
reply(cli, nick, chan, var.get_player_totals(acc), True)
|
||||||
if chan == nick:
|
|
||||||
pm(cli, nick, message)
|
|
||||||
else:
|
|
||||||
cli.notice(nick, message)
|
|
||||||
else:
|
else:
|
||||||
role = " ".join(params[1:])
|
role = " ".join(params[1:])
|
||||||
# Attempt to find the player's stats
|
# Attempt to find the player's stats
|
||||||
message = var.get_player_stats(acc, role)
|
reply(cli, nick, chan, var.get_player_stats(acc, role))
|
||||||
|
|
||||||
if chan == nick:
|
|
||||||
pm(cli, nick, message)
|
|
||||||
elif var.PHASE not in ("none", "join"):
|
|
||||||
cli.notice(nick, message)
|
|
||||||
else:
|
|
||||||
cli.msg(chan, message)
|
|
||||||
|
|
||||||
@cmd("mystats", "m", pm=True)
|
@cmd("mystats", "m", pm=True)
|
||||||
def my_stats(cli, nick, chan, rest):
|
def my_stats(cli, nick, chan, rest):
|
||||||
@ -9098,10 +9017,7 @@ def show_modes(cli, nick, chan, rest):
|
|||||||
msg = "Available game modes: \u0002"
|
msg = "Available game modes: \u0002"
|
||||||
modes = "\u0002, \u0002".join(sorted(var.GAME_MODES.keys() - {"roles"}))
|
modes = "\u0002, \u0002".join(sorted(var.GAME_MODES.keys() - {"roles"}))
|
||||||
|
|
||||||
if chan == nick:
|
reply(cli, nick, chan, msg + modes + "\u0002", True)
|
||||||
pm(cli, nick, msg + modes + "\u0002")
|
|
||||||
else:
|
|
||||||
cli.notice(nick, msg + modes + "\u0002")
|
|
||||||
|
|
||||||
def game_help(args=""):
|
def game_help(args=""):
|
||||||
return "Votes to make a specific game mode more likely. Available game mode setters: " +\
|
return "Votes to make a specific game mode more likely. Available game mode setters: " +\
|
||||||
|
Loading…
x
Reference in New Issue
Block a user