コード例 #1
0
    def __init__(self, config):
        self._config = config
        inbound_queue = queue.Queue(100)
        self._main_client = Client(
            inbound_queue=inbound_queue,
            twitch_char_limit='.twitch.tv:' in config['main_server'])
        self._main_client_thread = ClientThread(self._main_client)

        if 'discord_gateway_server' in config:
            self._discord_client = Client(
                inbound_queue=inbound_queue,
                twitch_char_limit=True)
            self._discord_client_thread = ClientThread(self._discord_client)
        else:
            self._discord_client = None
            self._discord_client_thread = None

        channels = self._config['channels']
        self._bot = Bot(channels, self._main_client,
                        inbound_queue,
                        ignored_users=self._config.get('ignored_users'),
                        lurk_channels=self._config.get('lurk_channels'),
                        discord_client=self._discord_client
                        )
        database = Database(self._config['database'])
        self._features = Features(self._bot, self._config['help_text'],
                                  database, self._config)
コード例 #2
0
ファイル: app.py プロジェクト: ioffl/chatbot383
class App(object):
    def __init__(self, config):
        self._config = config
        inbound_queue = queue.Queue(100)
        self._main_client = Client(inbound_queue=inbound_queue)
        self._main_client_thread = ClientThread(self._main_client)
        channels = self._config['channels']
        self._bot = Bot(channels, self._main_client,
                        inbound_queue,
                        ignored_users=self._config.get('ignored_users'),
                        lurk_channels=self._config.get('lurk_channels'),
                        )
        database = Database(self._config['database'])
        self._features = Features(self._bot, self._config['help_text'],
                                  database, self._config)

    def run(self):
        username = self._config['username']
        password = self._config.get('password')
        main_address = self._config['main_server'].rsplit(':', 1)
        main_address[1] = int(main_address[1])

        main_connect_factory = Client.new_connect_factory(
            hostname=main_address[0], use_ssl=self._config.get('ssl'))

        self._main_client.async_connect(
            main_address[0], main_address[1], username, password=password,
            connect_factory=main_connect_factory
        )

        self._main_client_thread.start()

        self._bot.run()
コード例 #3
0
ファイル: app.py プロジェクト: resistthis13/chatbot383
class App(object):
    def __init__(self, config):
        self._config = config
        self._main_client = Client()
        self._group_client = Client()
        self._main_client_thread = ClientThread(self._main_client)
        self._group_client_thread = ClientThread(self._group_client)
        channels = self._config['channels']
        self._bot = Bot(channels, self._main_client, self._group_client)
        database = Database(self._config['database'])
        self._features = Features(self._bot, self._config['help_text'],
                                  database)

    def run(self):
        username = self._config['username']
        password = self._config.get('password')
        main_address = self._config['main_server'].rsplit(':', 1)
        group_address = self._config['group_server'].rsplit(':', 1)
        main_address[1] = int(main_address[1])
        group_address[1] = int(group_address[1])

        self._main_client.async_connect(
            main_address[0], main_address[1], username, password=password
        )
        self._group_client.async_connect(
            group_address[0], group_address[1], username, password=password
        )

        self._main_client_thread.start()
        self._group_client_thread.start()

        self._bot.run()
コード例 #4
0
class App(object):
    def __init__(self, config):
        self._config = config
        inbound_queue = queue.Queue(100)
        self._main_client = Client(
            inbound_queue=inbound_queue,
            twitch_char_limit='.twitch.tv:' in config['main_server'])
        self._main_client_thread = ClientThread(self._main_client)

        if 'discord_gateway_server' in config:
            self._discord_client = Client(
                inbound_queue=inbound_queue,
                twitch_char_limit=True)
            self._discord_client_thread = ClientThread(self._discord_client)
        else:
            self._discord_client = None
            self._discord_client_thread = None

        channels = self._config['channels']
        self._bot = Bot(channels, self._main_client,
                        inbound_queue,
                        ignored_users=self._config.get('ignored_users'),
                        lurk_channels=self._config.get('lurk_channels'),
                        discord_client=self._discord_client
                        )
        database = Database(self._config['database'])
        self._features = Features(self._bot, self._config['help_text'],
                                  database, self._config)

    def run(self):
        username = self._config['username']
        password = self._config.get('password')
        main_address = self._config['main_server'].rsplit(':', 1)
        main_address[1] = int(main_address[1])

        main_connect_factory = Client.new_connect_factory(
            hostname=main_address[0], use_ssl=self._config.get('ssl'))

        self._main_client.async_connect(
            main_address[0], main_address[1], username, password=password,
            connect_factory=main_connect_factory
        )

        self._main_client_thread.start()

        if 'discord_gateway_server' in self._config:
            discord_password = self._config['discord_token']
            discord_address = self._config['discord_gateway_server'].rsplit(':', 1)
            discord_address[1] = int(discord_address[1])
            self._discord_client.async_connect(
                discord_address[0], discord_address[1], username,
                password=discord_password,
            )

            self._discord_client_thread.start()

        self._bot.run()
コード例 #5
0
ファイル: app.py プロジェクト: ioffl/chatbot383
 def __init__(self, config):
     self._config = config
     inbound_queue = queue.Queue(100)
     self._main_client = Client(inbound_queue=inbound_queue)
     self._main_client_thread = ClientThread(self._main_client)
     channels = self._config['channels']
     self._bot = Bot(channels, self._main_client,
                     inbound_queue,
                     ignored_users=self._config.get('ignored_users'),
                     lurk_channels=self._config.get('lurk_channels'),
                     )
     database = Database(self._config['database'])
     self._features = Features(self._bot, self._config['help_text'],
                               database, self._config)
コード例 #6
0
ファイル: app.py プロジェクト: resistthis13/chatbot383
 def __init__(self, config):
     self._config = config
     self._main_client = Client()
     self._group_client = Client()
     self._main_client_thread = ClientThread(self._main_client)
     self._group_client_thread = ClientThread(self._group_client)
     channels = self._config['channels']
     self._bot = Bot(channels, self._main_client, self._group_client)
     database = Database(self._config['database'])
     self._features = Features(self._bot, self._config['help_text'],
                               database)
コード例 #7
0
    def __init__(self, bot: Bot, help_text: str, database: Database,
                 config: dict):
        self._bot = bot
        self._help_text = help_text
        self._database = database
        self._config = config
        self._recent_messages_for_regex = collections.defaultdict(
            lambda: collections.deque(maxlen=100))
        self._last_message = {}
        self._spam_limiter = Limiter(min_interval=10)
        self._password_api_limiter = Limiter(min_interval=2)
        self._user_list = collections.defaultdict(set)
        self._regex_server = RegexServer()
        self._token_notifier = TokenNotifier(
            config.get('token_notify_filename'),
            config.get('token_notify_channels'),
            config.get('token_notify_interval', 60))
        self._tellnext_generator = None

        if os.path.isfile(config.get('tellnext_database', '')):
            self._tellnext_generator = TellnextGenerator(
                config['tellnext_database'])

        self._match_generator = None

        if os.path.isfile(config.get('veekun_pokedex_database', '')):
            self._match_generator = MatchGenerator(
                config['veekun_pokedex_database'])
            self._battlebot = BattleBot(config['veekun_pokedex_database'],
                                        self._bot)

            bot.register_message_handler('pubmsg',
                                         self._battlebot.message_callback)
            bot.register_message_handler('whisper',
                                         self._battlebot.message_callback)

        self._mail_disabled_channels = config.get('mail_disabled_channels')
        self._avoid_pikalaxbot = config.get('avoid_pikalaxbot')

        bot.register_message_handler('pubmsg', self._collect_recent_message)
        bot.register_message_handler('action', self._collect_recent_message)
        bot.register_command(r'!?s/(.+/.*)', self._regex_command)
        bot.register_command(r'(?i)!caw($|\s.*)', self._caw_command)
        bot.register_command(r'(?i)!countdown($|\s.*)',
                             self._countdown_command)
        bot.register_command(r'(?i)!debugecho\s+(.*)',
                             self._debug_echo_command)
        bot.register_command(r'(?i)!double(team)?($|\s.*)',
                             self._double_command)
        bot.register_command(r'(?i)!(set)?greet(ing)?($|\s.*)$',
                             self._greeting_command)
        bot.register_command(r'(?i)!(groudonger)?(help|commands)($|\s.*)',
                             self._help_command)
        bot.register_command(r'(?i)!groudon(ger)?($|\s.*)', self._roar_command)
        bot.register_command(r'(?i)!huffle($|\s.*)', self._huffle_command)
        bot.register_command(r'(?i)!hypestats($|\s.*)',
                             self._hype_stats_command)
        bot.register_command(r'(?i)!klappa($|\s.*)', self._klappa_command)
        bot.register_command(r'(?i)!(mail|post)($|\s.*)$', self._mail_command)
        bot.register_command(r'(?i)!(mail|post)status($|\s.*)',
                             self._mail_status_command)
        bot.register_command(r'(?i)!mute($|\s.*)',
                             self._mute_command,
                             ignore_rate_limit=True)
        bot.register_command(r'(?i)!normalize($|\s.*)',
                             self._normalize_command)
        bot.register_command(r'(?i)!password\s+(.*)', self._password_command)
        bot.register_command(r'(?i)!pick\s+(.*)', self._pick_command)
        bot.register_command(r'(?i)!praise($|\s.{,100})$',
                             self._praise_command)
        bot.register_command(r'(?i)!schedule($|\s.*)', self._schedule_command)
        bot.register_command(r'(?i)!(word)?(?:shuffle|scramble)($|\s.*)',
                             self._shuffle_command)
        bot.register_command(r'(?i)!song($|\s.{,50})$', self._song_command)
        bot.register_command(r'(?i)!sort($|\s.*)', self._sort_command)
        bot.register_command(r'(?i)!spellchat(?:ot)?($|\s.*)',
                             self._spell_chatot_command)
        bot.register_command(r'(?i)!racc(?:attack)?($|\s\S*)',
                             self._raccattack_command)
        bot.register_command(r'(?i)!rand(?:om)?case($|\s.*)',
                             self._rand_case_command)
        bot.register_command(r'(?i)!release($|\s.{,100})$',
                             self._release_command)
        bot.register_command(r'(?i)!reverse($|\s.*)', self._reverse_command)
        bot.register_command(r'(?i)!riot($|\s.{,100})$', self._riot_command)
        bot.register_command(r'(?i)!rip($|\s.{,100})$', self._rip_command)
        bot.register_command(r'(?i)!roomsize?($|\s.*)',
                             self._room_size_command)
        bot.register_command(r'(?i)!gen(?:erate)?match($|\s.*)$',
                             self._generate_match_command)
        bot.register_command(r'(?i)!(xd|minglee)($|\s.*)', self._xd_command)
        # bot.register_command(r'(?i)!(set)?{}($|\s.*)'.format(username), self._username_command)
        # Temporary disabled. interferes with rate limit
        # bot.register_command(r'.*\b[xX][dD] +MingLee\b.*', self._xd_rand_command)
        bot.register_command(r'(?i)!(wow)($|\s.*)', self._wow_command)
        bot.register_command(
            r'(?i)(?:has )?(?:just )?donate(?:d|s)? [^0-9]{0,5}([0-9][0-9,.]*)',
            self._donation_trigger)

        bot.register_message_handler('join', self._join_callback)
        bot.register_message_handler('part', self._part_callback)

        self._reseed_rng_sched()
        self._token_notify_sched()
        self._discord_presence_sched()
コード例 #8
0
ファイル: features.py プロジェクト: chfoo/chatbot383
    def __init__(self, bot: Bot, help_text: str, database: Database, config: configparser.ConfigParser):
        self._bot = bot
        self._help_text = help_text
        self._database = database
        self._config = config
        self._recent_messages_for_regex = collections.defaultdict(lambda: collections.deque(maxlen=100))
        self._last_message = {}
        self._spam_limiter = Limiter(min_interval=10)
        self._user_list = collections.defaultdict(set)
        self._regex_server = RegexServer()
        self._token_notifier = TokenNotifier(
            config.get("token_notify_filename"),
            config.get("token_notify_channels"),
            config.get("token_notify_interval", 60),
        )
        self._tellnext_generator = None

        if os.path.isfile(config.get("tellnext_database", "")):
            self._tellnext_generator = TellnextGenerator(config["tellnext_database"])

        self._match_generator = None

        if os.path.isfile(config.get("veekun_pokedex_database", "")):
            self._match_generator = MatchGenerator(config["veekun_pokedex_database"])
            self._battlebot = BattleBot(config["veekun_pokedex_database"], self._bot)

            bot.register_message_handler("pubmsg", self._battlebot.message_callback)
            bot.register_message_handler("whisper", self._battlebot.message_callback)

        self._mail_disabled_channels = config.get("mail_disabled_channels")
        self._avoid_pikalaxbot = config.get("avoid_pikalaxbot")

        bot.register_message_handler("pubmsg", self._collect_recent_message)
        bot.register_message_handler("action", self._collect_recent_message)
        bot.register_command(r"s/(.+/.*)", self._regex_command)
        bot.register_command(r"(?i)!double(team)?($|\s.*)", self._double_command)
        bot.register_command(r"(?i)!(groudonger)?(help|commands)($|\s.*)", self._help_command)
        bot.register_command(r"(?i)!groudon(ger)?($|\s.*)", self._roar_command)
        bot.register_command(r"(?i)!hypestats($|\s.*)", self._hype_stats_command)
        bot.register_command(r"(?i)!klappa($|\s.*)", self._klappa_command)
        bot.register_command(r"(?i)!(mail|post)($|\s.*)$", self._mail_command)
        bot.register_command(r"(?i)!(mail|post)status($|\s.*)", self._mail_status_command)
        bot.register_command(r"(?i)!mute($|\s.*)", self._mute_command, ignore_rate_limit=True)
        bot.register_command(r"(?i)!pick\s+(.*)", self._pick_command)
        bot.register_command(r"(?i)!praise($|\s.{,100})$", self._praise_command)
        bot.register_command(r"(?i)!(word)?(?:shuffle|scramble)($|\s.*)", self._shuffle_command)
        bot.register_command(r"(?i)!song($|\s.{,50})$", self._song_command)
        bot.register_command(r"(?i)!sort($|\s.*)", self._sort_command)
        bot.register_command(r"(?i)!rand(?:om)?case($|\s.*)", self._rand_case_command)
        bot.register_command(r"(?i)!release($|\s.{,100})$", self._release_command)
        bot.register_command(r"(?i)!reverse($|\s.*)", self._reverse_command)
        bot.register_command(r"(?i)!riot($|\s.{,100})$", self._riot_command)
        bot.register_command(r"(?i)!rip($|\s.{,100})$", self._rip_command)
        bot.register_command(r"(?i)!roomsize?($|\s.*)", self._room_size_command)
        bot.register_command(r"(?i)!gen(?:erate)?match($|\s.*)$", self._generate_match_command)
        bot.register_command(r"(?i)!(xd|minglee)($|\s.*)", self._xd_command)
        # bot.register_command(r'(?i)!(set)?{}($|\s.*)'.format(username), self._username_command)
        # Temporary disabled. interferes with rate limit
        # bot.register_command(r'.*\b[xX][dD] +MingLee\b.*', self._xd_rand_command)
        bot.register_command(r"(?i)!(wow)($|\s.*)", self._wow_command)

        bot.register_message_handler("join", self._join_callback)
        bot.register_message_handler("part", self._part_callback)

        self._reseed_rng_sched()
        self._token_notify_sched()