当前位置: 首页>>代码示例>>Python>>正文


Python handler.HandlerManager类代码示例

本文整理汇总了Python中pajbot.models.handler.HandlerManager的典型用法代码示例。如果您正苦于以下问题:Python HandlerManager类的具体用法?Python HandlerManager怎么用?Python HandlerManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了HandlerManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: award_tokens

    def award_tokens(self, tokens, redis=None, force=False):
        """ Returns True if tokens were awarded properly.
        Returns False if not.
        Tokens can only be rewarded once per stream ID.
        """

        streamer = StreamHelper.get_streamer()
        stream_id = StreamHelper.get_current_stream_id()

        if stream_id is False:
            return False

        if redis is None:
            redis = RedisManager.get()

        key = '{streamer}:{username}:tokens'.format(
                streamer=streamer, username=self.username)

        if force:
            res = True
            redis.hset(key, stream_id, tokens)
        else:
            res = True if redis.hsetnx(key, stream_id, tokens) == 1 else False
            if res is True:
                HandlerManager.trigger('on_user_gain_tokens', self, tokens)
        return res
开发者ID:kyroskoh,项目名称:pajbot,代码行数:26,代码来源:user.py

示例2: enable

    def enable(self, bot):
        self.bot = bot
        HandlerManager.add_handler('on_message', self.on_message, priority=100)
        HandlerManager.add_handler('on_commit', self.on_commit)
        if bot:
            self.run_later = bot.execute_delayed

            if 'safebrowsingapi' in bot.config['main']:
                # XXX: This should be loaded as a setting instead.
                # There needs to be a setting for settings to have them as "passwords"
                # so they're not displayed openly
                self.safeBrowsingAPI = SafeBrowsingAPI(bot.config['main']['safebrowsingapi'], bot.nickname, bot.version)
            else:
                self.safeBrowsingAPI = None

        if self.db_session is not None:
            self.db_session.commit()
            self.db_session.close()
            self.db_session = None
        self.db_session = DBManager.create_session()
        self.blacklisted_links = []
        for link in self.db_session.query(BlacklistedLink):
            self.blacklisted_links.append(link)

        self.whitelisted_links = []
        for link in self.db_session.query(WhitelistedLink):
            self.whitelisted_links.append(link)
开发者ID:SanderVDA,项目名称:pajbot,代码行数:27,代码来源:linkchecker.py

示例3: command_start

    def command_start(self, **options):
        bot = options['bot']
        source = options['source']
        message = options['message']

        if self.trivia_running:
            bot.me('{}, a trivia is already running'.format(source.username_raw))
            return

        self.trivia_running = True
        self.job.resume()

        try:
            self.point_bounty = int(message)
            if self.point_bounty < 0:
                self.point_bounty = 0
            elif self.point_bounty > 50:
                self.point_bounty = 50
        except:
            self.point_bounty = self.settings['default_point_bounty']

        if self.point_bounty > 0:
            bot.me('The trivia has started! {} points for each right answer!'.format(self.point_bounty))
        else:
            bot.me('The trivia has started!')

        HandlerManager.add_handler('on_message', self.on_message)
开发者ID:coral,项目名称:pajbot,代码行数:27,代码来源:trivia.py

示例4: create_stream

    def create_stream(self, status):
        log.info('Attempting to create a stream!')
        with DBManager.create_session_scope(expire_on_commit=False) as db_session:
            stream_chunk = db_session.query(StreamChunk).filter_by(broadcast_id=status['broadcast_id']).one_or_none()
            new_stream = False
            if stream_chunk is not None:
                stream = stream_chunk.stream
            else:
                log.info('checking if there is an active stream already')
                stream = db_session.query(Stream).filter_by(ended=False).order_by(Stream.stream_start.desc()).first()
                new_stream = stream is None

                if new_stream:
                    log.info('No active stream, create new!')
                    stream = Stream(status['created_at'],
                            title=status['title'])
                    db_session.add(stream)
                    db_session.commit()
                    log.info('Successfully added stream!')
                stream_chunk = StreamChunk(stream, status['broadcast_id'], status['created_at'])
                db_session.add(stream_chunk)
                db_session.commit()
                stream.stream_chunks.append(stream_chunk)
                log.info('Created stream chunk')

            self.current_stream = stream
            self.current_stream_chunk = stream_chunk
            db_session.expunge_all()

            if new_stream:
                HandlerManager.trigger('on_stream_start', stop_on_false=False)

            log.info('Successfully created a stream')
开发者ID:kyroskoh,项目名称:pajbot,代码行数:33,代码来源:stream.py

示例5: stop_quest

    def stop_quest(self):
        HandlerManager.remove_handler("on_duel_complete", self.on_duel_complete)

        redis = RedisManager.get()

        self.reset_progress(redis=redis)
        redis.delete(self.points_required_key)
开发者ID:Cophy08,项目名称:pajbot,代码行数:7,代码来源:winduelpoints.py

示例6: roulette

    def roulette(self, **options):
        message = options['message']
        user = options['source']
        bot = options['bot']

        try:
            bet = int(message.split(' ')[0])
        except (ValueError, TypeError, AttributeError):
            bot.whisper(user.username, 'I didn\'t recognize your bet! Usage: !roulette 150 to bet 150 points')
            return False

        if bet > user.points:
            bot.whisper(user.username, 'You don\'t have enough points to do a roulette for {} points :('.format(bet))
            return False

        if bet < self.settings['min_roulette_amount']:
            bot.whisper(user.username, 'You have to bet at least {} point! :('.format(self.settings['min_roulette_amount']))
            return False

        # Calculating the result
        result = self.rigged_random_result()
        points = bet if result else -bet
        user.points += points

        if points > 0:
            bot.me('{0} won {1} points in roulette! FeelsGoodMan'.format(user.username_raw, bet))
        else:
            bot.me('{0} lost {1} points in roulette! FeelsBadMan'.format(user.username_raw, bet))

        HandlerManager.trigger('on_roulette_finish', user, points)
开发者ID:Cophy08,项目名称:pajbot,代码行数:30,代码来源:roulette.py

示例7: stop_quest

    def stop_quest(self):
        HandlerManager.remove_handler('on_message', self.on_message)

        redis = RedisManager.get()

        self.reset_progress(redis=redis)
        redis.delete(self.current_emote_key)
开发者ID:kyroskoh,项目名称:pajbot,代码行数:7,代码来源:typeemote.py

示例8: roulette

    def roulette(self, **options):
        message = options['message']
        user = options['source']
        bot = options['bot']

        try:
            bet = int(message.split(' ')[0])
        except (ValueError, TypeError, AttributeError):
            bot.me('Sorry, {0}, I didn\'t recognize your bet! FeelsBadMan'.format(user.username_raw))
            return False

        if bet > user.points:
            bot.me('Sorry, {0}, you don\'t have enough points! FeelsBadMan'.format(user.username_raw))
            return False

        if bet <= 0:
            bot.me('Sorry, {0}, you have to bet at least 1 point! FeelsBadMan'.format(user.username_raw))
            return False

        # Calculating the result
        result = self.rigged_random_result()
        points = bet if result else -bet
        user.points += points

        if points > 0:
            bot.me('{0} won {1} points in roulette! FeelsGoodMan'.format(user.username_raw, bet))
        else:
            bot.me('{0} lost {1} points in roulette! FeelsBadMan'.format(user.username_raw, bet))

        HandlerManager.trigger('on_roulette_finish', user, points)
开发者ID:ManikDV,项目名称:pajbot,代码行数:30,代码来源:roulette.py

示例9: start_quest

    def start_quest(self):
        HandlerManager.add_handler('on_duel_complete', self.on_duel_complete)

        redis = RedisManager.get()

        self.progress = {}
        old_progress = redis.hgetall(self.progress_key)
        for user, progress in old_progress.items():
            try:
                self.progress[user.decode('utf8')] = int(progress)
            except (TypeError, ValueError):
                pass

        self.points_required = redis.get(self.points_required_key)
        try:
            self.points_required = int(self.points_required)
        except (TypeError, ValueError):
            pass
        if self.points_required is None:
            try:
                self.points_required = random.randint(self.settings['min_value'], self.settings['max_value'] + 1)
            except ValueError:
                # someone fucked up
                self.points_required = 500
            redis.set(self.points_required_key, self.points_required)
开发者ID:SnackMcOgrelord,项目名称:pajbot,代码行数:25,代码来源:winduelpoints.py

示例10: stop_quest

    def stop_quest(self):
        HandlerManager.remove_handler('on_duel_complete', self.on_duel_complete)

        redis = RedisManager.get()

        redis.delete(self.progress_key)
        redis.delete(self.points_required_key)
开发者ID:SnackMcOgrelord,项目名称:pajbot,代码行数:7,代码来源:winduelpoints.py

示例11: start_quest

    def start_quest(self):
        HandlerManager.add_handler('on_message', self.on_message)

        redis = RedisManager.get()

        self.load_progress(redis=redis)
        self.load_data(redis=redis)
开发者ID:kyroskoh,项目名称:pajbot,代码行数:7,代码来源:typeemote.py

示例12: start_quest

    def start_quest(self):
        HandlerManager.add_handler('on_duel_complete', self.on_duel_complete)

        redis = RedisManager.get()

        self.load_progress(redis=redis)
        self.load_data(redis=redis)

        self.LIMIT = self.points_required
开发者ID:coral,项目名称:pajbot,代码行数:9,代码来源:winduelpoints.py

示例13: commit_all

    def commit_all(self):
        log.info('Commiting all...')
        for key, manager in self.commitable.items():
            log.info('Commiting {0}'.format(key))
            manager.commit()
            log.info('Done with {0}'.format(key))
        log.info('ok!')

        HandlerManager.trigger('on_commit', stop_on_false=False)
开发者ID:ManikDV,项目名称:pajbot,代码行数:9,代码来源:bot.py

示例14: paid_timeout

    def paid_timeout(self, **options):
        message = options['message']
        bot = options['bot']
        source = options['source']

        _time = self.settings['timeout_length']
        _cost = self.settings['cost']

        if message is None or len(message) == 0:
            return False

        username = message.split(' ')[0]
        if len(username) < 2:
            return False

        victim = bot.users.find(username)
        if victim is None:
            bot.whisper(source.username, 'This user does not exist FailFish')
            return False

        """
        if victim == source:
            bot.whisper(source.username, 'You can\'t timeout yourself FailFish')
            return False
            """

        if victim.moderator is True:
            bot.whisper(source.username, 'This person has mod privileges, timeouting this person is not worth it.')
            return False

        if victim.level >= self.settings['bypass_level']:
            bot.whisper(source.username, 'This person\'s user level is too high, you can\'t timeout this person.')
            return False

        now = datetime.datetime.now()
        if victim.timed_out is True and victim.timeout_end > now:
            victim.timeout_end += datetime.timedelta(seconds=_time)
            bot.whisper(victim.username, '{victim.username}, you were timed out for an additional {time} seconds by {source.username}'.format(
                victim=victim,
                source=source,
                time=_time))
            bot.whisper(source.username, 'You just used {0} points to time out {1} for an additional {2} seconds.'.format(_cost, username, _time))
            num_seconds = int((victim.timeout_end - now).total_seconds())
            bot._timeout(username, num_seconds)
        else:
            bot.whisper(source.username, 'You just used {0} points to time out {1} for {2} seconds.'.format(_cost, username, _time))
            bot.whisper(username, '{0} just timed you out for {1} seconds. /w {2} !$unbanme to unban yourself for points forsenMoney'.format(source.username, _time, bot.nickname))
            bot._timeout(username, _time)
            victim.timed_out = True
            victim.timeout_start = now
            victim.timeout_end = now + datetime.timedelta(seconds=_time)

        payload = {'user': source.username, 'victim': victim.username}
        bot.websocket_manager.emit('timeout', payload)
        HandlerManager.trigger('on_paid_timeout',
                source, victim, _cost,
                stop_on_false=False)
开发者ID:SanderVDA,项目名称:pajbot,代码行数:57,代码来源:paidtimeout.py

示例15: disable

    def disable(self, bot):
        HandlerManager.remove_handler('on_message', self.on_message)
        HandlerManager.remove_handler('on_commit', self.on_commit)

        if self.db_session is not None:
            self.db_session.commit()
            self.db_session.close()
            self.db_session = None
            self.links = {}
开发者ID:kzf,项目名称:pajbot,代码行数:9,代码来源:linktracker.py


注:本文中的pajbot.models.handler.HandlerManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。