Created
April 2, 2024 11:38
-
-
Save Trao-X/4fa69b7bca4e99f7a0d6d3bdab88257f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const prepareGuildContext = async (id) => { | |
let ctx = {isPublic: false} | |
try { | |
const resp = await fetch(`https://discord.com/servers/${id}`) | |
const html = await resp.text() | |
const isPublic = !/<title(?:.*?)>Page Not Found \| Discord<\/title>/g.test(html) | |
if(isPublic) { | |
const match = html.match(/<script(?: nonce=".*?")>window.__PRELOADED_STATE__ = ({.*?})(?:;?)<\/script>/) | |
if (match) { | |
const {serverPage: s} = JSON.parse(match[1]) | |
const {guild: g} = s | |
const { name, description, about, vanity_url_code, keywords, preferred_locale, created_at, approximate_member_count, social_links } = g | |
ctx = { | |
name, description, about, vanity_url_code, keywords, preferred_locale, created_at, approximate_member_count, social_links, | |
fetchedAt: new Date().toString(), | |
isPublic: true | |
} | |
} | |
} | |
} catch (error) { | |
console.error("Error fetching guild context:", error); | |
} | |
return ctx | |
} | |
;(async (prompt, msg) => { | |
if(prompt.length < 1) return "`❌` Please provide at least **1** argument! Example: `-t ai Hello World`" | |
const guild = await prepareGuildContext(msg.guild_id) | |
const sysPrompt = "You're an AI tag of a Discord bot called Assyst. Your task is to provide the most accurate resonses to user's prompts you can get. Remember, you reply as a Discord bot so keep topics safe. Context:\n\nMessage:\n```" + JSON.stringify(msg) + "```" + (guild.isPublic ? ("\nGuild:\n```" + JSON.stringify(guild) + "```") : "") | |
if(prompt === "DEBUG_PROMPT") return "```" + sysPrompt + "```" | |
const data = { | |
hint: "character", | |
messages: [ {by: "system", text: sysPrompt} , {by: "user", text: prompt} ] | |
} | |
let error = null; | |
const response = await fetch("https://ai.aesthetic.computer/api/ask", { | |
method: "POST", | |
body: JSON.stringify(data) | |
}).catch(err => error = err) | |
if(error) return "`❗` Bot has encountered an error! Please send this issue to creator at [this page](https://gist.github.com/kvbaxi/563a0cde9865652e5e70ffbb41bca737): ```" + String(error) + "```" | |
const responseText = (await response.text()) | |
.replace(/\@(everyone|here)/g, "[the funny]") | |
return responseText | |
})(args.join(" ").trim(), message); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment