How to use the pmxbot.config function in pmxbot

To help you get started, we’ve selected a few pmxbot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yougov / pmxbot / tests / unit / test_commands.py View on Github external
def google_api_key(monkeypatch):
    key = os.environ.get('GOOGLE_API_KEY')
    if not key:
        pytest.skip("Need GOOGLE_API_KEY environment variable")
    monkeypatch.setitem(pmxbot.config, 'Google API key', key)
github yougov / pmxbot / pmxbot / core.py View on Github external
def _setup_logging():
    log_level = pmxbot.config.get('log level', logging.INFO)
    if isinstance(log_level, str):
        log_level = getattr(logging, log_level.upper())
    logging.basicConfig(level=log_level, format="%(message)s")
github yougov / pmxbot / pmxbot / logging.py View on Github external
def __contains__(self, channel):
        return channel in pmxbot.config.log_channels
github yougov / pmxbot / pmxbot / rolls.py View on Github external
def log_join(nick, channel):
    if channel not in pmxbot.config.log_channels:
        return
    ParticipantLogger.store.log_join(nick, channel)
github yougov / pmxbot / pmxbot / irc.py View on Github external
def on_join(self, connection, event):
        nick = event.source.nick
        channel = event.target
        client = connection
        for handler in core.JoinHandler._registry:
            try:
                handler.attach(locals())()
            except Exception:
                log.exception("Error in %s", handler)

        if channel not in pmxbot.config.log_channels:
            return
        if nick == self._nickname:
            return
        self.warn_history.warn(nick, connection)
github yougov / pmxbot / pmxbot / commands.py View on Github external
def google(rest):
    "Look up a phrase on google"
    API_URL = 'https://www.googleapis.com/customsearch/v1?'
    try:
        key = pmxbot.config['Google API key']
    except KeyError:
        return "Configure 'Google API key' in config"
    # Use a custom search that searches everything normally
    # http://stackoverflow.com/a/11206266/70170
    custom_search = '004862762669074674786:hddvfu0gyg0'
    params = dict(key=key, cx=custom_search, q=rest.strip())
    url = API_URL + urllib.parse.urlencode(params)
    resp = requests.get(url)
    resp.raise_for_status()
    results = resp.json()
    hit1 = next(iter(results['items']))
    return ' - '.join((urllib.parse.unquote(hit1['link']), hit1['title']))
github yougov / pmxbot / pmxbot / irc.py View on Github external
def _get_wrapper():
        """
        Get a socket wrapper based on SSL config.
        """
        if not pmxbot.config.get('use_ssl', False):
            return lambda x: x
        return importlib.import_module('ssl').wrap_socket