from command import CommandManager import json import slack import time with open('config.json', 'r') as f: config = json.load(f) CHESSTER_ID = config['CHESSTER']['ID'] SLEEP_SECONDS = config['GENERAL']['SLEEP_SECONDS'] command_queue = CommandManager() def start_chesster(): """Start up chesster""" if slack.connect(): print 'Chesster is up and running!' run_chesster() def run_chesster(): """Let chesster listen for any commands and act on them""" while True: command, channel = get_command_from_chat(slack.read()) if command is not None: command_queue.put_command_in_queue(command) response = command_queue.execute_top_command_in_queue() answer_in_chat(response, channel) time.sleep(SLEEP_SECONDS)
JSON = PATH['json'] # Yep you should rename your config.json and append priv to it # This way you won't add even more private stuff on github CONFIG = JSON + "priv.nhk.config.json" COMMANDS = JSON + "nhk.command.json" logging.basicConfig(level=logging.INFO) nhatz_config = CLIENT.loadJson(CONFIG) commands = CLIENT.loadJson(COMMANDS) censored = nhatz_config['censored'] Nhatz = discord.Client() last_msg = dict() comanager = CommandManager(Nhatz, commands, nhatz_config) def record_message(msg): if msg.channel.id in comanager.last_msg: comanager.last_msg[msg.channel.id].put(msg) else: comanager.last_msg[msg.channel.id] = queue.LifoQueue() comanager.last_msg[msg.channel.id].put(msg) @Nhatz.event async def on_ready(): CLIENT.greet(Nhatz)
logging.basicConfig(level=logging.INFO) wame_config = dict() xkcd_index = dict() xkcd_refs = dict() wame_config = CLIENT.loadJson(CONFIG) xkcd_index = CLIENT.loadJson(INDEX) xkcd_refs = CLIENT.loadJson(REF) blk_list = CLIENT.loadJson(BL) commands = CLIENT.loadJson(COMMANDS) Wame = discord.Client() wgame = discord.Game(name=wame_config['game']) comanager = CommandManager(Wame, xkcd_refs, xkcd_index, blk_list, commands, wame_config) @Wame.event async def on_ready(): await Wame.change_presence(game=wgame) bug_channel = Wame.get_channel(wame_config['report_channel']) CLIENT.greet(Wame, channel=bug_channel) @Wame.event async def on_message(message): if any([message.content.startswith(i) for i in wame_config['prefix']]): if message.mention_everyone \ or len(message.content.split("@here")) > 1 \ or len(message.mentions) > 1:
def __init__(self, storage, storageData): self.storage = storage self.storageData = storageData self.pages = storage.loadPages(storageData) self._manager = CommandManager(config.UNDO_HISTORY_SIZE)