simpler boolean channel settings
This commit is contained in:
parent
954a1b4dfc
commit
190d42fbb5
5 changed files with 16 additions and 13 deletions
9
Utils.py
9
Utils.py
|
@ -165,3 +165,12 @@ def from_pretty_time(pretty_time):
|
|||
seconds += number
|
||||
if seconds > 0:
|
||||
return seconds
|
||||
|
||||
IS_TRUE = ["true", "yes", "on", "y"]
|
||||
IS_FALSE = ["false", "no", "off", "n"]
|
||||
def bool_or_none(s):
|
||||
s = s.lower()
|
||||
if s in IS_TRUE:
|
||||
return True
|
||||
elif s in IS_FALSE:
|
||||
return False
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
|
||||
import Utils
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
|
@ -7,13 +7,11 @@ class Module(object):
|
|||
bot.events.on("channel").on("mode").hook(self.on_mode)
|
||||
bot.events.on("received").on("join").hook(self.on_join)
|
||||
|
||||
def validate_setchannel(self, s):
|
||||
return s.lower() == "true"
|
||||
def boot_done(self, event):
|
||||
self.bot.events.on("postboot").on("configure").on(
|
||||
"channelset").call(setting="automode",
|
||||
help="Disable/Enable automode",
|
||||
validate=self.validate_setchannel)
|
||||
validate=Utils.bool_or_none)
|
||||
|
||||
def on_mode(self, event):
|
||||
if event["channel"].get_setting("automode", False):
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import re, time
|
||||
import Utils
|
||||
|
||||
REGEX_KARMA = re.compile("(.*)(\+{2,}|\-{2,})")
|
||||
KARMA_DELAY_SECONDS = 3
|
||||
|
@ -14,13 +15,11 @@ class Module(object):
|
|||
usage="[target]")
|
||||
bot.events.on("boot").on("done").hook(self.boot_done)
|
||||
|
||||
def validate_setchannel(self, s):
|
||||
return s.lower() == "true"
|
||||
def boot_done(self, event):
|
||||
self.bot.events.on("postboot").on("configure").on(
|
||||
"channelset").call(setting="karmaverbose",
|
||||
help="Disable/Enable automatically responding to karma changes",
|
||||
validate=self.validate_setchannel)
|
||||
validate=Utils.bool_or_none)
|
||||
|
||||
def new_user(self, event):
|
||||
event["user"].last_karma = None
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import re, traceback
|
||||
import Utils
|
||||
|
||||
REGEX_SPLIT = re.compile("(?<!\\\\)/")
|
||||
REGEX_SED = re.compile("^s/")
|
||||
|
@ -10,13 +11,11 @@ class Module(object):
|
|||
bot.events.on("received").on("message").on("channel").hook(
|
||||
self.channel_message)
|
||||
|
||||
def validate_setchannel(self, s):
|
||||
return s.lower() == "true"
|
||||
def boot_done(self, event):
|
||||
self.bot.events.on("postboot").on("configure").on(
|
||||
"channelset").call(setting="sed",
|
||||
help="Disable/Enable sed in a channel",
|
||||
validate=self.validate_setchannel)
|
||||
validate=Utils.bool_or_none)
|
||||
|
||||
def channel_message(self, event):
|
||||
if event["action"] or not event["channel"].get_setting("sed", True):
|
||||
|
|
|
@ -26,13 +26,11 @@ class Module(object):
|
|||
self.channel_message)
|
||||
bot.events.on("boot").on("done").hook(self.boot_done)
|
||||
|
||||
def validate_setchannel(self, s):
|
||||
return s.lower() == "true"
|
||||
def boot_done(self, event):
|
||||
self.bot.events.on("postboot").on("configure").on(
|
||||
"channelset").call(setting="autoyoutube",
|
||||
help="Disable/Enable automatically getting info from youtube URLs",
|
||||
validate=self.validate_setchannel)
|
||||
validate=Utils.bool_or_none)
|
||||
|
||||
def get_video_page(self, video_id, part):
|
||||
return Utils.get_url(URL_YOUTUBEVIDEO, get_params={"part": part,
|
||||
|
|
Loading…
Reference in a new issue