Beispiel #1
0
 def func(self):
     try:
         user_id = self.text
         if len(str(user_id)) > 0:
             if not int(user_id) in db.white:
                 if self.mode == '+':
                     db.white.append(int(user_id))
                     self.result['message'] = UEngine.get_link_by_id(
                         user_id) + ' добавлен в белый список'
                 else:
                     self.result['message'] = UEngine.get_link_by_id(
                         user_id) + ' не состоит в белом списке'
             else:
                 if self.mode == '-':
                     db.white.remove(int(user_id))
                     self.result['message'] = UEngine.get_link_by_id(
                         user_id) + ' удален из белого списка'
                 else:
                     self.result['message'] = UEngine.get_link_by_id(
                         user_id) + ' уже в белом списке'
             UEngine.reset_privilege()
         else:
             self.result['message'] = 'Не правильная команда.'
         return True
     except Exception as e:
         self.result['message'] = str(e)
         return False
 def func(self):
     try:
         user_id = self.text
         if len(str(user_id)) > 0 and UEngine.user_exist_in_chat(user_id):
             if not int(user_id) in db.moders:
                 if self.mode == '+':
                     db.moders.append(int(user_id))
                     self.result['message'] = UEngine.get_link_by_id(
                         user_id) + ' добавлен в модеры'
                 else:
                     self.result['message'] = UEngine.get_link_by_id(
                         user_id) + ' не является модером'
             else:
                 if self.mode == '-':
                     db.moders.remove(int(user_id))
                     self.result['message'] = UEngine.get_link_by_id(
                         user_id) + ' удален из модеров'
                 else:
                     self.result['message'] = UEngine.get_link_by_id(
                         user_id) + ' уже в модерах'
             UEngine.reset_privilege()
         else:
             self.result['message'] = 'Не правильная команда.'
         return True
     except Exception as e:
         self.result['message'] = str(e)
         return False
 def func(self):
     try:
         if self.user == var.czarID:
             user_id = self.text
             if len(str(user_id)) > 0 and UEngine.user_exist_in_chat(user_id):
                 if not int(user_id) in db.admins:
                     if self.mode == '+':
                         db.admins.append(int(user_id))
                         self.result['message'] = UEngine.get_link_by_id(user_id) + ' добавлен в админы'
                     else:
                         self.result['message'] = UEngine.get_link_by_id(user_id) + ' не является админом'
                 else:
                     if self.mode == '-':
                         db.admins.remove(int(user_id))
                         self.result['message'] = UEngine.get_link_by_id(user_id) + ' удален из админов'
                     else:
                         self.result['message'] = UEngine.get_link_by_id(user_id) + ' уже в админах'
                 UEngine.reset_privilege()
             else:
                 self.result['message'] = 'Не правильная команда.'
         else:
             self.result['message'] = 'Недостаточно прав.'
         return True
     except Exception as e:
         self.result['message'] = str(e)
         return False
 def func(self):
     try:
         if random.randint(0, 100) <= 10:
             self.result['message'] = 'Никто'
         else:
             self.result['message'] = UEngine.get_link_by_id(
                 random.choice(VK().Messages().get_chat()['users']))
         return True
     except Exception as e:
         self.result['message'] = str(e)
         return False
 def func(self):
     try:
         user_id = self.text
         if len(str(user_id)) > 0:
             if not int(user_id) in db.black:
                 if self.mode == '+':
                     db.black.append(int(user_id))
                     self.result['message'] = UEngine.get_link_by_id(user_id) + ' добавлен в черный список'
                 else:
                     self.result['message'] = UEngine.get_link_by_id(user_id) + ' не состоит в черном списке'
             else:
                 if self.mode == '-':
                     db.black.remove(int(user_id))
                     self.result['message'] = UEngine.get_link_by_id(user_id) + ' удален из черного списка'
                 else:
                     self.result['message'] = UEngine.get_link_by_id(user_id) + ' уже в черном списке'
             from Plugins import BlackCheck
             BlackCheck.BlackCheckPlugin().func()
         else:
             self.result['message'] = 'Не правильная команда.'
         return True
     except Exception as e:
         self.result['message'] = str(e)
         return False
 def func(self):
     try:
         err = 0
         history = VK().Messages().get_history(count=10, offset=10)['items']
         for item in history:
             if 'action' in item:
                 if item['action'] == 'chat_title_update':
                     VK().Messages().edit_chat(title=var.title)
                     err += 1
                 if item['action'] == 'chat_photo_update':
                     VK().Messages().set_chat_photo(file=var.photo)
                     err += 1
                 if item['action'] == 'chat_invite_user_by_link':
                     if not int(item['action_mid']) in db.black:
                         VK().Messages().send(
                             message='Добро пожаловать, ' +
                             UEngine.get_link_by_id(item['action_mid']) +
                             '.')
                     else:
                         VK().Messages().remove_chat_user(
                             user_id=item['action_mid'])
                 if item['action'] == 'chat_invite_user' or item[
                         'action'] == 'chat_kick_user':
                     if not int(item['from_id']) in db.privilege:
                         VK().Messages().remove_chat_user(
                             user_id=item['from_id'])
                         if int(item['from_id']) != int(item['action_mid']):
                             VK().Messages().remove_chat_user(
                                 user_id=item['action_mid'])
                         err += 1
                     response = VK().Messages().get_chat()['users']
                     for user in response:
                         if int(user) in db.black:
                             VK().Messages().remove_chat_user(user_id=user)
                             err += 1
         chat_title = VK().Messages().get_chat()['title']
         if chat_title != var.title:
             VK().Messages().edit_chat(title=var.title)
             err += 1
         if err == 0:
             VK().Messages().send(message='Нарушений не обнаруженно.')
         if err > 0:
             VK().Messages().send(
                 message='Я как всегда на страже этой беседы.')
         return True
     except Exception as e:
         self.result['message'] = str(e)
         return False
Beispiel #7
0
    def start():
        try:
            Log.show_info(f'Бот запущен.')
            if not var.main_start:
                VK().Messages().send(message=f'{var.name}: Успешный запуск.')
                var.globalID = VK().Messages().get_history(
                    count=1)['items'][0]['id']
                var.main_start = True
            all_users = VK().Messages().get_chat()['users']
            main_users = VK().Messages().get_chat(
                chat_id=var.chatCheck)['users']
            for au in all_users:
                if au not in main_users:
                    VK().Messages().send(
                        message=
                        'Сорен, тут можно находится только тем, кто есть в основной беседе.'
                    )
                    VK().Messages().remove_chat_user(user_id=au)
            while True:
                chat_title = VK().Messages().get_chat()['title']
                if chat_title != var.title:
                    VK().Messages().edit_chat(title=var.title)
                response = VK().Messages().get_history(
                    count=10,
                    offset=-10,
                    start_message_id=var.globalID,
                    fields='first_name, last_name')
                if var.bot_online:
                    VK().Account().set_online()
                else:
                    VK().Account().set_offline()
                if not response is False:
                    response = response['items'][::-1]
                    if len(response):
                        for item in response:
                            if int(
                                    item['id']
                            ) > var.globalID and item['from_id'] != var.mainID:
                                var.globalID = int(item['id'])
                                s = ''
                                p = None
                                if 'body' in item:
                                    if len(item['body']) > 0:
                                        s += str.encode(
                                            item['body']).decode('utf-8')
                                    else:
                                        s += '(None)'
                                log = s
                                u = item['from_id']
                                if 'attachments' in item:
                                    log += ' ('
                                    for a in item['attachments']:
                                        tp = a['type']
                                        a = a[str(tp)]
                                        if tp == 'doc':
                                            log += f'doc: {a["title"]} (doc{a["owner_id"]}_{a["id"]}'
                                            if 'access_key' in a:
                                                log += '_' + a["access_key"]
                                            log += ')'
                                        if tp == 'photo':
                                            p = a['photo_604']
                                            log += f'photo: photo{a["owner_id"]}_{a["id"]}'
                                            if 'access_key' in a:
                                                log += '_' + a["access_key"]
                                        if tp == 'audio':
                                            log += f'audio: {a["artist"]} - ' \
                                                   f'{a["title"]} (audio{a["owner_id"]}_{a["id"]}'
                                            if 'access_key' in a:
                                                log += '_' + a["access_key"]
                                            log += ')'
                                        if tp == 'video':
                                            log += f'video: {a["title"]} (video{a["owner_id"]}_{a["id"]}'
                                            if 'access_key' in a:
                                                log += '_' + a["access_key"]
                                            log += ')'
                                        if tp == 'link':
                                            log += f'link: {a["title"]} ({a["url"]})'
                                        if tp == 'sticker':
                                            log += f'sticker: product_{a["product_id"]} id_{a["sticker_id"]}'
                                        log += ', '
                                    log = log[:len(log) - 2]
                                    log += ')'
                                if 'geo' in item:
                                    log += f' (geo: {item["geo"]["coordinates"]})'
                                    if 'place' in item['geo']:
                                        log += f' ({item["geo"]["place"]["country"]}, {item["geo"]["place"]["city"]})'
                                if 'fwd_messages' in item:
                                    log += f' (forward: '
                                    for mes in item['fwd_messages']:
                                        log += f'{UEngine.get_username_by_id(mes["user_id"])} ({mes["body"]}), '
                                    log = log[:len(log) - 2]
                                    log += ')'
                                Log.show_vk(
                                    UEngine.get_username_by_id(u) + ': ' + log)
                                f = open('DB\\money.txt', 'r')
                                money = eval(f.read())
                                if not str(item['user_id']) in money:
                                    money[str(item['user_id'])] = 0
                                money[str(item['user_id'])] += 1
                                f.close()
                                f = open('DB\\money.txt', 'w')
                                f.write(str(money))
                                f.close()
                                if 'action' in item:
                                    main_users = VK().Messages().get_chat(
                                        chat_id=var.chatCheck)['users']
                                    if item['action'] == 'chat_title_update':
                                        VK().Messages().edit_chat(
                                            title=var.title)
                                    if item['action'] == 'chat_photo_update':
                                        VK().Messages().set_chat_photo(
                                            file=var.photo)
                                    if item['action'] == 'chat_invite_user_by_link':
                                        if not int(
                                                item['user_id']
                                        ) in db.black and item[
                                                'user_id'] in main_users:
                                            VK().Messages().send(
                                                message='Добро пожаловать, ' +
                                                UEngine.get_link_by_id(
                                                    item['user_id']) + '.')
                                        else:
                                            VK().Messages().send(
                                                message=
                                                'Сорен, ты в ЧС или тебя нет в основной беседе.'
                                            )
                                            VK().Messages().remove_chat_user(
                                                user_id=item['action_mid'])
                                    if item['action'] == 'chat_invite_user' or item[
                                            'action'] == 'chat_kick_user':
                                        if not int(item['from_id']
                                                   ) in db.privilege:
                                            VK().Messages().remove_chat_user(
                                                user_id=item['from_id'])
                                            if int(item['from_id']) != int(
                                                    item['action_mid']):
                                                VK().Messages(
                                                ).remove_chat_user(
                                                    user_id=item['action_mid'])
                                        response = VK().Messages().get_chat(
                                        )['users']
                                        for user in response:
                                            if int(
                                                    user
                                            ) in db.black or not user in main_users:
                                                VK().Messages(
                                                ).remove_chat_user(
                                                    user_id=user)
                                    if item['action'] == 'chat_pin_message':
                                        if not int(item['action_mid']
                                                   ) in db.admins:
                                            VK().Messages().remove_chat_user(
                                                user_id=item['action_mid'])
                                            VK().Messages().unpin()
                                            VK().Messages().pin(
                                                message_id=var.
                                                pin_id['message_id'])
                                        else:
                                            var.pin_id['message_id'] = item[
                                                'id']
                                            f = open('DB\\pin.txt', 'w')
                                            f.write(str(var.pin_id))
                                            f.close()
                                    if item['action'] == 'chat_unpin_message':
                                        if not int(item['action_mid']
                                                   ) in db.admins:
                                            VK().Messages().remove_chat_user(
                                                user_id=item['action_mid'])
                                        VK().Messages().pin(
                                            message_id=var.pin_id['message_id']
                                        )
                                elif len(s) > 2:
                                    if (var.debug_mode and int(u) == var.czarID
                                        ) or not var.debug_mode:
                                        c = s[0]
                                        if c in var.prefixes:
                                            s = s[1:len(s)]
                                            md = 'a' if int(
                                                u) in db.admins else (
                                                    'm' if int(u) in db.moders
                                                    else 'u')

                                            def start_thread():
                                                Engine().cmd(
                                                    s, p, u, md, item['id'])

                                            Thread(target=start_thread).start()
                                    else:
                                        if s[0] in var.prefixes:
                                            VK().Messages().send(
                                                'Бот в режиме дебага.')
        except Exception as e:
            Log.show_error(e)
Beispiel #8
0
    def func(self):
        try:
            vote_time = 60
            _correct = True
            _start = True
            var.getting = True
            if not '?' in self.text or not '!' in self.text:
                _correct = False
            if not _correct:
                if '~' in self.text:
                    _correct = True
            command = ''
            if _correct:
                _id = 0
                q = ''
                a = []
                _users_voted = []
                _messages_voted = []
                _cmd_active = False
                if '~' in self.text:
                    command = self.text[1:self.text.find(' ')]
                    mes = self.text[self.text.find(' ') + 1:]
                    a.append(['Да', 0])
                    a.append(['Нет', 0])
                    try:
                        mes = UEngine.get_user_id(mes)
                        _id = int(mes)
                        if _id in db.privilege or _id in db.white or not UEngine.user_exist_in_chat(
                                _id):
                            _start = False
                        mes = UEngine.get_link_by_id(_id)
                        _cmd_active = True
                    except Exception as _exc:
                        print(_exc)
                        _start = False
                else:
                    q = self.text[:self.text.find('?')]
                    mes = self.text[self.text.find('?') + 2:]
                if not _cmd_active:
                    while mes != '':
                        a.append([mes[:mes.find('!')], 0])
                        mes = mes[mes.find('!') + 2:]

                def get():
                    _all_votes = 0
                    _start_in = VK().Messages().get_history(count=0)['count']
                    time.sleep(vote_time)
                    _end = VK().Messages().get_history(count=0)['count']
                    cnt = (_end - _start_in) * 2
                    response = VK().Messages().get_history(count=cnt)['items']
                    response = response[::-1]
                    for item in response:
                        _a = item['body'].lower()
                        i = 0
                        _in = True
                        if not item[
                                'user_id'] in _users_voted and not '?' in _a:
                            while i < len(a) and _in:
                                if a[i][0].lower() == _a:
                                    a[i][1] += 1
                                    _all_votes += 1
                                    _in = False
                                i += 1
                            if not _in:
                                _users_voted.append(item['user_id'])
                                _messages_voted.append(item['id'])
                    _str = 'Результаты:\n'
                    i = 0

                    def f(n, c):
                        _f = 100 / n * c
                        if c == 0:
                            return '0.00'
                        else:
                            return str(int(_f * 100) / 100)

                    def sort_col(n):
                        return n[1]

                    if _all_votes > 0:
                        a.sort(key=sort_col, reverse=True)

                        while i < len(a):
                            _str += str(a[i][1]) + '. ' + a[i][0] + ' [%' + f(
                                _all_votes, a[i][1]) + ']\n'
                            i += 1
                        VK().Messages().send(
                            message=_str,
                            forward_messages=', '.join(
                                str(_exc_in) for _exc_in in _messages_voted))
                        if command:
                            if a[0][1] == a[1][1]:
                                self.result['message'] = 'Живи' + self.text
                            elif a[0][0] == 'Да':
                                VK().Messages().remove_chat_user(user_id=_id)
                            else:
                                self.result['message'] = 'Живи' + self.text
                        return True
                    else:
                        self.result['message'] = 'Голосование отменено.'

                def start(question=None, answers=None):
                    _str = f'[{vote_time} sec] Голосование: '
                    if command != '':
                        _str += command + ' -> ' + mes
                    else:
                        _str += question
                    _str += '\n'
                    _i = 1
                    for i in answers:
                        _str += '- ' + i[0] + '\n'
                        _i += 1
                    VK().Messages().send(message=_str)
                    get()

                if _start:
                    start(q, a)
                else:
                    self.result['message'] = 'Ошибка'
            else:
                self.result['message'] = 'Неправильная команда'
            return True
        except Exception as e:
            self.result['message'] = str(e)
            return False