initial commit
This commit is contained in:
commit
3901a59b68
3 files changed
+96
No files matched your search
@@ -0,0 +1,2 @@
|
|||||||
|
DISCORD_TOKEN=YOUR_DISCORD_TOKEN
|
||||||
|
GEMINI_API_KEY=YOUR_GEMINI_API_KEY
|
||||||
@@ -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)
|
||||||
@@ -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
|
||||||
Reference in new issue
Block a user