-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
33 lines (28 loc) · 1.02 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import vk_api
from vk_api.bot_longpoll import VkBotEventType
from longpoll import VkBotLongPollFix
import logging
from objects import glob
import threading
import invoker
import config
import sqlite3
class Bot:
def __init__(self, api_token, group_id):
logging.basicConfig(
format='%(levelname)s: %(message)s', level=logging.DEBUG)
self.vk_session = vk_api.VkApi(token=api_token, api_version='5.92')
self.longpoll = VkBotLongPollFix(self.vk_session, group_id)
glob.vk = self.vk_session.get_api()
glob.upload = vk_api.VkUpload(glob.vk)
glob.db = sqlite3.connect("database.db", check_same_thread=False)
glob.c = glob.db.cursor()
def start(self):
glob.c.executescript(config.DATABASE_INIT)
glob.db.commit()
for event in self.longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
invoker.Invoker(event).invoke()
if __name__ == "__main__":
bot = Bot(config.API_KEY, config.GROUP_ID)
bot.start()