コード例 #1
0
ファイル: bot.py プロジェクト: TroyDota/pajbot
 def apply_filter(self, resp, f: SubstitutionFilter) -> Any:
     available_filters: dict[str, Callable[[Any, List[str]], Any]] = {
         "strftime": _filter_strftime,
         "lower": lambda var, args: var.lower(),
         "upper": lambda var, args: var.upper(),
         "title": lambda var, args: var.title(),
         "capitalize": lambda var, args: var.capitalize(),
         "swapcase": lambda var, args: var.swapcase(),
         "time_since_minutes": lambda var, args: "no time"
         if var == 0
         else utils.time_since(var * 60, 0, time_format="long"),
         "time_since": lambda var, args: "no time" if var == 0 else utils.time_since(var, 0, time_format="long"),
         "time_since_dt": _filter_time_since_dt,
         "timedelta_days": _filter_timedelta_days,
         "urlencode": _filter_urlencode,
         "join": _filter_join,
         "number_format": _filter_number_format,
         "add": _filter_add,
         "or_else": _filter_or_else,
         "or_broadcaster": self._filter_or_broadcaster,
         "or_streamer": self._filter_or_broadcaster,
         "slice": _filter_slice,
         "subtract": _filter_subtract,
         "multiply": _filter_multiply,
         "divide": _filter_divide,
         "floor": _filter_floor,
         "ceil": _filter_ceil,
     }
     if f.name in available_filters:
         return available_filters[f.name](resp, f.arguments)
     return resp
コード例 #2
0
ファイル: bot.py プロジェクト: mikuski08/pajbot
 def apply_filter(self, resp, f):
     available_filters = {
         "strftime": _filter_strftime,
         "lower": lambda var, args: var.lower(),
         "upper": lambda var, args: var.upper(),
         "title": lambda var, args: var.title(),
         "capitalize": lambda var, args: var.capitalize(),
         "swapcase": lambda var, args: var.swapcase(),
         "time_since_minutes": lambda var, args: "no time"
         if var == 0
         else utils.time_since(var * 60, 0, time_format="long"),
         "time_since": lambda var, args: "no time" if var == 0 else utils.time_since(var, 0, time_format="long"),
         "time_since_dt": _filter_time_since_dt,
         "urlencode": _filter_urlencode,
         "join": _filter_join,
         "number_format": _filter_number_format,
         "add": _filter_add,
         "or_else": _filter_or_else,
         "or_broadcaster": self._filter_or_broadcaster,
         "or_streamer": self._filter_or_broadcaster,
         "slice": _filter_slice,
     }
     if f.name in available_filters:
         return available_filters[f.name](resp, f.arguments)
     return resp
コード例 #3
0
ファイル: bot.py プロジェクト: flipsy/pajbot
 def apply_filter(self, resp, filter):
     available_filters = {
         'strftime':
         _filter_strftime,
         'lower':
         lambda var, args: var.lower(),
         'upper':
         lambda var, args: var.upper(),
         'time_since_minutes':
         lambda var, args: 'no time'
         if var == 0 else time_since(var * 60, 0, format='long'),
         'time_since':
         lambda var, args: 'no time'
         if var == 0 else time_since(var, 0, format='long'),
         'time_since_dt':
         _filter_time_since_dt,
         'urlencode':
         _filter_urlencode,
         'join':
         _filter_join,
         'number_format':
         _filter_number_format,
     }
     if filter.name in available_filters:
         return available_filters[filter.name](resp, filter.arguments)
     return resp
コード例 #4
0
 def apply_filter(resp, f):
     available_filters = {
         "strftime":
         _filter_strftime,
         "lower":
         lambda var, args: var.lower(),
         "upper":
         lambda var, args: var.upper(),
         "time_since_minutes":
         lambda var, args: "no time"
         if var == 0 else time_since(var * 60, 0, time_format="long"),
         "time_since":
         lambda var, args: "no time"
         if var == 0 else time_since(var, 0, time_format="long"),
         "time_since_dt":
         _filter_time_since_dt,
         "urlencode":
         _filter_urlencode,
         "join":
         _filter_join,
         "number_format":
         _filter_number_format,
         "add":
         _filter_add,
     }
     if f.name in available_filters:
         return available_filters[f.name](resp, f.arguments)
     return resp
コード例 #5
0
ファイル: bot.py プロジェクト: jardg/pajbot
 def c_status_length(self):
     if self.stream_manager.online:
         return time_since(time.time(), self.stream_manager.current_stream.stream_start.timestamp())
     else:
         if self.stream_manager.last_stream is not None:
             return time_since(time.time(), self.stream_manager.last_stream.stream_end.timestamp())
         else:
             return 'No recorded stream FeelsBadMan '
コード例 #6
0
ファイル: bot.py プロジェクト: damngamerz/bullbot
 def c_status_length(self):
     if self.stream_manager.online:
         return time_since(time.time(), self.stream_manager.current_stream.stream_start.timestamp())
     else:
         if self.stream_manager.last_stream is not None:
             return time_since(time.time(), self.stream_manager.last_stream.stream_end.timestamp())
         else:
             return 'No recorded stream FeelsBadMan '
コード例 #7
0
ファイル: bot.py プロジェクト: jardg/pajbot
 def apply_filter(self, resp, filter):
     available_filters = {
             'strftime': _filter_strftime,
             'lower': lambda var, args: var.lower(),
             'upper': lambda var, args: var.upper(),
             'time_since_minutes': lambda var, args: 'no time' if var == 0 else time_since(var * 60, 0, format='long'),
             'time_since': lambda var, args: 'no time' if var == 0 else time_since(var, 0, format='long'),
             'time_since_dt': _filter_time_since_dt,
             'urlencode': _filter_urlencode,
             'join': _filter_join,
             'number_format': _filter_number_format,
             }
     if filter.name in available_filters:
         return available_filters[filter.name](resp, filter.arguments)
     return resp
コード例 #8
0
ファイル: twitter.py プロジェクト: galoncyryll/pajbot
    def get_last_tweet(self, username):
        if self.twitter_client:
            try:
                public_tweets = self.twitter_client.user_timeline(username)
                for tweet in public_tweets:
                    if not tweet.text.startswith(
                            "RT ") and tweet.in_reply_to_screen_name is None:
                        tw = tweet_prettify_urls(tweet)
                        # Tweepy returns naive datetime object (but it's always UTC)
                        # .replace() makes it timezone-aware :)
                        created_at = tweet.created_at.replace(
                            tzinfo=datetime.timezone.utc)
                        return "{0} ({1} ago)".format(
                            tw.replace("\n", " "),
                            time_since(utils.now().timestamp(),
                                       created_at.timestamp(),
                                       time_format="short"),
                        )
            except Exception:
                log.exception("Exception caught while getting last tweet")
                return "FeelsBadMan"
        else:
            return "Twitter not set up FeelsBadMan"

        return "FeelsBadMan"
コード例 #9
0
    def check_follow_age(self, bot, source, username, streamer, event):
        streamer = bot.streamer if streamer is None else streamer.lower()
        age = bot.twitchapi.get_follow_relationship(username, streamer)
        is_self = source.username == username
        message = ''

        if age:
            # Following
            human_age = time_since(
                datetime.datetime.now().timestamp() - age.timestamp(), 0)
            suffix = 'been following {} for {}'.format(streamer, human_age)
            if is_self:
                message = 'You have ' + suffix
            else:
                message = username + ' has ' + suffix
        else:
            # Not following
            suffix = 'not following {}'.format(streamer)
            if is_self:
                message = 'You are ' + suffix
            else:
                message = username + ' is ' + suffix

        bot.send_message_to_user(source,
                                 message,
                                 event,
                                 method=self.settings['action_followage'])
コード例 #10
0
ファイル: bot.py プロジェクト: jardg/pajbot
def _filter_time_since_dt(var, args):
    try:
        ts = time_since(datetime.datetime.now().timestamp(), var.timestamp())
        if len(ts) > 0:
            return ts
        else:
            return '0 seconds'
    except:
        return 'never FeelsBadMan ?'
コード例 #11
0
def _filter_time_until_dt(var: Any, args: List[str]) -> Any:
    try:
        ts = utils.time_since(var.timestamp(), utils.now().timestamp())
        if ts:
            return ts

        return "0 seconds"
    except:
        return "never FeelsBadMan ?"
コード例 #12
0
ファイル: bot.py プロジェクト: damngamerz/bullbot
def _filter_time_since_dt(var, args):
    try:
        ts = time_since(datetime.datetime.now().timestamp(), var.timestamp())
        if len(ts) > 0:
            return ts
        else:
            return '0 seconds'
    except:
        return 'never FeelsBadMan ?'
コード例 #13
0
ファイル: bot.py プロジェクト: mikuski08/pajbot
def _filter_time_since_dt(var, args):
    try:
        ts = utils.time_since(utils.now().timestamp(), var.timestamp())
        if ts:
            return ts

        return "0 seconds"
    except:
        return "never FeelsBadMan ?"
コード例 #14
0
    def top_watchers(self, **options):
        bot = options["bot"]

        data = []
        with DBManager.create_session_scope() as db_session:
            for user in db_session.query(User).order_by(User.minutes_in_chat_online.desc())[: self.settings["num_top"]]:
                data.append(
                    "{user.username_raw} ({time_spent})".format(
                        user=user, time_spent=time_since(user.minutes_in_chat_online * 60, 0, time_format="short")
                    )
                )

        bot.say("Top {num_top} watchers: {data}".format(num_top=self.settings["num_top"], data=", ".join(data)))
コード例 #15
0
    def check_follow_age(self, bot, source, username, streamer, event):
        streamer = bot.streamer if streamer is None else streamer.lower()
        age = bot.twitchapi.get_follow_relationship(username, streamer)
        message = ''

        if age:
            # Following
            human_age = time_since(datetime.datetime.now().timestamp() - age.timestamp(), 0)
            message = '{} has been following {} for {}'.format(username, streamer, human_age)
        else:
            # Not following
            message = '{} is not following {}'.format(username, streamer)

        bot.send_message_to_user(source, message, event, method=self.settings['action_followage'])
コード例 #16
0
 def check_follow_age(self, bot, source, username, streamer):
     streamer = bot.streamer if streamer is None else streamer.lower()
     age = bot.twitchapi.get_follow_relationship(username, streamer)
     if source.username == username:
         if age is False:
             bot.say('{}, you are not following {}'.format(
                 source.username_raw, streamer))
         else:
             bot.say('{}, you have been following {} for {}'.format(
                 source.username_raw, streamer,
                 time_since(
                     datetime.datetime.now().timestamp() - age.timestamp(),
                     0)))
     else:
         if age is False:
             bot.say('{}, {} is not following {}'.format(
                 source.username_raw, username, streamer))
         else:
             bot.say('{}, {} has been following {} for {}'.format(
                 source.username_raw, username, streamer,
                 time_since(
                     datetime.datetime.now().timestamp() - age.timestamp(),
                     0)))
コード例 #17
0
ファイル: twitter.py プロジェクト: nuuls/pajbot
    def get_last_tweet(self, username):
        if self.twitter_client:
            try:
                public_tweets = self.twitter_client.user_timeline(username)
                for tweet in public_tweets:
                    if not tweet.text.startswith('RT ') and tweet.in_reply_to_screen_name is None:
                        tw = tweet_prettify_urls(tweet)
                        return '{0} ({1} ago)'.format(tw.replace('\n', ' '), time_since(datetime.now().timestamp(), tweet.created_at.timestamp(), format='short'))
            except Exception:
                log.exception('Exception caught while getting last tweet')
                return 'FeelsBadMan'
        else:
            return 'Twitter not set up FeelsBadMan'

        return 'FeelsBadMan'
コード例 #18
0
ファイル: followage.py プロジェクト: streptocarcus/bullbot
    def check_follow_age(self, bot, source, username, streamer, event):
        streamer = bot.streamer if streamer is None else streamer.lower()
        age = bot.twitchapi.get_follow_relationship(username, streamer)
        is_self = source.username == username
        message = ""
        streamer = streamer.replace('admiralbulldog', 'Buldog')

        if age:
            # Following
            human_age = time_since(utils.now().timestamp() - age.timestamp(), 0)
            message = "{} has been following {} for {}".format(username, streamer, human_age)
        else:
            # Not following
            message = "{} is not following {}".format(username, streamer)

        bot.send_message_to_user(source, message, event, method=self.settings["action_followage"])
コード例 #19
0
ファイル: top.py プロジェクト: wijayantoap/bullbot
    def top_offline(self, **options):
        bot = options['bot']

        data = []
        with DBManager.create_session_scope() as db_session:
            for user in db_session.query(User).order_by(
                    User.minutes_in_chat_offline.desc())[:self.
                                                         settings['num_top']]:
                data.append('{user.username_raw} ({time_spent})'.format(
                    user=user,
                    time_spent=time_since(user.minutes_in_chat_offline * 60,
                                          0,
                                          format='short')))

        bot.say('Top {num_top} offliners: {data}'.format(
            num_top=self.settings['num_top'], data=', '.join(data)))
コード例 #20
0
ファイル: followage.py プロジェクト: nuuls/pajbot
 def check_follow_age(self, bot, source, username, streamer):
     streamer = bot.streamer if streamer is None else streamer.lower()
     age = bot.twitchapi.get_follow_relationship(username, streamer)
     if source.username == username:
         if age is False:
             bot.say('{}, you are not following {}'.format(source.username_raw, streamer))
         else:
             bot.say('{}, you have been following {} for {}'.format(source.username_raw, streamer, time_since(datetime.datetime.now().timestamp() - age.timestamp(), 0)))
     else:
         if age is False:
             bot.say('{}, {} is not following {}'.format(source.username_raw, username, streamer))
         else:
             bot.say('{}, {} has been following {} for {}'.format(
                 source.username_raw,
                 username,
                 streamer,
                 time_since(datetime.datetime.now().timestamp() - age.timestamp(), 0)))
コード例 #21
0
ファイル: followage.py プロジェクト: jardg/pajbot
    def check_follow_age(self, bot, source, username, streamer):
        streamer = bot.streamer if streamer is None else streamer.lower()
        age = bot.twitchapi.get_follow_relationship(username, streamer)
        is_self = source.username == username

        if age:
            # Following
            human_age = time_since(datetime.datetime.now().timestamp() - age.timestamp(), 0)
            suffix = 'been following {} for {}'.format(streamer, human_age)
            if is_self:
                bot.send_message_to_user(source, 'You have ' + suffix, method=self.settings['action_followage'])
            else:
                bot.send_message_to_user(source, username + ' has ' + suffix, method=self.settings['action_followage'])
        else:
            # Not following
            suffix = 'not following {}'.format(streamer)
            if is_self:
                bot.send_message_to_user(source, 'You are ' + suffix, method=self.settings['action_followage'])
            else:
                bot.send_message_to_user(source, username + ' is ' + suffix, method=self.settings['action_followage'])
コード例 #22
0
ファイル: twitter.py プロジェクト: wijayantoap/bullbot
    def get_last_tweet(self, username):
        if self.twitter_client:
            try:
                public_tweets = self.twitter_client.user_timeline(username)
                for tweet in public_tweets:
                    if not tweet.text.startswith(
                            'RT ') and tweet.in_reply_to_screen_name is None:
                        tw = tweet_prettify_urls(tweet)
                        return '{0} ({1} ago)'.format(
                            tw.replace('\n', ' '),
                            time_since(datetime.now().timestamp(),
                                       tweet.created_at.timestamp(),
                                       format='short'))
            except Exception:
                log.exception('Exception caught while getting last tweet')
                return 'FeelsBadMan'
        else:
            return 'Twitter not set up FeelsBadMan'

        return 'FeelsBadMan'
コード例 #23
0
    def cmd_puptime(self, **options):
        bot = options['bot']
        source = options['source']

        viewer_data = bot.stream_manager.get_viewer_data()

        if viewer_data is False:
            bot.say('{}, the stream is offline.'.format(source.username_raw))
            return

        minutes_watched = viewer_data.get(source.username, None)
        if minutes_watched is None:
            bot.say(
                '{}, You haven\'t been registered watching the stream yet WutFace'
                .format(source.username_raw))
        else:
            minutes_watched = int(minutes_watched) * 60
            log.info(minutes_watched)
            bot.say('{}, You have been watching the stream for ~{}'.format(
                source.username_raw, time_since(minutes_watched, 0)))
コード例 #24
0
    def check_follow_age(self, bot, source, username, streamer, event):
        streamer = bot.streamer if streamer is None else streamer.lower()
        age = bot.twitchapi.get_follow_relationship(username, streamer)
        is_self = source.username == username
        message = ""

        if age:
            # Following
            human_age = time_since(utils.now().timestamp() - age.timestamp(), 0)
            suffix = "been following {} for {}".format(streamer, human_age)
            if is_self:
                message = "You have " + suffix
            else:
                message = username + " has " + suffix
        else:
            # Not following
            suffix = "not following {}".format(streamer)
            if is_self:
                message = "You are " + suffix
            else:
                message = username + " is " + suffix

        bot.send_message_to_user(source, message, event, method=self.settings["action_followage"])
コード例 #25
0
ファイル: followage.py プロジェクト: sadlyfell/bullbot
    def check_follow_age(self, bot, source, username, streamer, event):
        streamer = bot.streamer if streamer is None else streamer.lower()

        user_id = self.bot.twitch_helix_api.get_user_id(username)
        streamer_id = self.bot.twitch_helix_api.get_user_id(streamer)

        if user_id is None or streamer_id is None:
            # one of the users doesn't exist
            follow_since = None
        else:
            follow_since = bot.twitch_helix_api.get_follow_since(user_id, streamer_id)

        message = ""
        streamer = streamer.replace("admiralbulldog", "Buldog")

        if follow_since:
            # Following
            human_age = time_since(utils.now().timestamp() - follow_since.timestamp(), 0)
            message = "{} has been following {} for {}".format(username, streamer, human_age)
        else:
            # Not following
            message = "{} is not following {}".format(username, streamer)

        bot.send_message_to_user(source, message, event, method=self.settings["action_followage"])
コード例 #26
0
 def time_ago_timespan_seconds(t, format='long'):
     v = time_since(t, 0, format)
     return 'None' if len(v) == 0 else v
コード例 #27
0
ファイル: filters.py プロジェクト: jardg/pajbot
 def time_ago(t, format='long'):
     return time_since(datetime.datetime.now().timestamp(), t.timestamp(), format)
コード例 #28
0
ファイル: filters.py プロジェクト: jardg/pajbot
 def time_diff(t1, t2, format='long'):
     return time_since(t1.timestamp(), t2.timestamp(), format)
コード例 #29
0
ファイル: filters.py プロジェクト: jardg/pajbot
 def time_ago_timespan_seconds(t, format='long'):
     v = time_since(t, 0, format)
     return 'None' if len(v) == 0 else v
コード例 #30
0
ファイル: bot.py プロジェクト: damngamerz/bullbot
 def c_uptime(self):
     return time_since(datetime.datetime.now().timestamp(), self.start_time.timestamp())
コード例 #31
0
ファイル: personaluptime.py プロジェクト: jardg/pajbot
    def cmd_puptime(self, **options):
        bot = options['bot']
        source = options['source']

        viewer_data = bot.stream_manager.get_viewer_data()

        if viewer_data is False:
            bot.say('{}, the stream is offline.'.format(source.username_raw))
            return

        minutes_watched = viewer_data.get(source.username, None)
        if minutes_watched is None:
            bot.say('{}, You haven\'t been registered watching the stream yet WutFace'.format(source.username_raw))
        else:
            minutes_watched = int(minutes_watched) * 60
            log.info(minutes_watched)
            bot.say('{}, You have been watching the stream for ~{}'.format(source.username_raw, time_since(minutes_watched, 0)))
コード例 #32
0
ファイル: bot.py プロジェクト: flipsy/pajbot
 def on_pong(self, chatconn, event):
     # self.say('Received a pong. Last pong received {} ago'.format(time_since(datetime.datetime.now().timestamp(), self.last_pong.timestamp())))
     log.info('Received a pong. Last pong received {} ago'.format(
         time_since(datetime.datetime.now().timestamp(),
                    self.last_pong.timestamp())))
     self.last_pong = datetime.datetime.now()
コード例 #33
0
 def time_ago(t, format='long'):
     return time_since(datetime.datetime.now().timestamp(), t.timestamp(),
                       format)
コード例 #34
0
ファイル: bot.py プロジェクト: jardg/pajbot
 def on_pong(self, chatconn, event):
     # self.say('Received a pong. Last pong received {} ago'.format(time_since(datetime.datetime.now().timestamp(), self.last_pong.timestamp())))
     log.info('Received a pong. Last pong received {} ago'.format(time_since(datetime.datetime.now().timestamp(), self.last_pong.timestamp())))
     self.last_pong = datetime.datetime.now()
コード例 #35
0
 def time_diff(t1, t2, format='long'):
     return time_since(t1.timestamp(), t2.timestamp(), format)
コード例 #36
0
ファイル: bot.py プロジェクト: jardg/pajbot
 def c_uptime(self):
     return time_since(datetime.datetime.now().timestamp(), self.start_time.timestamp())
コード例 #37
0
ファイル: followage.py プロジェクト: sotif/pajbot
 def _format_for_follow_age(follow_since):
     human_age = time_since(
         utils.now().timestamp() - follow_since.timestamp(), 0)
     return f"for {human_age}"