diff --git a/assets/banner.jpg b/assets/banner.jpg new file mode 100755 index 0000000..ea7012f Binary files /dev/null and b/assets/banner.jpg differ diff --git a/assets/banner.png b/assets/banner.png new file mode 100755 index 0000000..2b3ecc8 Binary files /dev/null and b/assets/banner.png differ diff --git a/assets/logo.jpg b/assets/logo.jpg new file mode 100755 index 0000000..e92156f Binary files /dev/null and b/assets/logo.jpg differ diff --git a/assets/logo.png b/assets/logo.png new file mode 100755 index 0000000..c76ec7d Binary files /dev/null and b/assets/logo.png differ diff --git a/main.py b/main.py new file mode 100755 index 0000000..4d56233 --- /dev/null +++ b/main.py @@ -0,0 +1,136 @@ +import discord +from discord import app_commands +from discord.ext import commands, tasks +import requests +import threading +import random +import time +import json +from llama_cpp import Llama + +with open("settings.json", "r") as file: + settings = json.load(file) + +LLM = Llama( + model_path=settings["llama"]["model"], + n_ctx=settings["llama"]["ctx"], + n_threads=settings["llama"]["threads"], + n_gpu_layers=settings["llama"]["gpu"], + top_k=settings["llama"]["top_k"], + repeat_penality=settings["llama"]["repeat_penality"], + echo=False, + verbose=False) +if len(list(settings["llama"]["system_token"])) == 2: + SYS_PROMPT = list(settings["llama"]["system_token"])[0] + settings["llama"]["system_prompt"] + list(settings["llama"]["system_token"])[1] +elif len(list(settings["llama"]["system_token"])) == 1: + SYS_PROMPT = list(settings["llama"]["system_token"])[0] + settings["llama"]["system_prompt"] +else: + SYS_PROMPT = settings["llama"]["system_prompt"] +USER_TOKEN = list(settings["llama"]["user_token"]) +SYNC = settings["bot"]["sync"] +UWU_ACT = list(settings["uwu"]["act"]) +UWU_REPLACE = dict(settings["uwu"]["replace"]) +CONSONNES = list(settings["uwu"]["consonnes"]) +LISTE_GIF = list(settings["gifs"]) + +intents = discord.Intents.default() +bot = commands.Bot(command_prefix="+", intents=intents, help_command=None) +tree = bot.tree +queue = [] + +def texttouwu(text: str) -> str: + uwu_text = "" + for i in range(1, len(text) - 1): + if random.randint(0, 2) == 1: + if text[i] in UWU_REPLACE: + uwu_text += UWU_REPLACE[text[i]] + elif text[i - 1] == " " and text[i] in CONSONNES: + uwu_text += f"{text[i]}-{text[i]}" + else: + uwu_text += text[i] + else: + if text[i - 1] == " " and random.randint(0, 10) == 0: + uwu_text += random.choice(UWU_ACT) + uwu_text += text[i] + return text[0] + uwu_text + text[-1] + + +def get_gif(gif): + if gif.lower() == "list": + output = "Here is the list of all possible gifs:\n" + for name in LISTE_GIF: + output += name + ", " + return output[:-2] + gif = requests.get(f"https://api.otakugifs.xyz/gif?reaction={gif.lower()}").json() + try: + return gif["url"] + except: + return f"No gif '{gif}'" + + +def generate(prompt): + if len(USER_TOKEN) == 2: + user_prompt = USER_TOKEN[0] + prompt + USER_TOKEN[1] + elif len(USER_TOKEN) == 1: + user_prompt = USER_TOKEN[0] + prompt + else: + user_prompt = prompt + res = LLM(SYS_PROMPT + user_prompt, max_tokens=128, stop=[""]) + story = str(res["choices"][0]["text"]) + return story[2:].capitalize() + + +def send_answer(id, token, content): + url = f"https://discord.com/api/v10/webhooks/{id}/{token}/messages/@original" + json = { + "content": content, + } + code = requests.patch(url, data=json) + return code + + +def work(): + global queue + while True: + if not queue == []: + output = queue[0][1](queue[0][0]) + send_answer(queue[0][2], queue[0][3], output) + queue.pop(0) + time.sleep(0.1) + return None + + +@bot.tree.command(name="speak", description="Speak with Whispers!") +@app_commands.describe(message="The message you want to send to Whispers.") +async def speak(interaction, message: str): + global queue + await interaction.response.defer(thinking=True) + queue.append([message, generate, interaction.application_id, interaction.token]) + + +@bot.tree.command(name="uwu", description="Translate your message to uwu") +@app_commands.describe(nonuwu="The message you want to translate.") +async def uwu(interaction, nonuwu: str): + global queue + await interaction.response.defer(thinking=True) + queue.append([nonuwu, texttouwu, interaction.application_id, interaction.token]) + + +@bot.tree.command( + name="gif", + description="Send a gif corresponding to a topic, type 'list' to get the possible gifs", +) +@app_commands.describe(topic="The the topic of the gif") +async def gif(interaction, topic: str): + global queue + await interaction.response.defer(thinking=True) + queue.append([topic, get_gif, interaction.application_id, interaction.token]) + + +@bot.event +async def on_ready(): + if SYNC == "1": + await tree.sync() + +threading.Thread(target=work).start() +bot.run(settings["bot"]["token"]) diff --git a/settings.json b/settings.json new file mode 100755 index 0000000..b61ec45 --- /dev/null +++ b/settings.json @@ -0,0 +1,134 @@ +{ + "llama": { + "model": "YOUR LLAMA .GGUF HERE", + "ctx": 16000, + "threads": 4, + "gpu": 0, + "top_k": 50, + "repeat_penality": 1.5, + "system_prompt": "SYS PROMPT HERE", + "system_token": ["<|im_start|>system\n", "<|im_end|>\n"], + "user_token": ["<|im_start|>user\n", "<|im_end|>\n<|im_start|>assistant"] + }, + "bot": { + "token": "YOUR TOKEN HERE", + "sync": 0 + }, + "uwu": { + "act": [ + "*sweat* ", + "*screams* ", + "*purr* ", + "*blush* ", + "*meow* ", + "😊 ", + "\u2764\uFE0F ", + "\u2728 ", + "🌼 ", + "🌟 ", + "🥺 ", + "💕 ", + "\u0028\u002A\u005E\u03C9\u005E\u002A\u0029 ", + "\u0028\u2044\u0020\u2044\u2022\u2044\u03C9\u2044\u2022\u2044\u0020\u2044\u0029 " + ], + "replace": { + "l": "w", + "r": "w", + "L": "W", + "R": "W" + }, + "consonnes": [ + "b", + "c", + "d", + "f", + "g", + "h", + "j", + "k", + "l", + "m", + "n", + "p", + "q", + "r", + "s", + "t", + "v", + "w", + "x", + "y", + "z" + ] + }, + "gifs": [ + "airkiss", + "angrystare", + "bite", + "bleh", + "blush", + "brofist", + "celebrate", + "cheers", + "clap", + "confused", + "cool", + "cry", + "cuddle", + "dance", + "drool", + "evillaugh", + "facepalm", + "handhold", + "happy", + "headbang", + "hug", + "kiss", + "laugh", + "lick", + "love", + "mad", + "nervous", + "no", + "nom", + "nosebleed", + "nuzzle", + "nyah", + "pat", + "peek", + "pinch", + "poke", + "pout", + "punch", + "roll", + "run", + "sad", + "scared", + "shout", + "shrug", + "shy", + "sigh", + "sip", + "slap", + "sleep", + "slowclap", + "smack", + "smile", + "smug", + "sneeze", + "sorry", + "stare", + "stop", + "surprised", + "sweat", + "thumbsup", + "tickle", + "tired", + "wave", + "wink", + "woah", + "yawn", + "yay", + "yes" + ] +}