def set_up_time_step(message): try: var = int(message.text) if isinstance(var, int): user = User(user_id=message.from_user.id, chat_id=message.chat.id, name=message.from_user.first_name) user.check_if_user_exists() old_time = user.current_time user.change_current_time(time=message.text) if int(old_time) > int(user.current_time): pussy = True else: pussy = False bot.send_message( message.chat.id, min_planked_time_answer2(old_time=old_time, new_time=user.current_time, pussy=pussy, politeness=user.politeness)) except ValueError: bot.send_message(message.chat.id, 'You idiot, it is not an integer! Try again, moron')
def start_message(message): user = User(user_id=message.from_user.id, chat_id=message.chat.id, name=message.from_user.first_name) user.check_if_user_exists() msg = bot.reply_to( message, min_planked_time_answer(user=user.name, politeness=user.politeness)) bot.register_next_step_handler(msg, set_up_time_step)
def handle_docs_video(message): user = User(user_id=message.from_user.id, chat_id=message.chat.id, name=message.from_user.first_name) user.check_if_user_exists() print('Server time ', datetime.datetime.today()) if int(datetime.datetime.fromtimestamp(message.date).strftime("%H")) > 2: user.check_planked_today( datetime.datetime.fromtimestamp(message.date).strftime("%d %b %Y")) else: user.check_planked_today( (datetime.datetime.fromtimestamp(message.date) - timedelta(days=1)).strftime("%d %b %Y")) if user.planked_today is False: if int(datetime.datetime.fromtimestamp( message.date).strftime("%H")) > 2: if message.video.duration >= user.current_time: bot.send_message( message.chat.id, bot_planked_answer( message.from_user.first_name, datetime.datetime.fromtimestamp(message.date), user.politeness)) user.write_planked_today( datetime.datetime.fromtimestamp( message.date).strftime("%d %b %Y")) else: bot.send_message( message.chat.id, 'Dear ' + message.from_user.first_name + ', your current minimum planking time is ' + str(user.current_time) + ' seconds. Your video is ' + str(message.video.duration) + ' seconds, which is less.') bot.send_sticker( message.chat.id, 'CAACAgIAAxkBAAECQv9gkkGyCEsBZZL4RnkOD4A4fXLnKwACiwIAAladvQr3tGImDY878x8E' ) else: if message.video.duration >= user.current_time: bot.send_message( message.chat.id, bot_planked_answer( message.from_user.first_name, (datetime.datetime.fromtimestamp(message.date) - timedelta(days=1)), user.politeness)) else: bot.send_message( message.chat.id, 'Dear ' + message.from_user.first_name + ', your current minimum planking time is ' + str(user.current_time) + ' seconds. Your video is ' + str(message.video.duration) + ' seconds, which is less.') else: bot.send_message(message.chat.id, 'Bro, you already planked today! You can stop)')
def check_all_missed_times(chat): users_df = pd.read_hdf(users_db_path, key='df') message = 'Here is the list of all current lazy debtors: ' + ' \n ' for user in users_df.loc[users_df['chat_id'] == chat]['user_id']: check_user = User(user_id=user, chat_id=chat) check_user.check_if_user_exists() # member = bot.get_chat_member(chat_id=check_user.chat_id, user_id=check_user.user_id) # print('member:', member.status) if check_user.times_missed > 0: message = message + str(check_user.name) + ' - ' + str( check_user.times_missed) + ' \n ' bot.send_message(chat, message)
def change_name_step2(message): global user_to_change print('user to change ', user_to_change) print(user_to_change) users = load_chat_users(chat_id=message.chat.id) user = User(user_id=users[user_to_change], chat_id=message.chat.id) user.check_if_user_exists() markup = types.ReplyKeyboardRemove() user.change_name(name=message.text) bot.send_message( message.chat.id, 'I hereby welcome the reborn user, that from now on shall be known as ' + user.name + '!', reply_markup=markup) user_to_change = ""
def start_message(message): user = User(user_id=message.from_user.id, chat_id=message.chat.id, name=message.from_user.first_name) user.check_if_user_exists() bot.send_message( message.chat.id, 'Your current statistics: \n' 'Name: ' + str(user.name) + ' \n' 'Current minimum planking time: ' + str(user.current_time) + ' seconds. \n' 'Time increase: ' + str(user.time_increase) + ' seconds \n' 'Increase in days: ' + str(user.increase_in_days) + ' days \n' 'Next increase on: ' + str(user.increase_day) + '\n' 'Vacation: ' + str(user.vacation) + '\n' 'Times missed: ' + str(user.times_missed) + '\n' 'Politeness: ' + str(user.politeness))
def clear_a_name(message): users = load_chat_users(chat_id=message.chat.id) markup = types.ReplyKeyboardRemove() if message.text in users: user_who_missed = User(user_id=users[message.text], chat_id=message.chat.id) user_who_missed.check_if_user_exists() user_who_missed.change_times_missed(times=0) bot.send_message(message.chat.id, 'Done. The user now has ' + str(user_who_missed.times_missed) + ' misses.', reply_markup=markup) else: bot.send_message( message.chat.id, 'You could not have collected money from him, because he is not in our group!', reply_markup=markup)
def check_increase_date(): users_df = pd.read_hdf(users_db_path, key='df') for chat in users_df['chat_id'].drop_duplicates(): message = '' for user in users_df.loc[users_df['chat_id'] == chat]['user_id']: check_user = User(user_id=user, chat_id=chat) check_user.check_if_user_exists() if check_user.increase_day <= datetime.datetime.today().date(): check_user.change_increase_date() check_user.change_current_time() message = message + check_user.name +\ ' , congrats! Today is your increase day! Your new time is ' +\ str(int(check_user.current_time)) + ' seconds! Your next' \ ' increase date is ' +\ str(check_user.increase_day.strftime("%d %b %Y")) if message != '': bot.send_message(chat, message) message = ''
def send_daily_stats(days=1): users_df = pd.read_hdf(users_db_path, key='df') for chat in users_df['chat_id'].drop_duplicates(): message = 'Daily check list as of ' + \ str((datetime.datetime.today().date() - timedelta(days=days)).strftime("%d %b %Y")) + ': \n ' for user in users_df.loc[users_df['chat_id'] == chat]['user_id']: print('Showing current user: '******' - ' + str( check_user.planked_today) + ' \n ' bot.send_message(chat, message)
def set_up_increase_periods_step(message): try: var = int(message.text) if isinstance(var, int): user = User(user_id=message.from_user.id, chat_id=message.chat.id, name=message.from_user.first_name) user.check_if_user_exists() old_time = user.increase_in_days user.change_increase_in_days(days=message.text) bot.send_message( message.chat.id, 'Done. Your old increase in days was ' + str(old_time) + ' days. Your new increase in days is ' + str(user.increase_in_days) + ' days') except ValueError: bot.send_message(message.chat.id, 'You idiot, it is not an integer! Try again, moron')
def increase_missed_days(message): users = load_chat_users(chat_id=message.chat.id) markup = types.ReplyKeyboardRemove() if message.text in users: user_who_missed = User(user_id=users[message.text], chat_id=message.chat.id) user_who_missed.check_if_user_exists() user_who_missed.change_times_missed() bot.send_message(message.chat.id, increase_missed_day_answer( user_who_missed.name, str(user_who_missed.times_missed), user_who_missed.politeness), reply_markup=markup) # bot.send_message(message.chat.id, 'Done. The user now has ' + str(user_who_missed.times_missed) + ' misses.', reply_markup=markup) else: bot.send_message(message.chat.id, 'Stop messing with me, please! There is no such user', reply_markup=markup)
def set_up_vacation_step(message): global user_to_change # check if user exists users = load_chat_users(chat_id=message.chat.id) if message.text in users: user_to_change = message.text user = User(user_id=users[user_to_change], chat_id=message.chat.id) user.check_if_user_exists() markup = types.ReplyKeyboardMarkup(one_time_keyboard=True, selective=True) markup.add('On vacation/ill', 'Not on vacation/ill') bot.send_message( message.chat.id, vacation_status_answer(user=user.name, vacation=user.vacation, politeness=user.politeness)) msg = bot.reply_to(message, 'Which status is it?', reply_markup=markup) bot.register_next_step_handler(msg, set_up_vacation_step2) else: bot.send_message(message.chat.id, 'Sorry, there is no such user')
def set_up_vacation_step2(message): global user_to_change users = load_chat_users(chat_id=message.chat.id) user = User(user_id=users[user_to_change], chat_id=message.chat.id) user.check_if_user_exists() markup = types.ReplyKeyboardRemove() if message.text == "On vacation/ill" or message.text == "Not on vacation/ill": if message.text == "On vacation/ill": status = 'True' else: status = 'False' user.change_vacation(value=status) bot.send_message(message.chat.id, 'Done. The user is now ' + str(message.text).lower(), reply_markup=markup) user_to_change = "" else: bot.send_message( message.chat.id, 'In case noone told you - you can not write an essay here, use suggested options.', reply_markup=markup)
def change_politeness_step2(message): global user_to_change print('user to change ', user_to_change) users = load_chat_users(chat_id=message.chat.id) user = User(user_id=users[user_to_change], chat_id=message.chat.id) user.check_if_user_exists() markup = types.ReplyKeyboardRemove() if message.text == 'Please be gentle, senpai!': user.change_politeness(politeness='polite') bot.send_message( message.chat.id, 'Great! We have finally established our relationship!', reply_markup=markup) elif message.text == 'Hurt me, daddy!': user.change_politeness(politeness='rude') bot.send_message( message.chat.id, 'So you enjoy suffering? Okay, but remember, you can say "stop-word" only once a month! ', reply_markup=markup) else: bot.send_message(message.chat.id, 'I am afraid that is not an option.') user_to_change = ""
def set_up_planked_with_step(message): users = load_chat_users(chat_id=message.chat.id) markup = types.ReplyKeyboardRemove() if message.text in users: user_to_change_plank = User(user_id=users[message.text], chat_id=message.chat.id) user_to_change_plank.check_if_user_exists() user_to_check = User(user_id=message.from_user.id, chat_id=message.chat.id) user_to_check.check_if_user_exists() if int(datetime.datetime.fromtimestamp( message.date).strftime("%H")) > 2: user_to_check.check_planked_today( datetime.datetime.fromtimestamp( message.date).strftime("%d %b %Y")) if user_to_check.planked_today is True: user_to_change_plank.check_planked_today( datetime.datetime.fromtimestamp( message.date).strftime("%d %b %Y")) if user_to_change_plank.planked_today is False: bot.send_message(message.chat.id, 'Great! Hope you and ' + str(user_to_change_plank.name) + ' had a wonderful time!', reply_markup=markup) user_to_change_plank.write_planked_today( datetime.datetime.fromtimestamp( message.date).strftime("%d %b %Y")) else: bot.send_message( message.chat.id, 'I see that this user already planked today. ' 'Did you get drunk together and you forgot that you have already tagged your friend?)', reply_markup=markup) else: bot.send_message( message.chat.id, 'Hmmm... It looks like you have not planked yourself today.. Do not believe you.', reply_markup=markup) else: user_to_check.check_planked_today( (datetime.datetime.fromtimestamp(message.date) - timedelta(days=1)).strftime("%d %b %Y")) if user_to_check.planked_today is True: user_to_change_plank.check_planked_today( (datetime.datetime.fromtimestamp(message.date) - timedelta(days=1)).strftime("%d %b %Y")) if user_to_change_plank.planked_today is False: bot.send_message(message.chat.id, 'Great! Hope you and ' + str(user_to_change_plank.name) + ' had a wonderful time!', reply_markup=markup) user_to_change_plank.write_planked_today( (datetime.datetime.fromtimestamp(message.date) - timedelta(days=1)).strftime("%d %b %Y")) else: bot.send_message( message.chat.id, 'I see that this user already planked today. ' 'Did you get drunk together and you forgot that you have already tagged your friend?)', reply_markup=markup) else: bot.send_message( message.chat.id, 'Hmmm... It looks like you have not planked yourself today.. Do not believe you.', reply_markup=markup) else: bot.send_message(message.chat.id, 'Bloody hell!!! There is no such user. Start over.', reply_markup=markup)