コード例 #1
0
ファイル: pleblist.py プロジェクト: Nacht123/pajbot
    def pleblist_add_song(self, **options):
        message = options['message']
        bot = options['bot']
        source = options['source']

        if message:
            # 1. Find youtube ID in message
            msg_split = message.split(' ')
            youtube_id = find_youtube_id_in_string(msg_split[0])

            force = False

            try:
                if msg_split[1] == 'force' and source.level >= 500:
                    force = True
            except:
                pass

            if youtube_id is False:
                bot.whisper(source.username, 'Could not find a valid youtube ID in your argument.')
                return False

            # 2. Make sure the stream is live
            stream_id = StreamHelper.get_current_stream_id()
            if stream_id is None or stream_id is False:
                bot.whisper(source.username, 'You cannot request songs while the stream is offline.')
                return False

            ScheduleManager.execute_now(self.bg_pleblist_add_song, args=[stream_id, youtube_id, force], kwargs=options)
コード例 #2
0
ファイル: command.py プロジェクト: TalVivian/pajbot
    def run(self, bot, source, message, event={}, args={}, whisper=False):
        if self.action is None:
            log.warning('This command is not available.')
            return False

        if source.level < self.level:
            # User does not have a high enough power level to run this command
            return False

        if whisper and self.can_execute_with_whisper is False and source.level < Command.MIN_WHISPER_LEVEL and source.moderator is False:
            # This user cannot execute the command through a whisper
            return False

        if self.sub_only and source.subscriber is False and source.level < Command.BYPASS_SUB_ONLY_LEVEL and source.moderator is False:
            # User is not a sub or a moderator, and cannot use the command.
            return False

        if self.mod_only and source.moderator is False and source.level < Command.BYPASS_MOD_ONLY_LEVEL:
            # User is not a twitch moderator, or a bot moderator
            return False

        cd_modifier = 0.2 if source.level >= 500 or source.moderator is True else 1.0

        cur_time = time.time()
        time_since_last_run = (cur_time - self.last_run) / cd_modifier

        if time_since_last_run < self.delay_all and source.level < Command.BYPASS_DELAY_LEVEL:
            log.debug('Command was run {0:.2f} seconds ago, waiting...'.format(
                time_since_last_run))
            return False

        time_since_last_run_user = (cur_time - self.last_run_by_user.get(
            source.username, 0)) / cd_modifier

        if time_since_last_run_user < self.delay_user and source.level < Command.BYPASS_DELAY_LEVEL:
            log.debug('{0} ran command {1:.2f} seconds ago, waiting...'.format(
                source.username, time_since_last_run_user))
            return False

        if self.cost > 0 and not source.can_afford(self.cost):
            # User does not have enough points to use the command
            return False

        if self.tokens_cost > 0 and not source.can_afford_with_tokens(
                self.tokens_cost):
            # User does not have enough tokens to use the command
            return False

        args.update(self.extra_args)
        if self.run_in_thread:
            log.debug('Running {} in a thread'.format(self))
            ScheduleManager.execute_now(
                self.run_action, args=[bot, source, message, event, args])
        else:
            self.run_action(bot, source, message, event, args)
コード例 #3
0
ファイル: command.py プロジェクト: Nacht123/pajbot
    def run(self, bot, source, message, event={}, args={}, whisper=False):
        if self.action is None:
            log.warning('This command is not available.')
            return False

        if source.level < self.level:
            # User does not have a high enough power level to run this command
            return False

        if whisper and self.can_execute_with_whisper is False and source.level < Command.MIN_WHISPER_LEVEL and source.moderator is False:
            # This user cannot execute the command through a whisper
            return False

        if self.sub_only and source.subscriber is False and source.level < Command.BYPASS_SUB_ONLY_LEVEL and source.moderator is False:
            # User is not a sub or a moderator, and cannot use the command.
            return False

        if self.mod_only and source.moderator is False and source.level < Command.BYPASS_MOD_ONLY_LEVEL:
            # User is not a twitch moderator, or a bot moderator
            return False

        cd_modifier = 0.2 if source.level >= 500 or source.moderator is True else 1.0

        cur_time = time.time()
        time_since_last_run = (cur_time - self.last_run) / cd_modifier

        if time_since_last_run < self.delay_all and source.level < Command.BYPASS_DELAY_LEVEL:
            log.debug('Command was run {0:.2f} seconds ago, waiting...'.format(time_since_last_run))
            return False

        time_since_last_run_user = (cur_time - self.last_run_by_user.get(source.username, 0)) / cd_modifier

        if time_since_last_run_user < self.delay_user and source.level < Command.BYPASS_DELAY_LEVEL:
            log.debug('{0} ran command {1:.2f} seconds ago, waiting...'.format(source.username, time_since_last_run_user))
            return False

        if self.cost > 0 and not source.can_afford(self.cost):
            # User does not have enough points to use the command
            return False

        if self.tokens_cost > 0 and not source.can_afford_with_tokens(self.tokens_cost):
            # User does not have enough tokens to use the command
            return False

        args.update(self.extra_args)
        if self.run_in_thread:
            log.debug('Running {} in a thread'.format(self))
            ScheduleManager.execute_now(self.run_action, args=[bot, source, message, event, args])
        else:
            self.run_action(bot, source, message, event, args)
コード例 #4
0
ファイル: pleblist.py プロジェクト: TalVivian/pajbot
    def pleblist_add_song(self, **options):
        message = options['message']
        bot = options['bot']
        source = options['source']

        if message:
            # 1. Find youtube ID in message
            msg_split = message.split(' ')
            youtube_id = find_youtube_id_in_string(msg_split[0])

            if youtube_id is False:
                bot.whisper(source.username, 'Could not find a valid youtube ID in your argument.')
                return False

            # 2. Make sure the stream is live
            stream_id = StreamHelper.get_current_stream_id()
            if stream_id is None or stream_id is False:
                bot.whisper(source.username, 'You cannot request songs while the stream is offline.')
                return False

            ScheduleManager.execute_now(self.bg_pleblist_add_song, args=[stream_id, youtube_id], kwargs=options)