236 lines
5.7 KiB
Python
236 lines
5.7 KiB
Python
import os
|
|
import random
|
|
import discord
|
|
import requests
|
|
|
|
from dotenv import load_dotenv
|
|
from discord.ext import commands
|
|
|
|
load_dotenv()
|
|
|
|
DISCORD_TOKEN = os.getenv("dAPI_KEY")
|
|
CZCHAN_LLM_KEY = os.getenv("CZCHAN_LLM_KEY")
|
|
|
|
CHANCE = 1.0
|
|
IMAGE_FOLDER = "obruzky"
|
|
MUSIC_FOLDER = "hudba"
|
|
MAX_SIZE = int(9.9 * 1024 * 1024) # 9,9mb myslím
|
|
|
|
intents = discord.Intents.default()
|
|
intents.message_content = True
|
|
|
|
bot = commands.Bot(command_prefix="!", intents=intents)
|
|
|
|
VIDEO_EXT = (
|
|
".mp4",
|
|
".mov",
|
|
".avi",
|
|
".mkv",
|
|
".webm",
|
|
".3gp",
|
|
".3gpp",
|
|
".3g2",
|
|
)
|
|
|
|
AUDIO_EXT = (
|
|
".mp3",
|
|
".wav",
|
|
".ogg",
|
|
".flac",
|
|
".m4a",
|
|
".opus",
|
|
".3gp",
|
|
".3gpp",
|
|
".3g2",
|
|
)
|
|
|
|
files = os.listdir(IMAGE_FOLDER)
|
|
files2 = os.listdir(MUSIC_FOLDER)
|
|
|
|
PHRASES_ALL = [
|
|
"Tak uědlej JINEEJ SKUPINA VOLE TY NUDLE ČÍNSKÁ POSRANA",
|
|
"TY KURVO POSRANA ČDJ CIGAN Z USTÍ POSEDLÝ KRETEN ZE SLOVENSKO ESL",
|
|
"kordman dicx face reveal\nKORMAN JE NEGR Z OHIA",
|
|
"MÁM COKERA A KORDMANA PLNÝ ZUBY\nVOLE",
|
|
"léky",
|
|
"posedlej",
|
|
"Léky tohle nejsou hovna\nJsou to střeva\nJsou to střeva po znásilnění",
|
|
"jsem femboy z usteckého kraje a dam ti e-sex přes telefon",
|
|
"mugshot ahh negr kočka",
|
|
"Ano ale můžu být femgoy",
|
|
"OYYYY",
|
|
"Dělám to pro ženy",
|
|
"I'm not from Nová Vrchoslav 122",
|
|
"Kek faildox",
|
|
"Posedlost s 15 letím klukem btw",
|
|
"Honí si ho tomu nebo co?",
|
|
"Jeden měsíc mám troon arc a tohle jse stane",
|
|
"jsem validní femGOY",
|
|
"xestro...",
|
|
"jedy",
|
|
"POMOC LIDI\nMĚ BOLÍ MOC PÉRO Z GOONOVANÍ\n\nbolí mě to vole tak MOC\nNEMUŽU PŘESTAT DOE",
|
|
"Chtěl bych být foidka ale nemůžu doe je to nemorální",
|
|
"I gonna rape you with my slovenian BWC you fucking serbian subhuman",
|
|
"I have no friends, not online or offline\n\nI am not kidding, i can jump from my window, overdose or hang myself\nI can do it\nI gonna write a suicide note and post it on my main if that happens\nI dont care anymore",
|
|
"Similliar o algx\nIm not Mario Kart pedo i promise",
|
|
">Czech kuz?\n<Sort of.",
|
|
]
|
|
|
|
PHRASES_SNEED = [
|
|
"Tak uědlej JINEEJ SKUPINA VOLE TY NUDLE ČÍNSKÁ POSRANA",
|
|
"MÁM COKERA A KORDMANA PLNÝ ZUBY\nVOLE",
|
|
"Ano ale můžu být femgoy",
|
|
"posedlej",
|
|
"léky",
|
|
"Chtěl bych být foidka ale nemůžu doe je to nemorální",
|
|
"Posedlost s 15 letím klukem btw", # DODĚLŽI
|
|
]
|
|
|
|
PHRASES_BRIMMY = [
|
|
"TY KURVO POSRANA ČDJ CIGAN Z USTÍ POSEDLÝ KRETEN ZE SLOVENSKO ESL",
|
|
"kordman dicx face reveal\nKORMAN JE NEGR Z OHIA",
|
|
"léky",
|
|
"posedlej",
|
|
"I'm not from Nová Vrchoslav 122",
|
|
"Kek faildox",
|
|
"Jeden měsíc mám troon arc a tohle jse stane", # taky dodělži
|
|
]
|
|
|
|
# kabel zlincerald command musí mít kontrolku pro velikost souboru protože nějaké soubory mají přes 10mb což kabel nepovoluje
|
|
@bot.command()
|
|
async def zlincerald(ctx):
|
|
valid_files = []
|
|
|
|
for f in files:
|
|
path = os.path.join(IMAGE_FOLDER, f)
|
|
if os.path.getsize(path) <= MAX_SIZE:
|
|
valid_files.append(f)
|
|
|
|
chosen = random.choice(valid_files)
|
|
path = os.path.join(IMAGE_FOLDER, chosen)
|
|
await ctx.send(file=discord.File(path))
|
|
|
|
@bot.command()
|
|
async def hudba(ctx):
|
|
valid_files = []
|
|
|
|
for f in files2:
|
|
path = os.path.join(MUSIC_FOLDER, f)
|
|
if os.path.getsize(path) <= MAX_SIZE:
|
|
valid_files.append(f)
|
|
|
|
chosen = random.choice(valid_files)
|
|
path = os.path.join(MUSIC_FOLDER, chosen)
|
|
await ctx.send(file=discord.File(path))
|
|
|
|
def llm_api_call(messages):
|
|
response = requests.post(
|
|
"https://llm.czchan.org/v1/chat/completions",
|
|
headers={"Authorization": f"Bearer {CZCHAN_LLM_KEY}"},
|
|
json={
|
|
"messages": messages,
|
|
"mode": "chat",
|
|
"character": "David Šlinc",
|
|
"temperature": 0.3,
|
|
"top_p": 0.9,
|
|
"top_k": 40,
|
|
"repetition_penalty": 1.2,
|
|
"max_tokens": 512,
|
|
},
|
|
)
|
|
|
|
json_data = response.json()
|
|
return json_data["choices"][0]["message"]["content"]
|
|
|
|
|
|
message_store = {}
|
|
|
|
|
|
def log(message):
|
|
message_store[message.id] = {
|
|
"user_id": message.author.id,
|
|
"text": message.content,
|
|
"reply_to": (
|
|
message.reference.message_id
|
|
if message.reference else None
|
|
),
|
|
}
|
|
|
|
|
|
async def maybe_send(ctx, phrases):
|
|
if random.random() < CHANCE:
|
|
msg = await ctx.reply(random.choice(phrases))
|
|
log(msg)
|
|
|
|
|
|
@bot.command()
|
|
async def czchan(ctx):
|
|
await maybe_send(ctx, PHRASES_ALL)
|
|
|
|
|
|
@bot.command()
|
|
async def sneedmaster(ctx):
|
|
await maybe_send(ctx, PHRASES_SNEED)
|
|
|
|
|
|
@bot.command()
|
|
async def heckingemmy(ctx):
|
|
await maybe_send(ctx, PHRASES_BRIMMY)
|
|
|
|
|
|
@bot.command()
|
|
async def ai(ctx, *, text):
|
|
messages = [{"role": "user", "content": text}]
|
|
|
|
try:
|
|
response = llm_api_call(messages)
|
|
msg = await ctx.reply(response)
|
|
log(msg)
|
|
except:
|
|
print("LLM error")
|
|
|
|
|
|
@bot.event
|
|
async def on_message(message):
|
|
|
|
if message.author.bot:
|
|
return
|
|
|
|
log(message)
|
|
|
|
messages = []
|
|
current_id = message.id
|
|
should_reply = False
|
|
|
|
while current_id:
|
|
data = message_store.get(current_id)
|
|
if not data:
|
|
break
|
|
|
|
if data["user_id"] == bot.user.id:
|
|
should_reply = True
|
|
role = "assistant"
|
|
else:
|
|
role = "user"
|
|
|
|
messages.append({
|
|
"role": role,
|
|
"content": data["text"]
|
|
})
|
|
|
|
current_id = data["reply_to"]
|
|
|
|
messages.reverse()
|
|
|
|
if should_reply:
|
|
try:
|
|
response = llm_api_call(messages)
|
|
msg = await message.reply(response)
|
|
log(msg)
|
|
except:
|
|
print("LLM error")
|
|
|
|
await bot.process_commands(message)
|
|
|
|
|
|
bot.run(DISCORD_TOKEN) |