From 2c3aafc1015c38cb7f1a2d33091d6791189ee5d7 Mon Sep 17 00:00:00 2001 From: nyuszika7h Date: Sun, 13 Nov 2016 11:54:48 +0100 Subject: [PATCH] Improvements to !rules * RULES is now not defined in settings.py, only in botconfig.py. * If there are no rules specified, a default message is shown instructing users to configure it. * The "#CHANNEL channel rules: " prefix is now automatically prepended (skipped if the string already contains that, for backwards-compatibility). * The prefix and the no-rules message can be customized as they are in messages.py now. --- botconfig.py.example | 2 +- messages/en.json | 2 ++ src/settings.py | 2 -- src/wolfgame.py | 15 +++++++++++++-- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/botconfig.py.example b/botconfig.py.example index 1040758..c1363c4 100644 --- a/botconfig.py.example +++ b/botconfig.py.example @@ -24,7 +24,7 @@ SERVER_PASS = "{account}:{password}" OWNERS = ("unaffiliated/wolfbot_admin1",) # The comma is required at the end if there is only one owner. OWNERS_ACCOUNTS = ("1owner_acc",) -#RULES = "{0} channel rules: https://werewolf.chat/Freenode:Rules".format(botconfig.CHANNEL) +#RULES = "https://werewolf.chat/Freenode:Rules" ALLOWED_NORMAL_MODE_COMMANDS = [] # Debug mode commands to be allowed in normal mode OWNERS_ONLY_COMMANDS = [] # Commands that should only be allowed for owners, regardless of their original permissions diff --git a/messages/en.json b/messages/en.json index 2ebb7df..4c67043 100644 --- a/messages/en.json +++ b/messages/en.json @@ -864,6 +864,8 @@ "tempban_kick": "Temporary ban for warning: {reason}", "error_log": "An error has occurred and has been logged.", "error_pastebin": "(Unable to pastebin traceback; please check the console)", + "channel_rules": "{0} channel rules: {1}", + "no_channel_rules": "No rules are defined for {0}. Set RULES in botconfig.py to configure this.", "_": " vim: set sw=4 expandtab:" } diff --git a/src/settings.py b/src/settings.py index 4bb3ec4..72188c7 100644 --- a/src/settings.py +++ b/src/settings.py @@ -320,8 +320,6 @@ FORTUNE_CHANCE = 1/25 ALL_FLAGS = frozenset("AaDdFjms") -RULES = "To configure this command, the bot administrator should uncomment and modify RULES in botconfig.py." - GRAVEYARD_LOCK = threading.RLock() WARNING_LOCK = threading.RLock() WAIT_TB_LOCK = threading.RLock() diff --git a/src/wolfgame.py b/src/wolfgame.py index 2d6eaeb..7d8f26f 100644 --- a/src/wolfgame.py +++ b/src/wolfgame.py @@ -6550,11 +6550,22 @@ def reset_game(cli, nick, chan, rest): reset() cli.msg(botconfig.CHANNEL, "PING! {0}".format(" ".join(pl))) - @cmd("rules", pm=True) def show_rules(cli, nick, chan, rest): """Displays the rules.""" - reply(cli, nick, chan, var.RULES) + + if hasattr(botconfig, "RULES"): + rules = botconfig.RULES + + # Backwards-compatibility + pattern = re.compile(r"^\S+ channel rules: ") + + if pattern.search(rules): + rules = pattern.sub("", rules) + + reply(cli, nick, chan, messages["channel_rules"].format(botconfig.CHANNEL, rules)) + else: + reply(cli, nick, chan, messages["no_channel_rules"].format(botconfig.CHANNEL)) @cmd("help", raw_nick=True, pm=True) def get_help(cli, rnick, chan, rest):