Рефакторинг для запуска в виде модуля.
This commit is contained in:
parent
7acb795c0b
commit
d8338b0351
10 changed files with 33 additions and 40 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -1,5 +1,5 @@
|
||||||
.idea
|
.idea
|
||||||
.venv
|
.venv
|
||||||
__pycache__
|
__pycache__
|
||||||
bot.db
|
*.db
|
||||||
config.json
|
*.json
|
||||||
|
|
|
||||||
17
config.py
17
config.py
|
|
@ -1,17 +0,0 @@
|
||||||
import json
|
|
||||||
|
|
||||||
|
|
||||||
# Config = {
|
|
||||||
# api_token: "xxxxxxxx"
|
|
||||||
# }
|
|
||||||
Config = {}
|
|
||||||
|
|
||||||
|
|
||||||
def config_load():
|
|
||||||
global Config
|
|
||||||
with open('config.json', 'r') as file:
|
|
||||||
Config = json.load(file)
|
|
||||||
|
|
||||||
|
|
||||||
config_load()
|
|
||||||
print('Конфигурация загружена.')
|
|
||||||
|
|
@ -3,8 +3,8 @@ from typing import List
|
||||||
|
|
||||||
|
|
||||||
class BasicDatabase:
|
class BasicDatabase:
|
||||||
def __init__(self):
|
def __init__(self, filename: str):
|
||||||
self.conn = sqlite3.connect('bot.db')
|
self.conn = sqlite3.connect(filename)
|
||||||
self.conn.row_factory = sqlite3.Row
|
self.conn.row_factory = sqlite3.Row
|
||||||
self.cursor = self.conn.cursor()
|
self.cursor = self.conn.cursor()
|
||||||
|
|
||||||
|
|
|
||||||
0
tg/__init__.py
Normal file
0
tg/__init__.py
Normal file
|
|
@ -1,14 +1,18 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import json
|
||||||
|
|
||||||
from aiogram import Bot, Dispatcher
|
from aiogram import Bot, Dispatcher
|
||||||
|
|
||||||
import config
|
from . import handlers
|
||||||
import handlers
|
from . import tasks
|
||||||
import tasks
|
|
||||||
|
|
||||||
|
|
||||||
async def main() -> None:
|
async def main() -> None:
|
||||||
bot = Bot(token=config.Config['api_token'])
|
with open('tg.json', 'r') as file:
|
||||||
|
config = json.load(file)
|
||||||
|
print('Конфигурация загружена.')
|
||||||
|
|
||||||
|
bot = Bot(token=config['api_token'])
|
||||||
|
|
||||||
dp = Dispatcher()
|
dp = Dispatcher()
|
||||||
dp.include_router(handlers.router)
|
dp.include_router(handlers.router)
|
||||||
|
|
@ -16,5 +20,5 @@ async def main() -> None:
|
||||||
asyncio.create_task(tasks.daily_maintenance_task(bot))
|
asyncio.create_task(tasks.daily_maintenance_task(bot))
|
||||||
await dp.start_polling(bot)
|
await dp.start_polling(bot)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
|
@ -3,7 +3,7 @@ import database
|
||||||
|
|
||||||
class TgDatabase(database.BasicDatabase):
|
class TgDatabase(database.BasicDatabase):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__('tg.db')
|
||||||
|
|
||||||
self.cursor.execute("""
|
self.cursor.execute("""
|
||||||
CREATE TABLE IF NOT EXISTS chats (
|
CREATE TABLE IF NOT EXISTS chats (
|
||||||
|
|
|
||||||
0
vk/__init__.py
Normal file
0
vk/__init__.py
Normal file
17
vk/__main__.py
Normal file
17
vk/__main__.py
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
from . import handlers
|
||||||
|
from . import tasks
|
||||||
|
|
||||||
|
from vkbottle.bot import Bot as VkBot
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
with open('vk.json', 'r') as file:
|
||||||
|
config = json.load(file)
|
||||||
|
print('Конфигурация загружена.')
|
||||||
|
|
||||||
|
bot = VkBot(config['api_token'], labeler=handlers.labeler)
|
||||||
|
bot.loop_wrapper.on_startup.append(tasks.startup_task(bot.api))
|
||||||
|
bot.loop_wrapper.add_task(tasks.daily_maintenance_task(bot.api))
|
||||||
|
bot.run_forever()
|
||||||
11
vk/vk_bot.py
11
vk/vk_bot.py
|
|
@ -1,11 +0,0 @@
|
||||||
import config
|
|
||||||
import handlers
|
|
||||||
import tasks
|
|
||||||
|
|
||||||
from vkbottle.bot import Bot as VkBot
|
|
||||||
|
|
||||||
|
|
||||||
bot = VkBot(config.Config['api_token'], labeler=handlers.labeler)
|
|
||||||
bot.loop_wrapper.on_startup.append(tasks.startup_task(bot.api))
|
|
||||||
bot.loop_wrapper.add_task(tasks.daily_maintenance_task(bot.api))
|
|
||||||
bot.run_forever()
|
|
||||||
|
|
@ -3,7 +3,7 @@ import database
|
||||||
|
|
||||||
class VkDatabase(database.BasicDatabase):
|
class VkDatabase(database.BasicDatabase):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__('vk.db')
|
||||||
|
|
||||||
self.cursor.execute("""
|
self.cursor.execute("""
|
||||||
CREATE TABLE IF NOT EXISTS chats (
|
CREATE TABLE IF NOT EXISTS chats (
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue