Beispiel #1
0
def create_new_chat_handler(call):
    """Add new system of chats"""
    member = output.get_member(call.message.chat.id, call.from_user.id)
    if member.status in ("creator", "administrator"):
        complicated_commands.create_new_chat(call)
    else:
        output.answer_callback(call.id, "Для жмака нужно иметь админку")
Beispiel #2
0
 def get_person(self, parameters_dictionary: dict):
     """Gets possible target person"""
     if 'person_id' in parameters_dictionary.keys():
         return get_member(-1001268084945,
                           parameters_dictionary['person_id']).user
     if self.message.reply_to_message:  # Сообщение является ответом
         return left_new_or_else_member(self.message.reply_to_message)
     return self.message.from_user
Beispiel #3
0
def unban_user(person):
    """Remove ban from user"""
    database = Database()
    chats_to_unban = database.get_many('chats', ('violators_ban', 2))
    for chat in chats_to_unban:
        member = get_member(chat['id'], person.id)
        if member and member.status in ('left', 'kicked'):
            unban(chat['id'], person.id)
Beispiel #4
0
def message_about_add_chat_handler(call):
    """Tell users to use /add_chat x"""
    if output.get_member(call.message.chat.id, call.from_user.id).status in \
            ("creator", "administrator"):
        output.edit_text("Введите команду\n\n/add_chat x\n\n"
                         "Где x это номер системы вашего чата (ищите его в /help вашего чата",
                         call.message.chat.id, call.message.message_id)
    else:
        output.answer_callback(call.id, "Для жмака нужно иметь админку")
def get_bot_rights(message):
    """Check bot admin rights in the current chat"""
    info = get_member(message.chat.id, get_me().id)
    response = f'''Полномочия бота:

{value_marker(info.can_change_info, '✅', '❌')} Изменение профиля группы  
{value_marker(info.can_delete_messages, '✅', '❌')} Удаление сообщений  
{value_marker(info.can_restrict_members, '✅', '❌')} Блокировка участников  
{value_marker(info.can_invite_users, '✅', '❌')} Пригласительные ссылки  
{value_marker(info.can_pin_messages, '✅', '❌')} Закрепление сообщений  
{value_marker(info.can_promote_members, '✅', '❌')} Добавление администраторов
'''
    reply(message, response)
Beispiel #6
0
def add_person(message, person, system, database, system_configs):
    """Add entry to database about some person in some system"""
    chat_member_status = get_member(message.chat.id, person.id).status
    boss_commands_requirements = system_configs["commands"]["boss"]
    if chat_member_status == "creator":
        rank = system_configs['ranks'][-1]
    elif chat_member_status == 'administrator' and isinstance(
            boss_commands_requirements, list):
        rank = boss_commands_requirements[
            0]  # minimal rank to use admin commands
    else:
        rank = system_configs['ranks'][1]
    person_entry = (person.id, system, person.username, person.first_name,
                    rank, 0, 0, 0, 0, 0)
    database.append(person_entry, 'members')
Beispiel #7
0
def parameters_analyze(text: str,
                       value_necessary=True,
                       default_value=None,
                       value_positive=False) -> dict:
    """
    :param text: text of user's message
    :type text: str

    :param value_necessary: if it's necessary to return dictionary_of_parameters['value']

    :param default_value: default dictionary_of_parameters['value']

    :param value_positive: if dictionary_of_parameters['value'] must be positive
    :type value_positive: bool

    :return: parameters required for some command
    :rtype: dict
    """
    dictionary_of_parameters = {'command': remove_slash_and_bot_mention(text)}
    if default_value is not None:
        dictionary_of_parameters['value'] = default_value
    parts_of_the_message = text.split()[1:]
    for part in parts_of_the_message:
        if is_integer(part) and get_member(-1001268084945, int(part)):
            dictionary_of_parameters['person_id'] = int(part)
            parts_of_the_message.remove(part)
            break
    for part in parts_of_the_message:
        if is_integer(part):
            dictionary_of_parameters['value'] = int(part)
            parts_of_the_message.remove(part)
            break
    dictionary_of_parameters['comment'] = ' '.join(parts_of_the_message)
    if not value_necessary or ('value' in dictionary_of_parameters.keys() and
                               (dictionary_of_parameters['value'] > 0
                                or not value_positive)):
        return dictionary_of_parameters
    return dict()
Beispiel #8
0
 def run(self):
     for member in self.members:
         user = get_member(self.chat_id, member['id'])
         if user:
             member_update(self.system_id, user.user)
     reply(self.sent, "Теперь записи о людях максимально свежие!")