예제 #1
0
def twitchy():
    # we use the real twitch API in our tests, which should give great guarantees for it working
    config.read('config.ini')
    client_id = read_config('twitch', 'ClientId')
    client_secret = read_config('twitch', 'Secret')
    if not client_id or not client_secret:
        pytest.skip(
            'Cannot perform twitch tests! Please include twitch client id & secret in config.ini file.'
        )

    api = Twitchy(client_id, client_secret)
    yield api
    api.close()
예제 #2
0
def init():
    global e_host
    global e_cf_index
    global e_rank_index
    global e_fuzzy
    global e_shingle
    global e_explain
    global e_platforms
    global e_parts
    global e_allow_official

    e_host = read_config('elastic', 'Host', fallback=DEFAULT_HOST)
    e_cf_index = read_config('elastic',
                             'CustomsforgeIndex',
                             fallback=DEFAULT_CUSTOMSFORGE_INDEX)
    e_rank_index = read_config('elastic',
                               'RankIndex',
                               fallback=DEFAULT_USER_INDEX)
    e_fuzzy = read_config('elastic', 'Fuzziness', fallback=DEFAULT_FUZZINESS)
    e_shingle = read_config('elastic',
                            'ShingleCeiling',
                            convert=int,
                            fallback=DEFAULT_SHINGLE_CEILING)
    e_explain = read_config('elastic',
                            'Explain',
                            convert=parse_bool,
                            fallback=False)
    # noinspection PyTypeChecker
    e_platforms = read_config('elastic',
                              'Platforms',
                              convert=parse_list,
                              fallback=DEFAULT_PLATFORMS)
    # noinspection PyTypeChecker
    e_parts = read_config('elastic',
                          'Parts',
                          convert=parse_list,
                          fallback=DEFAULT_PARTS)
    e_allow_official = read_config('elastic',
                                   'RandomOfficial',
                                   convert=parse_bool,
                                   fallback=DEFAULT_OFFICIAL)

    e_shingle = max(2, e_shingle)

    for value in important_values():
        if value in TEST_ONLY_VALUES:
            nuke_from_orbit(
                'configuration error - cannot use TEST values for REAL initialization'
            )
예제 #3
0
from abc import ABC
from typing import Iterator

from sahyun_bot.users_settings import UserRank, User
from sahyun_bot.utils_settings import read_config

DEFAULT_MAX_SEARCH = 10
DEFAULT_MAX_PICK = 3
DEFAULT_MAX_PRINT = 5

cm_search = read_config('commands',
                        'MaxSearch',
                        convert=int,
                        fallback=DEFAULT_MAX_SEARCH)
cm_pick = read_config('commands',
                      'MaxPick',
                      convert=int,
                      fallback=DEFAULT_MAX_PICK)
cm_print = read_config('commands',
                       'MaxPrint',
                       convert=int,
                       fallback=DEFAULT_MAX_PRINT)

cm_search = max(1, cm_search)
cm_pick = max(1, cm_pick)
cm_print = max(1, cm_print)


class ResponseHook(ABC):
    """
    Base class for handling responses to the commands.
예제 #4
0
from sahyun_bot.utils_settings import read_config

t_id = read_config('twitch', 'ClientId')
t_secret = read_config('twitch', 'Secret')
예제 #5
0
from abc import ABC

from sahyun_bot.utils_settings import read_config

LINK_JOB_DEFAULT = 'ignore'

lj_default = read_config('links', 'Default', fallback=LINK_JOB_DEFAULT)


class LinkJob(ABC):
    """
    Strategy for handling links.

    Abstract implementations should start with 'Base'. Non-abstract implementations should not start with 'Base'.
    """
    def supports(self, link: str) -> bool:
        """
        :returns true if this job supports given link
        """
        return True

    def handle(self, link: str):
        """
        Performs some task with the given link.
        """
        raise NotImplementedError
예제 #6
0
def test_read_config():
    config.add_section('section')
    config.set('section', 'string', ' value ')
    config.set('section', 'int', ' 1 ')
    config.set('section', 'float', ' 2.71 ')
    config.set('section', 'bool', ' yes ')
    config.set('section', 'empty', '')
    config.set('section', 'blank', '')

    assert_that(read_config('section', 'string')).is_equal_to('value')
    assert_that(read_config('section', 'int', convert=int)).is_equal_to(1)
    assert_that(read_config('section', 'float',
                            convert=float)).is_equal_to(2.71)
    assert_that(read_config('section', 'bool', convert=parse_bool)).is_true()

    assert_that(read_config('section', 'missing')).is_none()
    assert_that(read_config('section', 'missing',
                            fallback='not_anymore')).is_equal_to('not_anymore')
    assert_that(read_config('section', 'string', convert=int,
                            fallback=10)).is_equal_to(10)

    assert_that(read_config('section', 'empty')).is_none()
    assert_that(read_config('section', 'empty',
                            fallback='used')).is_equal_to('used')
    assert_that(read_config('section', 'blank',
                            fallback='used')).is_equal_to('used')
    assert_that(
        read_config('section', 'empty', fallback='ignored',
                    allow_empty=True)).is_equal_to('')
    assert_that(
        read_config('section',
                    'blank',
                    fallback='still_ignored',
                    allow_empty=True)).is_equal_to('')
예제 #7
0
"""
Initializes configuration for the bot. Should only be imported by modules.py.
"""
import http.client
import logging.config

from sahyun_bot import elastic_settings
from sahyun_bot.customsforge_settings import *
from sahyun_bot.irc_bot_settings import *
from sahyun_bot.utils_settings import config, read_config, parse_bool

config.read('config.ini')

s_log = read_config('system',
                    'LoggingConfigFilename',
                    fallback='config_log_default.ini')
logging.config.fileConfig(
    s_log
)  # we initialize logging first to avoid dangling loggers from being created
logging.info('---------------------------------------------------------')
logging.info('                      NEW EXECUTION                      ')
logging.info('---------------------------------------------------------')

s_debug = read_config('system',
                      'HttpDebugMode',
                      convert=parse_bool,
                      fallback=False)
http.client.HTTPConnection.debuglevel = 1 if s_debug else 0

c_api_key = read_config('customsforge', 'ApiKey')
c_user = read_config('customsforge', 'Username')
from sahyun_bot.utils_settings import read_config

DEFAULT_MAX_THREADS = 8

l_max = read_config('load',
                    'MaxWorkers',
                    convert=int,
                    fallback=DEFAULT_MAX_THREADS)
예제 #9
0
from sahyun_bot.utils_settings import read_dynamic_config, read_config

DEFAULT_LENIENCY = 1

d_leniency = read_config('downtime',
                         'Leniency',
                         convert=int,
                         fallback=DEFAULT_LENIENCY)
d_down = read_dynamic_config('downtime',
                             ignore=['Leniency'],
                             convert_key=lambda key: key.lower(),
                             fallback='')