def quien(update, context): chat_id = update.effective_chat.id user_id = update.effective_user.id if not toolbox.user_is_in_group_or_admin(chat_id, user_id): return () output = "" break_users = sql.db.get_current_breaks() timestamp = datetime.now().timestamp() if not break_users: output = "0 users away.\n\n" else: if len(break_users) == 1: output += "1 user away.\n\n" else: output += str(len(break_users)) + " users away.\n\n" for i in break_users: break_type = break_duration_calculator(i['expected_length']) output += "*" + toolbox.list_user(i['user_id'], mention=False) + "*" output += " - " + datetime.fromtimestamp( i['start_time']).strftime("%H:%M") output += " " + break_type output += " (" + toolbox.seconds_to_string(timestamp - i['start_time'], longform=False) + ")" output += "\n" context.bot.send_message( chat_id=chat_id, text=output, parse_mode="Markdown" ) #, reply_to_message_id=update.message.message_id) #toolbox.save_json("break_users",break_users) return
def adduser(update, context): #db'd chat_id=update.effective_chat.id user_id=update.effective_user.id if not toolbox.user_is_admin(user_id): return() #help_users=toolbox.load_json('help_users') user_id=int(toolbox.remove_prefix(update.message.text,"/adduser ")) check=sql.db.check_help_user(user_id) output="*" output+=""+toolbox.list_user(user_id, mention=False) if check: output+="* is already on the helper list." # i don't think there may be duplicates if my bot works correctly, # but using a database creates that possibility. if len(check)>1 and config.verbose: toolbox.notify_owner("warning: dupligate found for "+ str(check)+"\n"+ "\nchat_id: "+chat_id+ "\nuser_id: "+user_id ) else: output+="* added to the helper list at index " output+=str(sql.db.add_help_user(user_id)[0])+"." if config.verbose: print(output) context.bot.send_message(chat_id=chat_id, text=str(output), parse_mode="Markdown") return()
def hack(update, context): chat_id = update.effective_chat.id user_id = update.effective_user.id if not toolbox.user_is_admin(user_id): return () output = "Hackeando....\n\n" try: name = context.args[0].title() output = "{0} ha sido hackeado.".format(name) except IndexError: try: reply_user_id = update.effective_message.reply_to_message.from_user.id #holy mother of objects name = toolbox.list_user(reply_user_id, config.all_users, mention=False) output = "{0} ha sido hackeado.".format(name) except AttributeError: name = toolbox.list_user(user_id, config.all_users, mention=False) output = "{0} ha sido hackeado.".format(name) context.bot.send_message(chat_id=chat_id, text=output)
def taking_break(update, context, lunch=False): chat_id = update.effective_chat.id user_id = update.effective_user.id if not toolbox.user_is_in_group_or_admin(chat_id, user_id): return () timestamp = datetime.now().timestamp() break_users = sql.db.get_current_breaks() toolbox.debug(break_users) username = toolbox.list_user(user_id, mention=False) try: expected_length = int(context.args[0]) except: expected_length = 15 if lunch: expected_length = 30 for i in break_users: if i['user_id'] == user_id: break_type = break_duration_calculator(i['expected_length']) output=username+" ya está de "+break_type+" desde las "+\ datetime.fromtimestamp(i['start_time']).strftime("%H:%M:%S") output += toolbox.count_away_users(len(break_users)) context.bot.send_message(chat_id=chat_id, text=output, parse_mode="Markdown") return () else: # yo this was an accident but apparently you can have an else after a for loop? wtf break_type = break_duration_calculator(expected_length) sql.db.send_user_away( user_id=user_id, timestamp=timestamp, expected_length=expected_length, alarm_channel=chat_id, ) output=username+" se ha ido de "+break_type+" a las "+\ datetime.fromtimestamp(timestamp).strftime("%H:%M:%S") output += toolbox.count_away_users( len(break_users) + 1) #break user was only updated _before_ adding the current user. context.bot.send_message( chat_id=chat_id, text=output, parse_mode="Markdown" ) #, reply_to_message_id=update.message.message_id) rebuild_schedule() return ()
def alarm(break_data): now = datetime.now().timestamp() diff = now - break_data['start_time'] break_type = break_duration_calculator(break_data['expected_length']) output = "" output += toolbox.list_user(break_data['user_id'], mention=True) output += " lleva ya " output += toolbox.seconds_to_string(diff, include_seconds=False) output += " de " + break_type + "." output += "\n\nUsa /back para salirte de " + break_type tg.updater.bot.send_message( chat_id=break_data['alarm_channel'], text=output, parse_mode="Markdown" ) #, reply_to_message_id=update.message.message_id) rebuild_schedule() return
def removeme(update,context): #db'd chat_id=update.effective_chat.id user_id=update.effective_user.id if not toolbox.user_is_in_group_or_admin(chat_id, user_id): return() check=sql.db.check_help_user(user_id) output="" output+="*"+toolbox.list_user(user_id, mention=False) if check: output+="* removed from the helper list." sql.db.remove_help_user(user_id) ## debugging purposes: #check=sql.db.check_help_user(user_id) #output+=str(check) else: output+="* not found on the helper list." context.bot.send_message(chat_id=chat_id, text=str(output), parse_mode="Markdown") return()
def sim(update, context): chat_id = update.effective_chat.id user_id = update.effective_user.id if not toolbox.user_is_admin(user_id): return () output = "Llamando al SIM....\n\n" try: name = context.args[0].title() output += sim_action_from_name(name) except IndexError: try: reply_user_id = update.effective_message.reply_to_message.from_user.id #holy mother of objects name = toolbox.list_user(reply_user_id, config.all_users, mention=False) output = sim_action_from_name(name) except AttributeError: output += sim_action_no_name() context.bot.send_message(chat_id=chat_id, text=output)
def back(update, context): chat_id = update.effective_chat.id user_id = update.effective_user.id if not toolbox.user_is_in_group_or_admin(chat_id, user_id): return () timestamp = datetime.now().timestamp() break_users = sql.db.get_current_breaks() toolbox.debug(break_users) username = toolbox.list_user(user_id, mention=False) user_is_on_break = False for i in break_users: if i['user_id'] == user_id: sql.db.bring_user_back(i['id'], timestamp) break_type = break_duration_calculator(i['expected_length']) output=username+" ha vuelto de "+break_type+" a las "+\ datetime.fromtimestamp(timestamp).strftime("%H:%M:%S")+\ ", después de "+toolbox.seconds_to_string(timestamp-i['start_time']) output += toolbox.count_away_users( len(break_users) - 1) #one user was removed after checking context.bot.send_message(chat_id=chat_id, text=output, parse_mode="Markdown") rebuild_schedule() return () else: output = username + " no está de break." output += toolbox.count_away_users(len(break_users)) context.bot.send_message( chat_id=chat_id, text=output, parse_mode="Markdown" ) #, reply_to_message_id=update.message.message_id) return