Exemple #1
0
 def __init__(self, access_token, group_id, api_version='5.103'):
     self.__group_id = group_id
     self.__vk_main = vk.VkApi(token=access_token, api_version=api_version)
     self.__server = longpoll.VkBotLongPoll(self.__vk_main, group_id)
     self.longpoll = longpoll
     self.__uploader = vk.upload.VkUpload(self.__vk_main)
     self.__event = None
Exemple #2
0
def main():
    try:
        session = vk_api.VkApi(token= token)
        lps = bot_longpoll.VkBotLongPoll(session, 192912095)
        for event in lps.listen():
            for view in views:
                if view.vkID not in userIds:
                    userIds.append(view.vkID)
            rawEvent = event.raw
            userId = rawEvent['object']['from_id']
            if event.raw['object']['from_id'] >= 0:
                mV = mainView.MainView(session= session, userId= userId, event= rawEvent)
                if mV.vkID not in userIds:
                    views.append(mV)
                    userIds.append(mV.vkID)
                a = threading.Thread(target= parseStuff, kwargs= {'event': rawEvent, "userId": userId})
                a.start()
            else: 
                userId = rawEvent['object']['peer_id']
                # apiV = APIView.APIView(session, userId)
                # if apiV.vkID not in apiIDs:
                #     apiViews.append(apiV)
                #     apiIDs.append(userId)
                # b = threading.Thread(target= parseAPIReq, kwargs= {'userId': userId, 'event': event})
                # b.start()
            pass
    except Exception as e:
        print(str(e))
        main()
Exemple #3
0
 def auth(self):
     """Authentificate bot as group."""
     try:
         print("You are going to log in as Полигон")
         os.system('clear')
         self.session = vk_api.VkApi(token=self.token)
         self.session._auth_token()
         print("authred")
         vk = self.session.get_api()
         global authed
         self.authed = True
         print('gAut Online')
         self.longpollserver = bot_longpoll.VkBotLongPoll(
             self.session, 172301854)
         print('gAut Online')
         self.gLPS = threading.Thread(target=self.lps,
                                      args=(self.session, ),
                                      daemon=True)
         # self.gLPS.start()
         print('gAut Online')
         self.lps(session=self.session)
         return True
     except Exception as e:
         print(e)
         pass
Exemple #4
0
 def __init__(self, group_id, token):
     self.group_id = group_id
     self.token = token
     self.vk = vk_api.VkApi(token=token)
     self.log_poller = bot_longpoll.VkBotLongPoll(self.vk, self.group_id)
     self.api = self.vk.get_api()
     self.user_states = dict()
     self.i = 0
Exemple #5
0
    def __init__(self, group_id, token):
        self.vk_api_object = vk_api.VkApi(token=token)
        self.vk_bot_watcher = poller.VkBotLongPoll(self.vk_api_object,
                                                   group_id=group_id)
        self.api = self.vk_api_object.get_api()

        # Определение констант клавиатуры
        self.KEYBOARD_START = 1  # Основная клавиатура при первом обращении к боту
        self.KEYBOARD_CITIES_PLAY = 2  # Кливиатура с подсказками для игры в "Города"
Exemple #6
0
def get_api():
    me = json.load(open('me.json'))
    apikey = me['apikey']
    group = me['group']

    v = vk.VkApi(token=apikey, api_version='5.101')
    api = v.get_api()
    gid = api.utils.resolveScreenName(screen_name=group)['object_id']
    bot = vkblp.VkBotLongPoll(v, group_id=gid)
    return bot, v, api, gid, me
Exemple #7
0
    def __init__(self, group_id, token):
        """

        :param group_id: vk group id
        :param token: token, generated vk for api
        """
        self.group_id = group_id
        self.token = token
        self.vk = vk_api.VkApi(token=token)
        self.long_poller = bot_longpoll.VkBotLongPoll(self.vk, self.group_id)
        self.api = self.vk.get_api()
Exemple #8
0
 def run(self, message_handler: Callable[[str, str], None]):
     vk_longpoll = bot_longpoll.VkBotLongPoll(self.session, self.group_id)
     for event in vk_longpoll.listen():
         print(f'* {event}')
         is_new_message = event.type == bot_longpoll.VkBotEventType.MESSAGE_NEW
         is_from_user = event.from_user
         if not is_new_message or not is_from_user:
             continue
         try:
             message_handler(event.obj.peer_id, event.obj.text)
         except Exception as e:
             print(f'! {e}')
    def __init__(self, token, group_id):
        """

        Parameters
        ----------
        token: str
            Ключ доступа к сообществу
        group_id: str
            ID сообщества

        """
        self.session = VkApi(token=token)
        self.vk_bot = bot_longpoll.VkBotLongPoll(self.session, group_id)
        self.api = self.session.get_api()
        bot_logger.info('Initialized')
        self.user_states = dict()  # peer_id -> UserState
Exemple #10
0
    def create_session(self, group_token, group_id):
        log = Log()
        log.sender = self
        log.action = 'create_session'
        log.log_var(group_id=group_id)

        try:
            api = vk_api.VkApi(token=group_token)
            log.log_var(api=api)

            self.longpoll = api_longpoll.VkBotLongPoll(api, group_id)
            self.vk_session = api.get_api()
            log.log_var(longpoll=self.longpoll, vk_session=self.vk_session)

            log.status = 'OK'
        except vk_api.VkApiError as e:
            log.status = 'Exception'
            log.log_var(exception_info=e)

        self.class_logger.log_info(log)
Exemple #11
0
import vk_api.vk_api
import vk_api.longpoll as vkl
import vk_api.bot_longpoll as vkb
import time


def write(uid, msg):
    vk.method('messages.send', {
        'peer_id': uid,
        'random_id': round(time.time() * 100000),
        'message': msg
    })


vk = vk_api.VkApi(token='')
longpoll = vkb.VkBotLongPoll(vk, 182022767)
chat_ids = [57, 82]
ccp = 2000000000

for event in longpoll.listen():
    if event.type == vkb.VkBotEventType.MESSAGE_NEW:
        if event.obj.peer_id != event.obj.from_id:
            print(event.obj)
            if event.obj['text'] == '1':
                write(event.obj['peer_id'], 'hello, chat')
            print('-' * 30)
        if event.obj.peer_id == event.obj.from_id:
            print(event.obj)
            if event.obj['text'] == '1':
                write(event.obj['peer_id'], 'hello, user')
            """ for key, value in event.obj.items():