Start Modis in console format.

    Args:
        discord_token (str): The bot token for your Discord application
        discord_client_id: The bot's client ID
765367
def console(discord_token, discord_client_id):
    

    state, response = datatools.get_compare_version()

    logger.info("Starting Modis in console")
    logger.info(response)

    import threading
    import asyncio

    logger.debug("Loading packages")
    from modis.discord_modis import main as discord_modis_console
    from modis.reddit_modis import main as reddit_modis_console
    from modis.facebook_modis import main as facebook_modis_console

    # Create threads
    logger.debug("Initiating threads")
    loop = asyncio.get_event_loop()
    discord_thread = threading.Thread(
        target=discord_modis_console.start,
        args=[discord_token, discord_client_id, loop])
    reddit_thread = threading.Thread(
        target=reddit_modis_console.start, args=[])
    facebook_thread = threading.Thread(
        target=facebook_modis_console.start, args=[])

    # Run threads
    logger.debug("Starting threads")
    discord_thread.start()
    reddit_thread.start()
    facebook_thread.start()

    logger.debug("Root startup completed")
664650
def stop(self):
        """"""
        self.button_toggle_text.set("Start Modis")
        self.state = "off"

        logger.info("Stopping Discord Modis")

        from ._client import client
        asyncio.run_coroutine_threadsafe(client.logout(), client.loop)
        self.status_bar.set_status(0)
933938
def on_connect(client):
    
    print "++ Opened connection to %s" % client.addrport()
    broadcast('%s joins the conversation.\n' % client.addrport() )
    CLIENT_LIST.append(client)
    client.send("Welcome to the Chat Server, %s.\n" % client.addrport() )
1098752
def chat(client):
    
    global SERVER_RUN
    msg = client.get_command()
    print '%s says, "%s"' % (client.addrport(), msg)

    for guest in CLIENT_LIST:
        if guest != client:
            guest.send('%s says, %s\n' % (client.addrport(), msg))
        else:
            guest.send('You say, %s\n' % msg)

    cmd = msg.lower()
    ## bye = disconnect
    if cmd == 'bye':
        client.active = False
    ## shutdown == stop the server
    elif cmd == 'shutdown':
        SERVER_RUN = False
277964
def start_cmd(cmd, descr, data):
    
    if data and "provenance" in data:
        entity_id = tz.get_in(["provenance", "entity"], data)
1142572
def create(id, token)
      fail SlackBotManager::TokenAlreadyConnected if find_connection(id)

      # Create connection
      conn = SlackBotManager::Client.new(token)
      conn.connect

      # Add to connections using a uniq token
      if conn
        cid = [id, Time.now.to_i].join(':')
        connections[cid] = conn
        info("Connected: #{id} (Connection: #{cid})")
        storage.set(teams_key, id, 'active')
      end
    rescue => err
      on_error(err)
    end
572170
def add_client(self, user_id=None):
        
        if user_id is None:
            # generate a random uuid if it's an unauthenticated client
            self.channel = 'public'
            user_id = uuid.uuid1().hex
        else:
            self.channel = 'private'
        
        self.id = user_id
        self.channels[self.channel][self.id] = self
        print 'Client connected to the %s channel.' % self.channel
98246
function enableCommand(consoleService, moduleId, msg, cb) {
    if (!moduleId) {
        logger.error(`fail to enable admin module for ${moduleId}`);
        cb('empty moduleId');
        return;
    }

    const modules = consoleService.modules;
    if (!modules[moduleId]) {
        cb(null, protocol.PRO_FAIL);
        return;
    }

    if (consoleService.master) {
        consoleService.enable(moduleId);
        consoleService.agent.notifyCommand('enable', moduleId, msg);
        cb(null, protocol.PRO_OK);
    } else {
        consoleService.enable(moduleId);
        cb(null, protocol.PRO_OK);
    }
}
1307677
def cli(self):
        
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

        client.connect(hostname=self.private_hostname,
                       username=self.username,
                       key_filename=self.key_filename,
                       timeout=self.timeout,
                       look_for_keys=self.look_for_keys)
        # set keepalive
        transport = client.get_transport()
        transport.set_keepalive(3)
        return client
1163909
def start(token, client_id, loop, on_ready_handler=None):
    """"""
    import discord
    import asyncio

    # Create client
    logger.debug("Creating Discord client")
    asyncio.set_event_loop(loop)
    client = discord.Client()
    from . import _client
    _client.client = client

    from .. import datatools
    if datatools.has_data():
        data = datatools.get_data()
    else:
        # Create a blank data file
        data = {"discord": {}}

    # Save default server info to data
    if "servers" not in data["discord"]:
        data["discord"]["servers"] = {}

    # Save default key info to data
    if "keys" not in data["discord"]:
        data["discord"]["keys"] = {}

    # Save logger info to data
    if "log_level" not in data:
        data["log_level"] = "DEBUG"

    data["discord"]["token"] = token
    data["discord"]["client_id"] = client_id
    datatools.write_data(data)

    # Import event handlers
    logger.debug("Importing event handlers")
    event_handlers = _get_event_handlers()

    # Create event handler combiner
    logger.debug("Compiling event handlers")

    def create_event_handler(event_handler_type):
        async def func(*args, **kwargs):
            for module_event_handler in event_handlers[event_handler_type]:
                # Check for errors in the module event
                try:
                    module_event_handler_func = getattr(module_event_handler,
                                                        event_handler_type)
                    await module_event_handler_func(*args, **kwargs)
                except Exception as module_exception:
                    logger.error("An error occured in '{}'".format(module_event_handler))
                    logger.exception(module_exception)

            if on_ready_handler is not None and event_handler_type == "on_ready":
                await on_ready_handler()

        func.__name__ = event_handler_type
        return func

    # Register event handlers
    logger.debug("Registering event handlers into client")
    for event_handler in event_handlers.keys():
        client.event(create_event_handler(event_handler))

    # Run the client loop
    logger.info("Connecting to Discord")
    try:
        client.loop.run_until_complete(client.login(token))
    except Exception as e:
        logger.exception(e)
        logger.critical("Could not connect to Discord")
    else:
        logger.debug("Running the bot")
        try:
            client.loop.run_until_complete(client.connect())
        except KeyboardInterrupt:
            client.loop.run_until_complete(client.logout())
            pending = asyncio.Task.all_tasks(loop=client.loop)
            gathered = asyncio.gather(*pending, loop=client.loop)
            try:
                gathered.cancel()
                client.loop.run_until_complete(gathered)

                # we want to retrieve any exceptions to make sure that
                # they don't nag us about it being un-retrieved.
                gathered.exception()
            except Exception as e:
                logger.exception(e)
        except Exception as e:
            logger.exception(e)
            pending = asyncio.Task.all_tasks(loop=client.loop)
            gathered = asyncio.gather(*pending, loop=client.loop)
            gathered.exception()
        finally:
            try:
                client.loop.run_until_complete(client.logout())
            except Exception as e:
                logger.exception(e)

            logger.critical("Bot stopped\n")
            client.loop.close()
407176
def homeautoswitch(self, cmd, ain=None, param=None):
        
        assert self.sid, "Not logged in"
        params = {
            'switchcmd': cmd,
            'sid': self.sid,
        }
        if param is not None:
            params['param'] = param
        if ain:
            params['ain'] = ain

        url = self.base_url + '/webservices/homeautoswitch.lua'
        response = self.session.get(url, params=params, timeout=10)
        response.raise_for_status()
        return response.text.strip().encode('utf-8')
1361435
def start(self):
        
        print("Starting debug client cwd: {}".format(os.getcwd()))
        print("Sys path: {}".format(sys.path))

        #: Initialize the hotswapper
        self.hotswap = Hotswapper(debug=False)

        if self.mode == 'server':
            self.server.start(self)
        else:
            self.client.start(self)
438221
def member_create(self, params, member_id):
        
        member_config = params.get('rsParams', {})
        server_id = params.pop('server_id', None)
        version = params.pop('version', self._version)
        proc_params = {'replSet': self.repl_id}
        proc_params.update(params.get('procParams', {}))
        if self.enable_ipv6:
            enable_ipv6_single(proc_params)
        # Make sure that auth isn't set the first time we start the servers.
        proc_params = self._strip_auth(proc_params)

        # Don't pass in auth_key the first time we start the servers.
        server_id = self._servers.create(
            name='mongod',
            procParams=proc_params,
            sslParams=self.sslParams,
            version=version,
            server_id=server_id
        )
        member_config.update({"_id": member_id,
                              "host": self._servers.hostname(server_id)})
        return member_config
954398
def execute
      cli_arguments = Telegram::CLIArguments.new(@config)
      command = "'#{@config.daemon}' #{cli_arguments.to_s}"
      @stdout = IO.popen(command, 'a+')
      initialize_stdout_reading
    end
346110
def command_prompt(pymux, variables):
    
    client_state = pymux.get_client_state()

    if variables['<command>']:
        # When a 'command' has been given.
        client_state.prompt_text = variables['<message>'] or '(%s)' % variables['<command>'].split()[0]
        client_state.prompt_command = variables['<command>']

        client_state.prompt_mode = True
        client_state.prompt_buffer.reset(Document(
            format_pymux_string(pymux, variables['<default>'] or '')))

        get_app().layout.focus(client_state.prompt_buffer)
    else:
        # Show the ':' prompt.
        client_state.prompt_text = ''
        client_state.prompt_command = ''

        get_app().layout.focus(client_state.command_buffer)

    # Go to insert mode.
    get_app().vi_state.input_mode = InputMode.INSERT
536171
def get_token(username, length=20, timeout=20):
    
    redis = get_redis_client()
    token = get_random_string(length)
    token_key = 'token:{}'.format(token)
    redis.set(token_key, username)
    redis.expire(token_key, timeout)
    return token
129915
function startRtm (token) {
  api.rtm.start(token, (err, bot) => {
    if (err) {
      return console.log(err)
    }

    bot.on(/hello/, (bot, message) => {
      bot.reply(message, 'GO CUBS')
    })

    bot.on(/howdy/, (bot, message) => {
      bot.reply(message, 'GO TRIBE')
    })
  })
}