Compare commits

...

18 Commits

Author SHA1 Message Date
df9d8b295d Merge branch 'main' of ssh://git.smartsoltech.kr:2222/trevor/post_bot
Some checks failed
continuous-integration/drone/push Build is failing
2025-09-05 17:51:30 +09:00
61b9bd8cfe tmp commit 2025-09-05 17:50:25 +09:00
f079ad2cf7 adding channels and groups fixing
Some checks failed
continuous-integration/drone/push Build is failing
2025-09-05 15:47:09 +09:00
e7a40b4718 add_group, add_Channel process modification
Some checks failed
continuous-integration/drone/push Build is failing
2025-09-05 15:40:28 +09:00
443799d480 Merge branch 'v2'
Some checks failed
continuous-integration/drone/push Build is failing
2025-09-05 15:19:43 +09:00
c2b56ba8d6 Merge pull request 'v2' (#11) from v2 into main
Some checks failed
continuous-integration/drone/push Build is failing
Reviewed-on: #11
2025-09-05 06:03:46 +00:00
97b20d799e Merge pull request 'database fix' (#10) from v2 into main
Some checks failed
continuous-integration/drone/push Build is failing
Reviewed-on: #10
2025-09-05 05:41:07 +00:00
2dc77169da Merge pull request 'database creation fixes' (#9) from v2 into main
Some checks failed
continuous-integration/drone/push Build is failing
Reviewed-on: #9
2025-09-05 05:36:23 +00:00
7c80a51a82 Merge pull request 'database creation process' (#8) from v2 into main
Some checks failed
continuous-integration/drone/push Build is failing
Reviewed-on: #8
2025-09-05 05:32:57 +00:00
0365659d55 Merge pull request 'migrations fix' (#7) from v2 into main
Some checks failed
continuous-integration/drone/push Build is failing
Reviewed-on: #7
2025-09-05 05:27:38 +00:00
1c87721611 Merge pull request 'migration fix' (#6) from v2 into main
Some checks failed
continuous-integration/drone/push Build is failing
Reviewed-on: #6
2025-09-05 05:23:12 +00:00
c6574efee3 Merge pull request 'model channels' (#5) from v2 into main
Some checks failed
continuous-integration/drone/push Build is failing
Reviewed-on: #5
2025-09-05 05:17:27 +00:00
fb620e5d38 Merge branch 'v2'
Some checks failed
continuous-integration/drone/push Build is failing
2025-09-05 14:06:13 +09:00
3788fca8ee ssMerge branch 'main' of ssh://git.smartsoltech.kr:2222/trevor/post_bot
Some checks failed
continuous-integration/drone/push Build is failing
2025-09-05 05:01:39 +00:00
fb82b7f270 chmod +x lacally added 2025-09-05 05:01:02 +00:00
5f3bac5bf5 Merge pull request 'script fix docker-compose vs docker compose' (#3) from v2 into main
Some checks failed
continuous-integration/drone/push Build is failing
Reviewed-on: #3
2025-09-05 05:00:07 +00:00
a39a7bf910 Merge pull request 'script fix' (#2) from v2 into main
Some checks failed
continuous-integration/drone/push Build is failing
Reviewed-on: #2
2025-09-05 04:57:49 +00:00
aa88880a52 Merge pull request 'migrations + util scripts' (#1) from v2 into main
Some checks failed
continuous-integration/drone/push Build is failing
Reviewed-on: #1
2025-09-05 04:56:06 +00:00
5 changed files with 123 additions and 29 deletions

0
bin/update.sh Normal file → Executable file
View File

View File

@@ -1,18 +1,60 @@
from telegram import Update from telegram import Update
from telegram.ext import ContextTypes from telegram.ext import ContextTypes, ConversationHandler, CommandHandler, MessageHandler, filters
from db import AsyncSessionLocal from db import AsyncSessionLocal
from models import Channel from models import Channel
async def add_channel(update: Update, context: ContextTypes.DEFAULT_TYPE): INPUT_NAME, INPUT_LINK = range(2)
args = context.args or []
if update.message is None: async def add_channel_start(update: Update, context: ContextTypes.DEFAULT_TYPE):
return if context.user_data is None:
if len(args) < 2: context.user_data = {}
await update.message.reply_text('Используйте: /add_channel <название> <ссылка>') if update.message:
return await update.message.reply_text('Введите имя канала:')
name, link = args[0], args[1] return INPUT_NAME
async def input_channel_name(update: Update, context: ContextTypes.DEFAULT_TYPE):
if context.user_data is None:
context.user_data = {}
text = update.message.text.strip() if update.message and update.message.text else ''
context.user_data['channel_name'] = text
if update.message:
await update.message.reply_text('Теперь отправьте ссылку на канал (должна начинаться с @):')
return INPUT_LINK
async def input_channel_link(update: Update, context: ContextTypes.DEFAULT_TYPE):
if context.user_data is None:
context.user_data = {}
link = update.message.text.strip() if update.message and update.message.text else ''
if not link.startswith('@'):
if update.message:
await update.message.reply_text('Ошибка: ссылка на канал должна начинаться с @. Попробуйте снова.')
return INPUT_LINK
context.user_data['channel_link'] = link
return await save_channel(update, context)
async def save_channel(update: Update, context: ContextTypes.DEFAULT_TYPE):
if context.user_data is None:
context.user_data = {}
name = context.user_data.get('channel_name')
link = context.user_data.get('channel_link')
if not name or not link:
if update.message:
await update.message.reply_text('Ошибка: не указано название или ссылка.')
return ConversationHandler.END
async with AsyncSessionLocal() as session: async with AsyncSessionLocal() as session:
channel = Channel(name=name, link=link) channel = Channel(name=name, link=link)
session.add(channel) session.add(channel)
await session.commit() await session.commit()
await update.message.reply_text(f'Канал "{name}" добавлен.') if update.message:
await update.message.reply_text(f'Канал "{name}" добавлен.')
return ConversationHandler.END
add_channel_conv = ConversationHandler(
entry_points=[CommandHandler('add_channel', add_channel_start)],
states={
INPUT_NAME: [MessageHandler(filters.TEXT & ~filters.COMMAND, input_channel_name)],
INPUT_LINK: [MessageHandler(filters.TEXT & ~filters.COMMAND, input_channel_link)],
},
fallbacks=[]
)

View File

@@ -1,19 +1,60 @@
from telegram import Update from telegram import Update
from telegram.ext import ContextTypes from telegram.ext import ContextTypes, ConversationHandler, CommandHandler, MessageHandler, filters
from db import AsyncSessionLocal from db import AsyncSessionLocal
from models import Group from models import Group
async def add_group(update: Update, context: ContextTypes.DEFAULT_TYPE): INPUT_NAME, INPUT_LINK = range(2)
args = context.args or []
if update.message is None: async def add_group_start(update: Update, context: ContextTypes.DEFAULT_TYPE):
return if context.user_data is None:
if len(args) < 2: context.user_data = {}
await update.message.reply_text('Используйте: /add_group <название> <ссылка>') if update.message:
return await update.message.reply_text('Введите имя группы:')
name, link = args[0], args[1] return INPUT_NAME
session = AsyncSessionLocal()
group = Group(name=name, link=link) async def input_group_name(update: Update, context: ContextTypes.DEFAULT_TYPE):
session.add(group) if context.user_data is None:
session.commit() context.user_data = {}
session.close() text = update.message.text.strip() if update.message and update.message.text else ''
await update.message.reply_text(f'Группа "{name}" добавлена.') context.user_data['group_name'] = text
if update.message:
await update.message.reply_text('Теперь отправьте chat_id группы (например, -1001234567890):')
return INPUT_LINK
async def input_group_link(update: Update, context: ContextTypes.DEFAULT_TYPE):
if context.user_data is None:
context.user_data = {}
link = update.message.text.strip() if update.message and update.message.text else ''
if not link.startswith('-100'):
if update.message:
await update.message.reply_text('Ошибка: chat_id группы должен начинаться с -100. Попробуйте снова.')
return INPUT_LINK
context.user_data['group_link'] = link
return await save_group(update, context)
async def save_group(update: Update, context: ContextTypes.DEFAULT_TYPE):
if context.user_data is None:
context.user_data = {}
name = context.user_data.get('group_name')
link = context.user_data.get('group_link')
if not name or not link:
if update.message:
await update.message.reply_text('Ошибка: не указано название или ссылка.')
return ConversationHandler.END
async with AsyncSessionLocal() as session:
group = Group(name=name, link=link)
session.add(group)
await session.commit()
if update.message:
await update.message.reply_text(f'Группа "{name}" добавлена.')
return ConversationHandler.END
add_group_conv = ConversationHandler(
entry_points=[CommandHandler('add_group', add_group_start)],
states={
INPUT_NAME: [MessageHandler(filters.TEXT & ~filters.COMMAND, input_group_name)],
INPUT_LINK: [MessageHandler(filters.TEXT & ~filters.COMMAND, input_group_link)],
},
fallbacks=[]
)

View File

@@ -1,5 +1,16 @@
import os
import asyncio import asyncio
from db import init_db from db import init_db
# Проверка bot.db перед инициализацией
if os.path.exists("bot.db") and os.path.isdir("bot.db"):
print("Удаляю папку bot.db...")
import shutil
shutil.rmtree("bot.db")
if not os.path.exists("bot.db"):
print("Создаю пустой файл bot.db...")
open("bot.db", "a").close()
if __name__ == "__main__": if __name__ == "__main__":
asyncio.run(init_db()) asyncio.run(init_db())

View File

@@ -65,8 +65,8 @@ async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text(help_text, parse_mode='HTML') await update.message.reply_text(help_text, parse_mode='HTML')
# Импорт обработчиков # Импорт обработчиков
from handlers.add_channel import add_channel from handlers.add_channel import add_channel_conv
from handlers.add_group import add_group from handlers.add_group import add_group_conv
from handlers.add_button import add_button_conv from handlers.add_button import add_button_conv
from handlers.new_post import new_post_conv from handlers.new_post import new_post_conv
from handlers.group_buttons import group_buttons_conv from handlers.group_buttons import group_buttons_conv
@@ -84,8 +84,8 @@ def main():
application = Application.builder().token(TELEGRAM_TOKEN).build() application = Application.builder().token(TELEGRAM_TOKEN).build()
application.add_handler(CommandHandler('start', start)) application.add_handler(CommandHandler('start', start))
application.add_handler(CommandHandler('help', help_command)) application.add_handler(CommandHandler('help', help_command))
application.add_handler(CommandHandler('add_channel', add_channel)) application.add_handler(add_channel_conv)
application.add_handler(CommandHandler('add_group', add_group)) application.add_handler(add_group_conv)
application.add_handler(add_button_conv) application.add_handler(add_button_conv)
application.add_handler(new_post_conv) application.add_handler(new_post_conv)
application.add_handler(group_buttons_conv) application.add_handler(group_buttons_conv)