commit 3901a59b6818efb55c83d31125e9223268b77f25 Author: timurtom Date: Sun Nov 1 01:49:13 2026 +0200 initial commit diff --git a/.env b/.env new file mode 100644 index 0000000..8b15c50 --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +DISCORD_TOKEN=YOUR_DISCORD_TOKEN +GEMINI_API_KEY=YOUR_GEMINI_API_KEY \ No newline at end of file diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..b7ef19e --- /dev/null +++ b/bot.py @@ -0,0 +1,72 @@ +import os +import discord +from discord.ext import commands +from dotenv import load_dotenv +from google import genai +from google.genai import types + +# Загружаем переменные из .env +load_dotenv() +DISCORD_TOKEN = os.getenv("DISCORD_TOKEN") +GEMINI_API_KEY = os.getenv("GEMINI_API_KEY") + +# Инициализируем клиент Gemini +ai_client = genai.Client(api_key=GEMINI_API_KEY) + +# Настройка интентов Discord +intents = discord.Intents.default() +intents.message_content = True + +bot = commands.Bot(command_prefix="!", intents=intents) + +@bot.event +async def on_ready(): + print(f"Logged in as {bot.user.name} (ID: {bot.user.id}) 🚀") + +@bot.event +async def on_message(message): + # Игнорируем сообщения от самого бота + if message.author == bot.user: + return + + # Проверяем пинг бота + if bot.user in message.mentions: + # Очищаем пинг из текста + prompt = message.content.replace(f"<@{bot.user.id}>", "").replace(f"<@!{bot.user.id}>", "").strip() + + if not prompt: + await message.reply("вась") + return + + async with message.channel.typing(): + try: + # Передаем системное правило через config + response = ai_client.models.generate_content( + model="gemini-2.5-flash", + contents=prompt, + config=types.GenerateContentConfig( + system_instruction=( + "Ты дискорд-бот. Твоё главное и нерушимое правило: " + "НИКОГДА И НИ ПРИ КАКИХ ОБСТОЯТЕЛЬСТВАХ НЕ ПИШИ КОД. " + "Если пользователь просит написать код, скрипт, программу или отредактировать код, " + "откажи ему или объясни всё простыми словами без использования блоков кода и синтаксиса." + ) + ) + ) + + reply_text = response.text + + # Делим длинные ответы (лимит Discord — 2000 символов) + if len(reply_text) > 2000: + for i in range(0, len(reply_text), 2000): + await message.channel.send(reply_text[i:i+2000]) + else: + await message.reply(reply_text) + + except Exception as e: + print(f"Error communicating with Gemini: {e}") + await message.reply("damn, something broke trying to reach the AI 😭") + + await bot.process_commands(message) + +bot.run(DISCORD_TOKEN) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..9ed429d --- /dev/null +++ b/requirements.txt @@ -0,0 +1,22 @@ +attrs==26.1.0 +certifi==2026.10.23 +cffi==2.1.1 +cryptography==50.0.2 +cupshelpers==1.0 +dbus-python==1.5.1 +filelock==4.0.10 +nftables==0.1 +packaging==26.3 +psutil==7.2.2 +pycairo==1.29.2 +pycparser==3.12 +pycups==2.0.4 +pygdbmi==0.11.0.0 +PyGObject==3.58.1 +sentry-sdk==2.73.0 +smbus==1.1 +TBB @ file:///build/onetbb/src/build/python/python_build +ufw==0.36.2 +urllib3==2.8.0 +VapourSynth==81 +wheel==0.48.0