def kick(update, context): save_command(update, "kick") if check_permission(update.message.from_user.id) > 0: context.bot.send_message(text=text.unauthorized, chat_id=update.message.chat_id) return try: people = getUserByFullName(context.args[0], context.args[1]) except: message = text.args_not_given context.bot.send_message(text=message, chat_id=update.message.chat_id) return if not people: message = text.person_not_found.format(context.args[0], context.args[1]) context.bot.send_message(text=message, chat_id=update.message.chat_id) return chat = fastChat.getAVIS() for person in people: try: context.bot.kick_chat_member(chat_id=chat, user_id=person.chat_id) context.bot.unban_chat_member(chat_id=chat, user_id=person.chat_id) except: message = text.can_not_kick.format(person.name + ' ' + person.surname, chat) context.bot.send_message(text=message, chat_id=update.message.chat_id)
def edit_number(update, context): save_command(update, "number") if check_permission(update.message.chat_id) > 0: context.bot.send_message(text=text.unauthorized, chat_id=update.message.chat_id) return try: name = context.args[0] surname = context.args[1] number = int(context.args[2]) except IndexError: context.bot.send_message(chat_id=update.message.chat_id, text=text.wrong_args_number) return if number < 0 or number > 99: context.bot.send_message(chat_id=update.message.chat_id, text=text.wrong_range_number) return elif number == 0: result = userDao.edit_user_number(name, surname, None) else: result = userDao.edit_user_number(name, surname, number) if result == 0: context.bot.send_message(chat_id=update.message.chat_id, text=text.number_updated) elif result == 1: context.bot.send_message(chat_id=update.message.chat_id, text=text.number_update_failed)
def members(update, context): save_command(update, "members") if check_permission(update.message.chat_id) > 2: context.bot.send_message(text=text.unauthorized, chat_id=update.message.chat_id) return people = userDao.get_all() message = "" for person in people: message = message \ + str(person.chat_id) + " " \ + person.name + " " \ + person.surname + " " \ + str(person.nickname) + " " \ + str(person.number) + " " \ + str(person.bday) + " " \ + str(person.delays) + " " \ + str(person.absence) + " " \ + str(person.fines0) + " " \ + str(person.fines1) + " " \ + str(person.active) + "\n" context.bot.send_message(chat_id=update.message.chat_id, text=message)
def pop(update, context): save_command(update, "pop") if check_permission(update.message.from_user.id) > 1: context.bot.send_message(text=text.unauthorized, chat_id=update.message.chat_id) return with open(filePath, 'r+') as f_paste: paste_dict = json.load(f_paste) try: paste_dict.pop(0) f_paste.seek(0) json.dump(paste_dict, f_paste, indent=4) f_paste.truncate() except: context.bot.send_message(chat_id=update.message.chat_id, text=text.emptyList) return context.bot.send_message(chat_id=update.message.chat_id, text=text.listUpdated) showList(update, context)
def addPerson(update, context, name=None): if name is None: save_command(update, "add") if check_permission(update.message.from_user.id) > 1: context.bot.send_message(text=text.unauthorized, chat_id=update.message.chat_id) return try: sent_name = context.args[0] except IndexError: context.bot.send_message(chat_id=update.message.chat_id, text=text.validName) return else: sent_name = name with open(filePath, 'r+') as f_paste: paste_dict = json.load(f_paste) paste_dict.append(sent_name) f_paste.seek(0) json.dump(paste_dict, f_paste, indent=4) f_paste.truncate() try: chat = update.message.chat_id except: chat = getAVIS() context.bot.send_message(chat_id=chat, text=text.personAdded.format(sent_name)) showList(update, context)
def remove(update, context): save_command(update, "remove") if check_permission(update.message.from_user.id) > 1: context.bot.send_message(text=text.unauthorized, chat_id=update.message.chat_id) return n = int(context.args[0]) if n <= 1: context.bot.send_message(chat_id=update.message.chat_id, text=text.usePop) return with open(filePath, "r+") as f_paste: paste_dict = json.load(f_paste) if n > len(paste_dict): message = 'Out of index' else: name = paste_dict[n - 1] paste_dict.pop(n - 1) f_paste.seek(0) json.dump(paste_dict, f_paste, indent=4) f_paste.truncate() message = text.personRemoved.format(name) context.bot.send_message(chat_id=update.message.chat_id, text=message) showList(update, context)
def showList(update, context): try: save_command(update, "paste") if check_permission(update.message.from_user.id) > 2: context.bot.send_message(text=text.unauthorized, chat_id=update.message.chat_id) return except: print("no user id, may be an automatic call?") with open(filePath, 'r') as f_paste: paste_dict = json.load(f_paste) message = '\n'.join(paste_dict) try: chat = update.message.chat_id except: chat = getAVIS() if message == '': message = text.emptyList context.bot.send_message(chat_id=chat, text=message)
def help(update, context): save_command(update, "help") if check_permission(update.message.from_user.id) > 2: context.bot.send_message(text=text.unauthorized, chat_id=update.message.chat_id) return commands = getCommands() message = text.help + '\n' for command in commands: message = message + '\n/' + command.command context.bot.send_message(text=message, chat_id=update.message.chat_id)
def man(update, context): save_command(update, "man") if check_permission(update.message.from_user.id) > 2: context.bot.send_message(text=text.unauthorized, chat_id=update.message.chat_id) return commands = getCommandsFull() message = text.man + '\n' for command in commands: message = message + '\n\n/' + \ command.command + ' ' + command.args + '\n' + \ command.description.capitalize() + ';' context.bot.send_message(text=message, chat_id=update.message.chat_id)
def change_active(update, context): save_command(update, "active") if check_permission(update.message.chat_id) > 0: context.bot.send_message(text=text.unauthorized, chat_id=update.message.chat_id) return try: name = context.args[0] surname = context.args[1] except IndexError: context.bot.send_message(chat_id=update.message.chat_id, text=text.wrong_args_active) return userDao.edit_user_active(name, surname) context.bot.send_message(chat_id=update.message.chat_id, text=text.active_updated)
def register(update, context): save_command(update, "register") if check_permission(update.message.chat_id) > 0: context.bot.send_message(text=text.unauthorized, chat_id=update.message.chat_id) return try: chat_id = context.args[0] name = context.args[1] surname = context.args[2] bday = context.args[3] bday_array = bday.split("-") bday_year = int(bday_array[0]) bday_month = int(bday_array[1]) bday_day = int(bday_array[2]) except IndexError: context.bot.send_message(chat_id=update.message.chat_id, text=text.wrong_args_new_user) return try: bday_date = datetime.date(year=bday_year, month=bday_month, day=bday_day) except: context.bot.send_message(chat_id=update.message.chat_id, text=text.wrong_data_format) return result = userDao.create_new_user( User(chat_id=chat_id, name=name, surname=surname, bday=bday_date)) if result == 0: context.bot.send_message(chat_id=update.message.chat_id, text=text.insert_success) elif result == 1: context.bot.send_message(chat_id=update.message.chat_id, text=text.chat_id_already_exist)
def edit_nickname(update, context): save_command(update, "nickname") if check_permission(update.message.chat_id) > 0: context.bot.send_message(text=text.unauthorized, chat_id=update.message.chat_id) return try: name = context.args[0] surname = context.args[1] nickname = context.args[2] except IndexError: context.bot.send_message(chat_id=update.message.chat_id, text=text.wrong_args_nickname) return result = userDao.edit_user_nickname(name, surname, nickname) if result == 0: context.bot.send_message(chat_id=update.message.chat_id, text=text.nickname_updated) elif result == 1: context.bot.send_message(chat_id=update.message.chat_id, text=text.nickname_update_failed)