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': lambda var, args: urllib.parse.urlencode(var), 'join': _filter_join, 'number_format': _filter_number_format, } if filter.name in available_filters: return available_filters[filter.name](resp, filter.arguments) return resp
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 '
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 '
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 ?'
def check_follow_age(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)))
def top_offline(self, **options): bot = options['bot'] data = [] for user in bot.users.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)))
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, format='short'))) bot.say('Top {num_top} watchers: {data}'.format( num_top=self.settings['num_top'], data=', '.join(data)))
def top_watchers(self, **options): bot = options['bot'] data = [] for user in bot.users.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, format='short'))) bot.say('Top {num_top} watchers: {data}'.format( num_top=self.settings['num_top'], data=', '.join(data)))
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'
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)))
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)))
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'
def time_ago(t, format='long'): return time_since(datetime.datetime.now().timestamp(), t.timestamp(), format)
def howcleanis_internal(self, bot, source, message, event, args): if message: msg_args = message.split(' ') username = msg_args[0].lower() pattern = re.compile("^([A-Za-z0-9_]+)$") if not pattern.match(username): return user = bot.users[username] if not args['whisper']: if not hasattr(bot, 'lastHowClean'): bot.lastHowClean = 0 if datetime.datetime.now().timestamp() - bot.lastHowClean < 4: return bot.lastHowClean = datetime.datetime.now().timestamp() minutes = user.minutes_in_chat_online + user.minutes_in_chat_offline age = bot.twitchapi.get_follow_relationship(username, 'trumpsc') if args['whisper']: replyfunc = lambda x: bot.whisper(source.username, x) else: #return replyfunc = bot.say emote = 'DansGame' clean_emote = 'SeemsGood' if username == 'frodan': emote = 'KappaPride' clean_emote = 'KappaPride' elif username == 'ek0p': clean_emote = 'DansGame' elif username == 'forsenlol': clean_emote = 'gachiGASM' elif username == 'reynad27': emote = 'EleGiggle' clean_emote = 'EleGiggle' elif username == 'nl_kripp': emote = 'PJSalt' clean_emote = 'PJSalt' elif username == 'thijshs': emote = 'haHAA' clean_emote = 'haHAA' elif username == 'bobross': clean_emote = 'KappaRoss' elif username == 'legendarylea': emote = '(puke)' elif username == 'massansc' or username == 'p4wnyhof' or username == 'athenelive': emote = 'MrDestructoid' clean_emote = 'MrDestructoid' if username == 'imcleanbot': replyfunc('I\'m clean, don\'t shoot \\ BabyRage /') elif username == 'trumpsc': replyfunc('What do you think BrokeBack') elif username == 'pajlada': replyfunc('pajlada \"idles\" in Trump chat 24/7 so that we can\'t know when he\'s actually watching DansGame') elif 'trump_sub' in user.tags or username == 'eloise_ailv' or username == 'limeyomnicron': replyfunc('{0} is a Trump sub DansGame DansGame DansGame'.format(user.username)) elif minutes > 0: replyfunc('{0} {1} has watched Trump for {2} {3}'.format(user.username, ('' if age is False else 'follows Trump and '), timetotext(minutes), emote)) elif age is False: replyfunc('{0} is clean {1}'.format(user.username, clean_emote)) else: replyfunc('{0} has been following Trump for {1} {2}'.format(user.username, time_since(datetime.datetime.now().timestamp() - age.timestamp(), 0), emote))
def time_ago_timespan_seconds(t, format='long'): v = time_since(t, 0, format) return 'None' if len(v) == 0 else v
def time_diff(t1, t2, format='long'): return time_since(t1.timestamp(), t2.timestamp(), format)
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)))
def c_uptime(self): return time_since(datetime.datetime.now().timestamp(), self.start_time.timestamp())
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()
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()