Example #1
0
def explain_response(lrrbot, conn, event, respond_to, command):
    """
	Command: !explain TOPIC
	Mod-Only: true
	Section: text
	
	Provide an explanation for a given topic.
	--command
	Command: !explain show
	Mod-Only: true
	Section: text

	Provide an explanation for the currently-live show.
	"""
    command = " ".join(command.split())
    if command.lower() == "show":
        command = lrrbot.show_override or lrrbot.show
        if command is None and lrrbot.is_mod(event):
            conn.privmsg(respond_to, "Current show not set.")
    response_data = storage.data["explanations"].get(command.lower())
    if not response_data:
        return
    if response_data["access"] == "sub":
        if not lrrbot.is_sub(event) and not lrrbot.is_mod(event):
            log.info("Refusing explain %s due to inadequate access" % command)
            return
    if response_data["access"] == "mod":
        if not lrrbot.is_mod(event):
            log.info("Refusing explain %s due to inadequate access" % command)
            return
    response = response_data['response']
    if isinstance(response, (tuple, list)):
        response = random.choice(response)
    conn.privmsg(respond_to, response)
Example #2
0
def set_data(lrrbot, user, data):
	if not isinstance(data['key'], (list, tuple)):
		data['key'] = [data['key']]
	log.info("Setting storage %s to %r" % ('.'.join(data['key']), data['value']))
	# if key is, eg, ["a", "b", "c"]
	# then we want to effectively do:
	# storage.data["a"]["b"]["c"] = value
	# But in case one of those intermediate dicts doesn't exist:
	# storage.data.setdefault("a", {}).setdefault("b", {})["c"] = value
	node = storage.data
	for subkey in data['key'][:-1]:
		node = node.setdefault(subkey, {})
	node[data['key'][-1]] = data['value']
	storage.save()
Example #3
0
def set_data(lrrbot, user, data):
    if not isinstance(data['key'], (list, tuple)):
        data['key'] = [data['key']]
    log.info("Setting storage %s to %r" %
             ('.'.join(data['key']), data['value']))
    # if key is, eg, ["a", "b", "c"]
    # then we want to effectively do:
    # storage.data["a"]["b"]["c"] = value
    # But in case one of those intermediate dicts doesn't exist:
    # storage.data.setdefault("a", {}).setdefault("b", {})["c"] = value
    node = storage.data
    for subkey in data['key'][:-1]:
        node = node.setdefault(subkey, {})
    node[data['key'][-1]] = data['value']
    storage.save()
Example #4
0
def static_response(lrrbot, conn, event, respond_to, command):
	command = " ".join(command.split())
	response_data = storage.data["responses"][command.lower()]
	if response_data["access"] == "sub":
		if not lrrbot.is_sub(event) and not lrrbot.is_mod(event):
			log.info("Refusing %s due to inadequate access" % command)
			return
	if response_data["access"] == "mod":
		if not lrrbot.is_mod(event):
			log.info("Refusing %s due to inadequate access" % command)
			return
	response = response_data["response"]
	if isinstance(response, (tuple, list)):
		response = random.choice(response)
	conn.privmsg(respond_to, response)
Example #5
0
def static_response(lrrbot, conn, event, respond_to, command):
    command = " ".join(command.split())
    response_data = storage.data["responses"][command.lower()]
    if response_data["access"] == "sub":
        if not lrrbot.is_sub(event) and not lrrbot.is_mod(event):
            log.info("Refusing %s due to inadequate access" % command)
            return
    if response_data["access"] == "mod":
        if not lrrbot.is_mod(event):
            log.info("Refusing %s due to inadequate access" % command)
            return
    response = response_data["response"]
    if isinstance(response, (tuple, list)):
        response = random.choice(response)
    conn.privmsg(respond_to, response)
Example #6
0
#!/usr/bin/env python3

import logging

from lrrbot import bot, log, chatlog, twitchsubs
from common.config import config


logging.basicConfig(level=config['loglevel'], format="[%(asctime)s] %(levelname)s:%(name)s:%(message)s")
if config['logfile'] is not None:
	fileHandler = logging.FileHandler(config['logfile'], 'a', 'utf-8')
	fileHandler.formatter = logging.root.handlers[0].formatter
	logging.root.addHandler(fileHandler)

import lrrbot.commands
import lrrbot.serverevents
bot.compile()

chatlog.createthread()
twitchsubs.createthread()

try:
	log.info("Bot startup")
	bot.start()
except (KeyboardInterrupt, SystemExit):
	pass
finally:
	log.info("Bot shutdown")
	logging.shutdown()
	chatlog.exitthread()