From 4c5d60a110f97cab6657d378529cb2397cce72fe Mon Sep 17 00:00:00 2001 From: vMohammad Date: Sat, 3 Aug 2024 07:28:15 +0300 Subject: [PATCH] Shakespearean plugin (#28) * feat(ServerListIndicators): toggle compact and optimization (#27) * Shakespearean plugin * Fixes --------- Co-authored-by: verysillycat Co-authored-by: thororen1234 <78185467+thororen1234@users.noreply.github.com> --- README.md | 3 +- .../shakeSpearean.dev/index.ts | 41 ++++++++++ .../shakeSpearean.dev/native.ts | 76 +++++++++++++++++++ src/utils/constants.ts | 4 + 4 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 src/equicordplugins/shakeSpearean.dev/index.ts create mode 100644 src/equicordplugins/shakeSpearean.dev/native.ts diff --git a/README.md b/README.md index c09f9f0f..52e0fcc5 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ An enhanced version of [Vencord](https://github.com/Vendicated/Vencord) by [Vend - Request for plugins from Discord.
-Extra included plugins (107 additional plugins) +Extra included plugins (118 additional plugins) - AllCallTimers by MaxHerbold and D3SOX - AltKrispSwitch by newwares @@ -114,6 +114,7 @@ An enhanced version of [Vencord](https://github.com/Vendicated/Vencord) by [Vend - SearchFix by Jaxx - SekaiStickers by MaiKokain - ServerSearch by camila314 +- Shakespearean by vmohammad - ShowBadgesInChat by Inbestigator and KrystalSkull - Slap by Korbo - SoundBoardLogger by Moxxie, fres, echo (maintained by thororen) diff --git a/src/equicordplugins/shakeSpearean.dev/index.ts b/src/equicordplugins/shakeSpearean.dev/index.ts new file mode 100644 index 00000000..95c90d80 --- /dev/null +++ b/src/equicordplugins/shakeSpearean.dev/index.ts @@ -0,0 +1,41 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { addPreSendListener, removePreSendListener, SendListener } from "@api/MessageEvents"; +import { definePluginSettings, Settings } from "@api/Settings"; +import { EquicordDevs } from "@utils/constants"; +import definePlugin, { OptionType } from "@utils/types"; +import { MessageStore } from "@webpack/common"; + +import { transferMessage } from "./native"; + + + +const presendObject: SendListener = async (channelId, msg, extra) => { + const messageRef = extra.replyOptions.messageReference; + const repliedMessage = ((messageRef?.message_id && messageRef.channel_id) && MessageStore.getMessage(messageRef?.channel_id, messageRef?.message_id)) || undefined; + msg.content = await transferMessage(msg, Settings.plugins.Shakespearean.model, repliedMessage); +}; +export default definePlugin({ + name: "Shakespearean", + description: "Makes every message you send shakespearean", + authors: [EquicordDevs.vmohammad], + dependencies: ["MessageEventsAPI"], + settings: definePluginSettings( + { + model: { + type: OptionType.STRING, + description: "Which model to use for this... thing", + default: "llama3" + } + }), + start() { + addPreSendListener(presendObject); + }, + stop() { + removePreSendListener(presendObject); + } +}); diff --git a/src/equicordplugins/shakeSpearean.dev/native.ts b/src/equicordplugins/shakeSpearean.dev/native.ts new file mode 100644 index 00000000..3f104d2e --- /dev/null +++ b/src/equicordplugins/shakeSpearean.dev/native.ts @@ -0,0 +1,76 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { MessageObject } from "@api/MessageEvents"; +import { Message } from "discord-types/general"; + +export async function transferMessage(message: MessageObject, model: string, repliedMessage?: Message) { + // you can use this on anything really + // NOTE: you need to have ollama running with cors set to *, to do this set OLLAMA_ORIGINS to *, in your envioument variables. + const req = await fetch("http://127.0.0.1:11434/api/chat", { + method: "POST", + body: JSON.stringify({ + model: model, + messages: [ + { + "role": "system", + "content": `Transform any user message into a Shakespearean style, except do not change any URLs or text matching the regex <(?:@[!&]?|#)\\d+>. Only repeat the user's message in a Shakespearean voice without acknowledging or responding to anything else. for context this is your message object *START* ${JSON.stringify(message)} *END* and this is the replied message object (if avalaible): *START* ${JSON.stringify(repliedMessage)} *END*, remember to use context in the response` + }, + { + "role": "user", + "content": "hello" + }, + { + "role": "assistant", + "content": "Hark! A gentle greeting to thee, 'tis 'hello' I say." + }, + { + "role": "user", + "content": "How are you?" + }, + { + "role": "assistant", + "content": "How art thou faring, noble soul?" + }, + { + "role": "user", + "content": "What is your name?" + }, + { + "role": "assistant", + "content": "What doth they call thee, fair entity?" + }, + { + "role": "user", + "content": "Goodbye" + }, + { + "role": "assistant", + "content": "Fare thee well, until we meet again." + }, + { + "role": "user", + "content": "Check this link: https://example.com" + }, + { + "role": "assistant", + "content": "Prithee, observe this link: https://example.com" + }, + { + content: message.content, + role: "user" + } + ], + stream: false + }), + headers: { + "Content-Type": "application/json" + } + }); + const res = await req.json(); + const msg = res.message.content; + return msg; +} diff --git a/src/utils/constants.ts b/src/utils/constants.ts index d58aea2d..cf765b88 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -551,6 +551,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({ } satisfies Record); export const EquicordDevs = Object.freeze({ + vmohammad: { + name: "vMohammad", + id: 921098159348924457n + }, nexpid: { name: "Nexpid", id: 853550207039832084n