ыыыыыы

This commit is contained in:
2025-10-30 19:06:36 +03:00
parent 559265cbce
commit 0a9eb61143
4 changed files with 200 additions and 8 deletions

BIN
furry.db

Binary file not shown.

View File

@@ -1,10 +1,41 @@
# localization.py
def getstr(lang, strname): def getstr(lang, strname):
# ======== RUSSIAN ======== # ======== RUSSIAN ========
if lang == "ru" and strname == "test": return "Привет, мир!" if lang == "ru" and strname == "test": return "Привет, мир!"
if lang == "ru" and strname == "test2": return "жопа" if lang == "ru" and strname == "test2": return "жопа"
if lang == "ru" and strname == "succlang": return "Русский язык был успешно пременён!" if lang == "ru" and strname == "succlang": return "Русский язык был успешно пременён!"
# ======== FILTERS RUSSIAN ========
if lang == "ru" and strname == "filter_list": return "Список фильтров в этом чате:"
if lang == "ru" and strname == "no_filters": return "В этом чате нет фильтров."
if lang == "ru" and strname == "filter_set_usage": return "Использование: /filter set <триггер> (в ответ на сообщение)"
if lang == "ru" and strname == "filter_reply_required": return "Вы должны ответить на сообщение для установки фильтра."
if lang == "ru" and strname == "filter_unsupported_type": return "Неподдерживаемый тип сообщения. Поддерживаются: текст, фото, видео, документы, аудио, голосовые, стикеры."
if lang == "ru" and strname == "filter_set_success": return "Фильтр '{trigger}' успешно установлен!"
if lang == "ru" and strname == "filter_already_exists": return "Фильтр '{trigger}' уже существует."
if lang == "ru" and strname == "filter_remove_usage": return "Использование: /filter remove <триггер>"
if lang == "ru" and strname == "filter_remove_success": return "Фильтр '{trigger}' успешно удален."
if lang == "ru" and strname == "filter_not_found": return "Фильтр '{trigger}' не найден."
if lang == "ru" and strname == "filter_send_error": return "Ошибка при отправке медиа."
if lang == "ru" and strname == "filter_usage": return "Использование:\n/filter - показать все фильтры\n/filter set <триггер> - установить фильтр (в ответ на сообщение)\n/filter remove <триггер> - удалить фильтр"
# ======== ENGLISH ======== # ======== ENGLISH ========
if lang == "en" and strname == "test": return "Hello, world!" if lang == "en" and strname == "test": return "Hello, world!"
if lang == "en" and strname == "succlang": return "English language has been successfully applied!" if lang == "en" and strname == "succlang": return "English language has been successfully applied!"
# ======== FILTERS ENGLISH ========
if lang == "en" and strname == "filter_list": return "Filters in this chat:"
if lang == "en" and strname == "no_filters": return "No filters in this chat."
if lang == "en" and strname == "filter_set_usage": return "Usage: /filter set <trigger> (reply to a message)"
if lang == "en" and strname == "filter_reply_required": return "You must reply to a message to set a filter."
if lang == "en" and strname == "filter_unsupported_type": return "Unsupported message type. Supported: text, photos, videos, documents, audio, voice, stickers."
if lang == "en" and strname == "filter_set_success": return "Filter '{trigger}' set successfully!"
if lang == "en" and strname == "filter_already_exists": return "Filter '{trigger}' already exists."
if lang == "en" and strname == "filter_remove_usage": return "Usage: /filter remove <trigger>"
if lang == "en" and strname == "filter_remove_success": return "Filter '{trigger}' removed successfully."
if lang == "en" and strname == "filter_not_found": return "Filter '{trigger}' not found."
if lang == "en" and strname == "filter_send_error": return "Error sending media."
if lang == "en" and strname == "filter_usage": return "Usage:\n/filter - show all filters\n/filter set <trigger> - set filter (reply to a message)\n/filter remove <trigger> - remove filter"
return "String not found"

175
main.py
View File

@@ -1,10 +1,12 @@
# main.py
import logging import logging
import localization as lang import localization as lang
from telegram import Update from telegram import Update
from telegram.ext import Application, CommandHandler, ContextTypes from telegram.ext import Application, CommandHandler, MessageHandler, filters, ContextTypes
import os import os
import sqlite3 import sqlite3
# Enable logging # Enable logging
logging.basicConfig( logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
@@ -17,10 +19,22 @@ cursor = conn.cursor()
def init_db(): def init_db():
cursor.execute(''' cursor.execute('''
CREATE TABLE IF NOT EXISTS user_lang ( CREATE TABLE IF NOT EXISTS user_lang (
chatid INTEGER PRIMARY KEY NULL, chatid INTEGER PRIMARY KEY,
lang TEXT DEFAULT 'no' lang TEXT DEFAULT 'no'
) )
''') ''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS filters (
id INTEGER PRIMARY KEY AUTOINCREMENT,
chatid INTEGER,
trigger TEXT,
content_type TEXT,
text_content TEXT,
file_id TEXT,
caption TEXT,
UNIQUE(chatid, trigger)
)
''')
conn.commit() conn.commit()
init_db() init_db()
@@ -54,11 +68,11 @@ async def set_lang(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
try: try:
userlang = str(context.args[0]) userlang = str(context.args[0])
try: try:
cursor.execute("INSERT INTO user_lang (chatid, lang) VALUES (?, ?)", (chat_id, userlang)) # omfg cursor.execute("INSERT INTO user_lang (chatid, lang) VALUES (?, ?)", (chat_id, userlang))
except: except:
fuckinnothing = "fuckinnothing" pass
cursor.execute("UPDATE user_lang SET lang = ? WHERE chatid = ?", (userlang, chat_id)) # omfg cursor.execute("UPDATE user_lang SET lang = ? WHERE chatid = ?", (userlang, chat_id))
conn.commit() conn.commit()
cursor.execute("SELECT lang FROM user_lang WHERE chatid = ?", (chat_id,)) cursor.execute("SELECT lang FROM user_lang WHERE chatid = ?", (chat_id,))
row = cursor.fetchone() row = cursor.fetchone()
@@ -66,14 +80,161 @@ async def set_lang(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
except: except:
await update.message.reply_text('/lang en\n/lang ru') await update.message.reply_text('/lang en\n/lang ru')
async def filtercmd(update: Update, context: ContextTypes.DEFAULT_TYPE):
chat = update.effective_chat
chat_id = chat.id
cursor.execute("SELECT lang FROM user_lang WHERE chatid = ?", (chat_id,))
row = cursor.fetchone()
user_lang = row[0] if row else "en"
if not context.args:
cursor.execute("SELECT trigger, content_type FROM filters WHERE chatid = ?", (chat_id,))
filters_list = cursor.fetchall()
if filters_list:
filter_text = lang.getstr(user_lang, "filter_list") + "\n"
for i, (trigger, content_type) in enumerate(filters_list, 1):
type_emoji = {
'text': '📝',
'photo': '🖼',
'video': '🎥',
'document': '📎',
'audio': '🎵',
'voice': '🎤',
'sticker': '🤡'
}.get(content_type, '')
filter_text += f"{i}. {type_emoji} {trigger}\n"
await update.message.reply_text(filter_text)
else:
await update.message.reply_text(lang.getstr(user_lang, "no_filters"))
return
action = context.args[0].lower()
if action == "set":
if len(context.args) < 2:
await update.message.reply_text(lang.getstr(user_lang, "filter_set_usage"))
return
if not update.message.reply_to_message:
await update.message.reply_text(lang.getstr(user_lang, "filter_reply_required"))
return
trigger = context.args[1].lower()
replied_message = update.message.reply_to_message
content_type = 'text'
text_content = None
file_id = None
caption = None
if replied_message.text:
content_type = 'text'
text_content = replied_message.text
elif replied_message.photo:
content_type = 'photo'
file_id = replied_message.photo[-1].file_id
caption = replied_message.caption
elif replied_message.video:
content_type = 'video'
file_id = replied_message.video.file_id
caption = replied_message.caption
elif replied_message.document:
content_type = 'document'
file_id = replied_message.document.file_id
caption = replied_message.caption
elif replied_message.audio:
content_type = 'audio'
file_id = replied_message.audio.file_id
caption = replied_message.caption
elif replied_message.voice:
content_type = 'voice'
file_id = replied_message.voice.file_id
elif replied_message.sticker:
content_type = 'sticker'
file_id = replied_message.sticker.file_id
else:
await update.message.reply_text(lang.getstr(user_lang, "filter_unsupported_type"))
return
try:
cursor.execute(
"INSERT INTO filters (chatid, trigger, content_type, text_content, file_id, caption) VALUES (?, ?, ?, ?, ?, ?)",
(chat_id, trigger, content_type, text_content, file_id, caption)
)
conn.commit()
await update.message.reply_text(lang.getstr(user_lang, "filter_set_success").format(trigger=trigger))
except sqlite3.IntegrityError:
await update.message.reply_text(lang.getstr(user_lang, "filter_already_exists").format(trigger=trigger))
elif action == "remove":
if len(context.args) < 2:
await update.message.reply_text(lang.getstr(user_lang, "filter_remove_usage"))
return
trigger = context.args[1].lower()
cursor.execute("DELETE FROM filters WHERE chatid = ? AND trigger = ?", (chat_id, trigger))
conn.commit()
if cursor.rowcount > 0:
await update.message.reply_text(lang.getstr(user_lang, "filter_remove_success").format(trigger=trigger))
else:
await update.message.reply_text(lang.getstr(user_lang, "filter_not_found").format(trigger=trigger))
else:
await update.message.reply_text(lang.getstr(user_lang, "filter_usage"))
async def handle_messages(update: Update, context: ContextTypes.DEFAULT_TYPE):
if update.message.text and update.message.text.startswith('/'):
return
if update.message.from_user.is_bot:
return
chat = update.effective_chat
chat_id = chat.id
message_text = update.message.text or update.message.caption or ""
if not message_text:
return
cursor.execute("SELECT trigger, content_type, text_content, file_id, caption FROM filters WHERE chatid = ?", (chat_id,))
filters_list = cursor.fetchall()
for trigger, content_type, text_content, file_id, caption in filters_list:
if trigger.lower() in message_text.lower():
try:
if content_type == 'text':
await update.message.reply_text(text_content)
elif content_type == 'photo':
await update.message.reply_photo(file_id, caption=caption)
elif content_type == 'video':
await update.message.reply_video(file_id, caption=caption)
elif content_type == 'document':
await update.message.reply_document(file_id, caption=caption)
elif content_type == 'audio':
await update.message.reply_audio(file_id, caption=caption)
elif content_type == 'voice':
await update.message.reply_voice(file_id)
elif content_type == 'sticker':
await update.message.reply_sticker(file_id)
break # Only trigger one filter per message
except Exception as e:
logging.error(f"Error sending media: {e}")
await update.message.reply_text(lang.getstr("en", "filter_send_error"))
break
def main() -> None: def main() -> None:
application = Application.builder().token(bottoken).build() application = Application.builder().token(bottoken).build()
application.add_handler(CommandHandler("start", start)) application.add_handler(CommandHandler("start", start))
application.add_handler(CommandHandler("lang", set_lang)) application.add_handler(CommandHandler("lang", set_lang))
application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_messages))
application.add_handler(CommandHandler("filter", filtercmd))
application.run_polling(allowed_updates=Update.ALL_TYPES) application.run_polling(allowed_updates=Update.ALL_TYPES)
if __name__ == "__main__": if __name__ == "__main__":
main() main()