change some things
This commit is contained in:
parent
6805a93744
commit
ad6a359ac7
1 changed files with 3 additions and 8 deletions
11
index.js
11
index.js
|
|
@ -18,10 +18,8 @@ const client = new Client({
|
||||||
const OLLAMA_URL = "http://localhost:11434/api/generate";
|
const OLLAMA_URL = "http://localhost:11434/api/generate";
|
||||||
const OWNER_ID = config.discord.owner;
|
const OWNER_ID = config.discord.owner;
|
||||||
|
|
||||||
// Eval command function
|
|
||||||
async function executeEval(code, message) {
|
async function executeEval(code, message) {
|
||||||
try {
|
try {
|
||||||
// Create a safe context with limited access
|
|
||||||
const context = {
|
const context = {
|
||||||
message,
|
message,
|
||||||
client,
|
client,
|
||||||
|
|
@ -31,7 +29,6 @@ async function executeEval(code, message) {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Execute the code
|
|
||||||
const result = eval(`
|
const result = eval(`
|
||||||
(function() {
|
(function() {
|
||||||
const { message, client, config, console } = arguments[0];
|
const { message, client, config, console } = arguments[0];
|
||||||
|
|
@ -144,7 +141,6 @@ client.on(Events.MessageCreate, async (message) => {
|
||||||
const isDM = message.channel.type === 1;
|
const isDM = message.channel.type === 1;
|
||||||
const isReply = message.reference !== null;
|
const isReply = message.reference !== null;
|
||||||
|
|
||||||
// Check for eval command first (owner only)
|
|
||||||
if (message.author.id === OWNER_ID && isMentioned) {
|
if (message.author.id === OWNER_ID && isMentioned) {
|
||||||
let content = message.content.replace(`<@${client.user.id}>`, "").trim();
|
let content = message.content.replace(`<@${client.user.id}>`, "").trim();
|
||||||
|
|
||||||
|
|
@ -160,7 +156,6 @@ client.on(Events.MessageCreate, async (message) => {
|
||||||
const result = await executeEval(code, message);
|
const result = await executeEval(code, message);
|
||||||
const output = result !== undefined ? String(result) : "undefined";
|
const output = result !== undefined ? String(result) : "undefined";
|
||||||
|
|
||||||
// Handle long outputs
|
|
||||||
if (output.length > 1900) {
|
if (output.length > 1900) {
|
||||||
const chunks = output.match(/.{1,1900}/g) || [output];
|
const chunks = output.match(/.{1,1900}/g) || [output];
|
||||||
await message.reply("```js\n" + chunks[0] + "```");
|
await message.reply("```js\n" + chunks[0] + "```");
|
||||||
|
|
@ -178,7 +173,6 @@ client.on(Events.MessageCreate, async (message) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we should respond normally
|
|
||||||
const shouldRespond =
|
const shouldRespond =
|
||||||
isMentioned || isDM || (isReply && (await isReplyToBot(message)));
|
isMentioned || isDM || (isReply && (await isReplyToBot(message)));
|
||||||
|
|
||||||
|
|
@ -194,7 +188,7 @@ client.on(Events.MessageCreate, async (message) => {
|
||||||
|
|
||||||
if (!prompt) {
|
if (!prompt) {
|
||||||
await message.reply(
|
await message.reply(
|
||||||
"Hey! You mentioned me but didn't say anything. What's up?",
|
"hey! you mentioned me but didn't say anything. what's up?",
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -222,7 +216,8 @@ client.on(Events.MessageCreate, async (message) => {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error handling message:", error);
|
console.error("Error handling message:", error);
|
||||||
await message.reply(
|
await message.reply(
|
||||||
"Oops! Something went wrong while processing your message.",
|
"oops! something went wrong while processing your message. Error handling message:",
|
||||||
|
error,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue