Ejemplo n.º 1
0
    def run(self, bot, source, message, event={}, args={}):
        resp = self.get_response(bot, self.get_extra_data(source, message, args))

        if not resp:
            return False

        if irc.client.is_channel(event.target):
            if self.num_urlfetch_subs == 0:
                return bot.say(resp, channel=event.target)
            else:
                return ScheduleManager.execute_now(urlfetch_msg,
                        args=[],
                        kwargs={
                            'args': [],
                            'kwargs': {
                                'channel': event.target
                                },
                            'method': bot.say,
                            'message': resp,
                            'num_urlfetch_subs': self.num_urlfetch_subs,
                            })
        else:
            if self.num_urlfetch_subs == 0:
                return bot.whisper(source.username, resp)
            else:
                return ScheduleManager.execute_now(urlfetch_msg,
                        args=[],
                        kwargs={
                            'args': [source.username],
                            'kwargs': {},
                            'method': bot.whisper,
                            'message': resp,
                            'num_urlfetch_subs': self.num_urlfetch_subs,
                            })
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    def pleblist_add_song(self, bot, source, message, **rest):
        if not message:
            return False

        # 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, "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, "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, bot, source])
Ejemplo n.º 4
0
    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
            bot.whisper(source.username, 'You don\'t have a high enough access level to use this command. If you think you are supposed to, ' \
                                         'contact DatGuy1/Darth_Henry/AdmiralBulldog')
            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
            bot.whisper(source.username, 'You can\'t use this command in whispers you baboon')
            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.
            bot.whisper(source.username, 'This is a sub only 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):
            if self.notify_on_error:
                bot.whisper(source.username, 'You do not have the required {} points to execute this command. (You have {} points)'.format(self.cost, source.points_available()))
            # 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):
            if self.notify_on_error:
                bot.whisper(source.username, 'You do not have the required {} tokens to execute this command. (You have {} tokens)'.format(self.tokens_cost, source.tokens))
            # 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)
Ejemplo n.º 5
0
    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 not self.can_run_command(source, whisper):
            return False

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

        cur_time = pajbot.utils.now().timestamp()
        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(
                f"Command was run {time_since_last_run:.2f} seconds ago, waiting..."
            )
            return False

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

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

        if self.cost > 0 and not source.can_afford(self.cost):
            if self.notify_on_error:
                bot.whisper(
                    source,
                    f"You do not have the required {self.cost} points to execute this command. (You have {source.points} points)",
                )
            # 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):
            if self.notify_on_error:
                bot.whisper(
                    source,
                    f"You do not have the required {self.tokens_cost} tokens to execute this command. (You have {source.tokens} tokens)",
                )
            # User does not have enough tokens to use the command
            return False

        args.update(self.extra_args)
        if self.run_in_thread:
            log.debug(f"Running {self} in a thread")
            ScheduleManager.execute_now(
                self.run_action, args=[bot, source, message, event, args])
        else:
            self.run_action(bot, source, message, event, args)

        return True
Ejemplo n.º 6
0
 def __init__(self, bot, token):
     self.bot = bot
     self.token = token
     self.sent_ping = False
     self.websocket = None
     self.ping_schedule = ScheduleManager.execute_every(
         60, self.ping_server)
     self.check_connection_schedule = ScheduleManager.execute_every(
         30, self.check_connection)
     ScheduleManager.execute_now(self.check_connection)
Ejemplo n.º 7
0
    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):
            if self.notify_on_error:
                bot.whisper(source.username, 'You do not have the required {} points to execute this command. (You have {} points)'.format(self.cost, source.points_available()))
            # 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):
            if self.notify_on_error:
                bot.whisper(source.username, 'You do not have the required {} tokens to execute this command. (You have {} tokens)'.format(self.tokens_cost, source.tokens))
            # 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)
Ejemplo n.º 8
0
    def enable(self, bot):
        # Web interface, nothing to do
        if not bot:
            return

        ScheduleManager.execute_now(
            lambda: self.bot.action_queue.submit(self._update_subscribers))
        # every 10 minutes, add the subscribers update to the action queue
        ScheduleManager.execute_every(
            10 * 60,
            lambda: self.bot.action_queue.submit(self._update_subscribers))
Ejemplo n.º 9
0
    def run(self, bot, source, message, event={}, args={}):
        extra = self.get_extra_data(source, message, args)
        resp = self.get_response(bot, extra)

        if not resp:
            return False

        if irc.client.is_channel(event.target):
            if self.num_urlfetch_subs == 0:
                return bot.say(resp, channel=event.target)
            else:
                return ScheduleManager.execute_now(urlfetch_msg,
                                                   args=[],
                                                   kwargs={
                                                       'args': [],
                                                       'kwargs': {
                                                           'channel':
                                                           event.target
                                                       },
                                                       'method':
                                                       bot.say,
                                                       'bot':
                                                       bot,
                                                       'extra':
                                                       extra,
                                                       'message':
                                                       resp,
                                                       'num_urlfetch_subs':
                                                       self.num_urlfetch_subs,
                                                   })
        else:
            if self.num_urlfetch_subs == 0:
                return bot.whisper(source.username, resp)
            else:
                return ScheduleManager.execute_now(urlfetch_msg,
                                                   args=[],
                                                   kwargs={
                                                       'args':
                                                       [source.username],
                                                       'kwargs': {},
                                                       'method':
                                                       bot.whisper,
                                                       'bot':
                                                       bot,
                                                       'extra':
                                                       extra,
                                                       'message':
                                                       resp,
                                                       'num_urlfetch_subs':
                                                       self.num_urlfetch_subs,
                                                   })
Ejemplo n.º 10
0
 def run(self, bot, source, message, event={}, args={}):
     resp = self.get_response(bot, self.get_extra_data(source, message, args))
     if resp:
         if self.num_urlfetch_subs == 0:
             bot.whisper(source.username, resp)
         else:
             ScheduleManager.execute_now(urlfetch_msg,
                     args=[],
                     kwargs={
                         'args': [source.username],
                         'kwargs': {},
                         'method': bot.whisper,
                         'message': resp,
                         'num_urlfetch_subs': self.num_urlfetch_subs,
                         })
Ejemplo n.º 11
0
    def run(self, bot, source, message, event={}, args={}):
        extra = self.get_extra_data(source, message, args)
        resp = self.get_response(bot, extra)

        if not resp:
            return False

        if self.num_urlfetch_subs == 0:
            return bot.me(resp)
        else:
            return ScheduleManager.execute_now(urlfetch_msg,
                                               args=[],
                                               kwargs={
                                                   'args': [],
                                                   'kwargs': {},
                                                   'method':
                                                   bot.me,
                                                   'bot':
                                                   bot,
                                                   'extra':
                                                   extra,
                                                   'message':
                                                   resp,
                                                   'num_urlfetch_subs':
                                                   self.num_urlfetch_subs,
                                               })
Ejemplo n.º 12
0
    def command_stop_bet(self, bot, message, **rest):
        reason = message if message else "No reason given EleGiggle"
        with DBManager.create_session_scope() as db_session:
            current_game = self.get_current_game(db_session,
                                                 with_bets=True,
                                                 with_users=True)
            for bet in current_game.bets:
                bet.user.points = User.points + bet.points
                bot.whisper(
                    bet.user,
                    f"Your {bet.points} points bet has been refunded. The reason given is: '{reason}'"
                )

                db_session.delete(bet)

            db_session.delete(current_game)

        self.spectating = False
        if self.close_schedule:
            try:
                self.close_schedule.remove()
            except:
                pass
        self.close_schedule = ScheduleManager.execute_now(
            self.bot.websocket_manager.emit,
            args=["bet_close_game", WIDGET_ID])

        bot.me("All your bets have been refunded and betting has been closed.")
Ejemplo n.º 13
0
 def run(self, bot, source, message, event={}, args={}):
     resp = self.get_response(bot,
                              self.get_extra_data(source, message, args))
     if resp:
         if self.num_urlfetch_subs == 0:
             bot.whisper(source.username, resp)
         else:
             ScheduleManager.execute_now(urlfetch_msg,
                                         args=[],
                                         kwargs={
                                             'args': [source.username],
                                             'kwargs': {},
                                             'method':
                                             bot.whisper,
                                             'message':
                                             resp,
                                             'num_urlfetch_subs':
                                             self.num_urlfetch_subs,
                                         })
Ejemplo n.º 14
0
    def run(self, bot, source, message, event={}, args={}):
        extra = self.get_extra_data(source, message, args)
        resp = self.get_response(bot, extra)

        if not resp:
            return False

        if irc.client.is_channel(event.target):
            if self.num_urlfetch_subs == 0:
                return bot.say(resp, channel=event.target)

            return ScheduleManager.execute_now(
                urlfetch_msg,
                args=[],
                kwargs={
                    "args": [],
                    "kwargs": {
                        "channel": event.target
                    },
                    "method": bot.say,
                    "bot": bot,
                    "extra": extra,
                    "message": resp,
                    "num_urlfetch_subs": self.num_urlfetch_subs,
                },
            )

        if self.num_urlfetch_subs == 0:
            return bot.whisper(source, resp)

        return ScheduleManager.execute_now(
            urlfetch_msg,
            args=[],
            kwargs={
                "args": [source],
                "kwargs": {},
                "method": bot.whisper,
                "bot": bot,
                "extra": extra,
                "message": resp,
                "num_urlfetch_subs": self.num_urlfetch_subs,
            },
        )
Ejemplo n.º 15
0
 def on_message(self, ws, message):
     msg = json.loads(message)
     if msg["type"].lower() == "pong":
         self.sent_ping = False
     elif msg["type"].lower() == "reconnect":
         ScheduleManager.execute_now(self.reset)
     elif msg["type"].lower() == "message":
         if msg["data"][
                 "topic"] == "channel-bits-events-v2." + self.bot.streamer_user_id:
             messageR = json.loads(msg["data"]["message"])
             user_id_of_cheer = str(messageR["data"]["user_id"])
             bits_cheered = str(messageR["data"]["bits_used"])
             with DBManager.create_session_scope() as db_session:
                 user = User.find_by_id(db_session, user_id_of_cheer)
                 if user is not None:
                     HandlerManager.trigger("on_cheer",
                                            True,
                                            user=user,
                                            bits_cheered=bits_cheered)
Ejemplo n.º 16
0
    def run(self, bot, source, message, event={}, args={}):
        extra = self.get_extra_data(source, message, args)
        resp = self.get_response(bot, extra)

        if not resp:
            return False

        if irc.client.is_channel(event.target):
            if self.num_urlfetch_subs == 0:
                return bot.say(resp, channel=event.target)
            else:
                return ScheduleManager.execute_now(
                    urlfetch_msg,
                    args=[],
                    kwargs={
                        "args": [],
                        "kwargs": {"channel": event.target},
                        "method": bot.say,
                        "bot": bot,
                        "extra": extra,
                        "message": resp,
                        "num_urlfetch_subs": self.num_urlfetch_subs,
                    },
                )
        else:
            if self.num_urlfetch_subs == 0:
                return bot.whisper(source.username, resp)
            else:
                return ScheduleManager.execute_now(
                    urlfetch_msg,
                    args=[],
                    kwargs={
                        "args": [source.username],
                        "kwargs": {},
                        "method": bot.whisper,
                        "bot": bot,
                        "extra": extra,
                        "message": resp,
                        "num_urlfetch_subs": self.num_urlfetch_subs,
                    },
                )
Ejemplo n.º 17
0
    def run(self, bot, source, message, event={}, args={}):
        resp = self.get_response(bot, self.get_extra_data(source, message, args))

        if not resp:
            return False

        if self.num_urlfetch_subs == 0:
            return bot.me(resp)
        else:
            return ScheduleManager.execute_now(urlfetch_msg,
                    args=[],
                    kwargs={
                        'args': [],
                        'kwargs': {},
                        'method': bot.me,
                        'message': resp,
                        'num_urlfetch_subs': self.num_urlfetch_subs,
                        })
Ejemplo n.º 18
0
    def run(self, bot, source, message, event={}, args={}):
        extra = self.get_extra_data(source, message, args)
        resp = self.get_response(bot, extra)

        if not resp:
            return False

        if self.num_urlfetch_subs == 0:
            return bot.whisper(source.username, resp)
        else:
            return ScheduleManager.execute_now(urlfetch_msg,
                    args=[],
                    kwargs={
                        'args': [source.username],
                        'kwargs': {},
                        'method': bot.whisper,
                        'bot': bot,
                        'extra': extra,
                        'message': resp,
                        'num_urlfetch_subs': self.num_urlfetch_subs,
                        })
Ejemplo n.º 19
0
    def run(self, bot, source, message, event={}, args={}):
        extra = self.get_extra_data(source, message, args)
        resp = self.get_response(bot, extra)

        if not resp:
            return False

        if self.num_urlfetch_subs == 0:
            return bot.me(resp)

        return ScheduleManager.execute_now(
            urlfetch_msg,
            args=[],
            kwargs={
                "args": [],
                "kwargs": {},
                "method": bot.me,
                "bot": bot,
                "extra": extra,
                "message": resp,
                "num_urlfetch_subs": self.num_urlfetch_subs,
            },
        )
Ejemplo n.º 20
0
    def run(self, bot, source, message, event={}, args={}):
        extra = self.get_extra_data(source, message, args)
        resp = self.get_response(bot, extra)

        if not resp:
            return False

        if self.num_urlfetch_subs == 0:
            return bot.me(resp)
        else:
            return ScheduleManager.execute_now(
                urlfetch_msg,
                args=[],
                kwargs={
                    "args": [],
                    "kwargs": {},
                    "method": bot.me,
                    "bot": bot,
                    "extra": extra,
                    "message": resp,
                    "num_urlfetch_subs": self.num_urlfetch_subs,
                },
            )
Ejemplo n.º 21
0
    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 = pajbot.utils.now().timestamp()
        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):
            if self.notify_on_error:
                bot.whisper(
                    source.username,
                    "You do not have the required {} points to execute this command. (You have {} points)"
                    .format(self.cost, source.points_available()),
                )
            # 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):
            if self.notify_on_error:
                bot.whisper(
                    source.username,
                    "You do not have the required {} tokens to execute this command. (You have {} tokens)"
                    .format(self.tokens_cost, source.tokens),
                )
            # 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)

        return True
Ejemplo n.º 22
0
 def check_ping(self):
     if self.sent_ping:
         log.error("Pubsub connection timed out")
         ScheduleManager.execute_now(self.reset)