def money_give(message, person, parameters_dictionary: dict): """Функция обмена деньгами между людьми""" LOG.log(f"money_give invoked to person {person.id}") database = Database() getter = person giver = message.from_user money = parameters_dictionary['value'] system = database.get('chats', ('id', message.chat.id))['system'] value_getter = get_person(message, getter, system, database)['money'] value_giver = get_person(message, giver, system, database)['money'] money_name_word = get_word_object( get_system_configs(system)['money_name'], 'Russian') money_name = money_name_word.cased_by_number(abs(money), if_one_then_accusative=True) if money < 0: reply(message, "Я вам запрещаю воровать") elif money == 0: reply(message, "Я вам запрещаю делать подобные бессмысленные запросы") else: if money > value_giver: reply(message, "Не хватает {}".format(money_name_word.genitive_plural())) else: value_getter += money value_giver -= money giv_m = send(giver.id, "#Финансы\n\nВы успешно перевели {} {} на счёт {}. " "Теперь у вас их {}".format(money, money_name, person_link(getter), value_giver), parse_mode='HTML') get_m = send( getter.id, "#Финансы\n\nНа ваш счёт переведено {} {} со счёта {}. " "Теперь у вас их {}".format(money, money_name, person_link(giver), value_getter), parse_mode='HTML') if get_m: get_m = "🔔 уведомлён(а)" else: get_m = "🔕 не уведомлён(а)" if giv_m: giv_m = "🔔 уведомлён(а)" else: giv_m = "🔕 не уведомлён(а)" reply(message, "{} передал(а) {} {} {}!".format(person_link(giver), person_link(getter), money, money_name), parse_mode='HTML') send( admin_place(message, database), f"#Финансы #f{getter.id} #f{giver.id}\n\n" f"{person_link(getter)} [{value_getter - money} --> {value_getter}] {get_m}\n" f"{person_link(giver)} [{value_giver + money} --> {value_giver}] {giv_m}\n", parse_mode='HTML') database.change(value_getter, 'money', 'members', ('id', getter.id), ('system', system)) database.change(value_giver, 'money', 'members', ('id', giver.id), ('system', system))
def unwarn(message, person, parameters_dictionary: dict): """Снимает с участника предупреждение""" database = Database() unwarns = parameters_dictionary['value'] chat = database.get('chats', ('id', message.chat.id)) system = chat['system'] value = database.get('members', ('id', person.id), ('system', system))['warns'] - unwarns if value >= 0: database.change(value, 'warns', 'members', ('id', person.id), ('system', system)) adm_place = admin_place(message, database) if adm_place: text = "#warns\n\n" text += "Пользователь {} потерял(а) {} варн(а) и их стало {}\n".format( person_info_in_html(person), unwarns, value) text += "Варн(ы) снят(ы) пользователем {}\n".format( person_info_in_html(message.from_user)) if 'comment' in parameters_dictionary.keys(): text += "Комментарий: {}".format( parameters_dictionary['comment']) send(adm_place, text, parse_mode='HTML') reply(message, "Варн(ы) снят(ы). Теперь их {}".format(value)) if 3 - unwarns <= value < 3: chat_configs = get_system_configs(system) unban_user(person) database.change(chat_configs['ranks'][1], 'rank', 'members', ('id', person.id), ('system', system)) else: reply(message, "Нельзя сделать отрицательное количество предупреждений")
def warn(message, person, parameters_dictionary): """Даёт участнику предупреждение""" database = Database() warns = parameters_dictionary['value'] chat = database.get('chats', ('id', message.chat.id)) system = chat['system'] value = database.get('members', ('id', person.id), ('system', system))['warns'] + warns database.change(value, 'warns', 'members', ('id', person.id), ('system', system)) reply(message, "Варн(ы) выдан(ы). Теперь их {}".format(value)) adm_place = admin_place(message, database) if adm_place: send(adm_place, "Пользователь {} получил(а) {} варн(а) и их стало {}".format( person_info_in_html(person), warns, value), parse_mode='HTML') blowout = database.get('channels', ('name', 'Проколы'))['id'] how_many = 10 # Сколько пересылает сообщений end_forwarding = message.reply_to_message.message_id start_forwarding = end_forwarding - how_many send(blowout, "В чате {} случилось нарушение участником {} Прысылаю {} сообщений". format(chat_info_in_html(message.chat), person_info_in_html(person), how_many), parse_mode='HTML') for msg_id in range(start_forwarding, end_forwarding + 1): forward(blowout, message.chat.id, msg_id) if value >= 3: ban(message, person)
def non_ironic(call): """Реакция, если обвинение было неироничным""" # Проверка, нажал ли на кнопку не тот, кто нужен edit_text("Неиронично!", call.message.chat.id, call.message.message_id) send(admin_place(call.message, Database()), "Произошло оскорбление! " + "[Ссылка на инцидент](t.me/{}/{})".format( call.message.reply_to_message.chat.username, call.message.reply_to_message.message_id), parse_mode="Markdown") answer_callback(call.id)
def rank_changer(message, person): """Changes person's rank""" database = Database() chat = database.get('chats', ('id', message.chat.id)) system = chat['system'] chat_configs = get_system_configs(system) command = message.text.split()[0].split(sep='@')[0] adm_place = admin_place(message, database) if command in chat_configs["ranks_commands"]: rank_index = chat_configs["ranks_commands"].index(command) rank = chat_configs["ranks"][rank_index] database.change(rank, "rank", 'members', ('id', person.id), ('system', system)) reply(message, f"Теперь это {rank} по званию!") if adm_place: send(adm_place, "Пользователь {} получил(а) звание {}".format( person_info_in_html(person), rank), parse_mode='HTML') elif command in chat_configs["appointment_adders"]: appointment_index = chat_configs["appointment_adders"].index(command) appointment = chat_configs["appointments"][appointment_index] if not database.get('appointments', ('id', person.id), ('system', system), ('appointment', appointment)): database.append((person.id, system, appointment), "appointments") reply( message, f"Теперь это {appointment}. Поздравим человека с повышением!") if adm_place: send(adm_place, "Пользователь {} получил(а) должность {}".format( person_info_in_html(person), appointment), parse_mode='HTML') else: reply(message, "У этого человека и так есть эта должность") elif command in chat_configs["appointment_removers"]: appointment_index = chat_configs["appointment_removers"].index(command) appointment = chat_configs["appointments"][appointment_index] database.remove("appointments", ('id', person.id), ('system', system), ('appointment', appointment)) reply(message, f"Теперь это не {appointment}") if adm_place: send(adm_place, "Пользователь {} потерял(а) должность {}".format( person_info_in_html(person), appointment), parse_mode='HTML') unban_user(person) if is_suitable(message, person, 'boss', loud=False): give_admin(message, person, loud=False) else: del_admin(message, person, loud=False)
def mute(message, person, parameters_dictionary): """Даёт участнику бан""" database = Database() hours = parameters_dictionary['value'] chat = database.get('chats', ('id', message.chat.id)) system = chat['system'] for chat in full_chat_list(database, system): restrict(chat['id'], person.id, until_date=time() + hours * 3600) adm_place = admin_place(message, database) if adm_place: send(adm_place, "Пользователь {} получил(а) мут на {} час(ов)".format( person_info_in_html(person), hours), parse_mode='HTML') reply(message, "Мут выдан")
def money_fund(message, parameters_dictionary): """Transfer money to the chat fund""" database = Database() giver = message.from_user money = parameters_dictionary['value'] chat = database.get('chats', ('id', message.chat.id)) system = chat['system'] value_giver = database.get('members', ('id', giver.id), ('system', system))['money'] value_system = database.get('systems', ('id', system))['money'] money_name_word = get_word_object( get_system_configs(system)['money_name'], 'Russian') money_name = money_name_word.cased_by_number(abs(money), if_one_then_accusative=True) if money < 0: reply(message, "Я вам запрещаю воровать") elif money == 0: reply(message, "Я вам запрещаю делать подобные бессмысленные запросы") else: if money > value_giver: reply(message, "Не хватает {}".format(money_name_word.genitive_plural())) else: if value_system != 'inf': value_system = int(value_system) value_system += money value_giver -= money text = f"#Финансы\n\nВы успешно перевели {money} {money_name} в фонд чата. " \ f"Теперь у вас их {value_giver}" giv_m = value_marker(send(giver.id, text), "🔔 уведомлён(а)", "🔕 не уведомлён(а)") reply(message, "{} заплатил(а) в банк {} {}!".format( person_link(giver), money, money_name), parse_mode='HTML') answer = f"#Финансы #f{giver.id}\n\n" if value_system != 'inf': answer += f"#Бюджет [{value_system - money} --> {value_system}]\n" answer += f"{person_link(giver)} [{value_giver + money} --> {value_giver}] {giv_m}\n" send(admin_place(message, database), answer, parse_mode='HTML') database.change(value_giver, 'money', 'members', ('id', giver.id), ('system', system)) database.change(value_system, 'money', 'systems', ('id', system))
def ban(message, person, comment=True, unban_then=False): """Даёт участнику бан""" database = Database() blowout = database.get('channels', ('name', 'Проколы'))['id'] how_many = 3 # Сколько пересылает сообщений if not unban_then: end_forwarding = get_target_message(message).message_id start_forwarding = end_forwarding - how_many send(blowout, "В чате {} забанили участника {}. Прысылаю {} сообщений".format( chat_info_in_html(message.chat), person_info_in_html(person), how_many), parse_mode='HTML') for msg_id in range(start_forwarding, end_forwarding + 1): forward(blowout, message.chat.id, msg_id) if comment: send( message.chat.id, "Ну всё, этому челу " + "бан" * (not unban_then) + "кик" * unban_then) chat = database.get('chats', ('id', message.chat.id)) system = chat['system'] chat_configs = get_system_configs(system) if not unban_then: database.change(chat_configs['ranks'][0], 'rank', 'members', ('id', person.id), ('system', system)) for chat in full_chat_list(database, system): kick(chat['id'], person.id) for channel in channel_list(database): kick(channel['id'], person.id) adm_place = admin_place(message, database) if adm_place: send(adm_place, "Пользователь {} получил(а) бан".format( person_info_in_html(person) + ', но сразу и разбан' * unban_then), parse_mode='HTML') if unban_then: unban_user(person)
def money_pay(message, person, parameters_dictionary): """Платит человеку деньги из бюджета чата""" LOG.log(f"money pay invoked to person {person.id}") database = Database() chat = database.get('chats', ('id', message.chat.id)) system = chat['system'] bot_money = database.get('systems', ('id', system))['money'] if bot_money != 'inf': bot_money = int(bot_money) p_id = person.id money = parameters_dictionary['value'] money_name_word = get_word_object( get_system_configs(system)['money_name'], 'Russian') money_name = money_name_word.cased_by_number(abs(money), if_one_then_accusative=True) person_money = get_person(message, person, system, database)['money'] if money == 0: reply(message, "Я вам запрещаю делать подобные бессмысленные запросы") elif money < 0: money = -int(money) # Делаем из отрицательного числа положительное if person_money - money >= 0: person_money -= money if bot_money != 'inf': bot_money += money sent = send( p_id, "#Финансы\n\n" f"С вашего счёта было снято {money} {money_name} в банк. " f"Теперь у вас {person_money}") sent = cf.value_marker(sent, "🔔 уведомлён(а)", "🔕 не уведомлён(а)") reply(message, 'У {} забрали {} {} в банк!'.format(person_link(person), money, money_name), parse_mode='HTML') answer = "#Финансы " + f"#f{p_id}\n\n" if bot_money != 'inf': answer += f"#Бюджет [{bot_money - money} --> {bot_money}]\n" answer += f"{person_link(person)} [{person_money + money} --> {person_money}] {sent}" send(admin_place(message, database), answer, parse_mode='HTML') else: reply( message, "У людей число {} должно быть больше нуля".format( money_name_word.genitive_plural())) else: if bot_money != 'inf' and bot_money < money: reply( message, "У нас нет столько {} в банке".format( money_name_word.genitive_plural())) else: person_money += money sent = send( p_id, "#Финансы\n\n" f"На ваш счёт было переведено {money} {money_name} из банка. " f"Теперь у вас {person_money}") sent = cf.value_marker(sent, "🔔 уведомлён(а)", "🔕 не уведомлён(а)") reply(message, '{} получил(а) из банка {} {}!'.format( person_link(person), money, money_name), parse_mode='HTML') answer = "#Финансы " + f"#f{p_id}\n\n" if bot_money != 'inf': bot_money -= money answer += f"#Бюджет [{bot_money + money} --> {bot_money}]\n" answer += f"{person_link(person)} [{person_money - money} --> {person_money}] {sent}" send(admin_place(message, database), answer, parse_mode='HTML') database.change(person_money, 'money', 'members', ('id', p_id), ('system', system)) if bot_money != 'inf': database.change(bot_money, 'money', 'systems', ('id', system))