Initial sugoma-local-ai commit
This commit is contained in:
parent
15cf28be75
commit
ce0360133b
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,5 @@
|
||||
config.json
|
||||
|
||||
# ---> Node
|
||||
# Logs
|
||||
logs
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"token": "Token",
|
||||
"ALLOWED_IDS": ["1266775948548903026", "1151129960141037659", "1275008490959667234", "1234866477086019648", "1277611369578889277", "1242022836529266708", "1275098630059200586", "1277311957405405296", "1277936618749300760", "1275899048171409528"],
|
||||
"admin": "593524756393754635",
|
||||
"shapeGuild": "1277635303363973173",
|
||||
"shapeChannel": "1277652579547086860"
|
||||
"admin": "798192964911235073",
|
||||
"modelname": "phi3:medium",
|
||||
"systemd": ""
|
||||
}
|
57
index.js
57
index.js
@ -1,14 +1,25 @@
|
||||
const { error } = require('console');
|
||||
const { Client, Message, MessageAttachment } = require('discord.js-selfbot-v13');
|
||||
const axios = require('axios');
|
||||
const config = require('./config.json');
|
||||
//const { ollama } = require('ollama');
|
||||
import ollama from 'ollama'
|
||||
import error from 'console';
|
||||
import { Client, Message, MessageAttachment } from 'discord.js-selfbot-v13';
|
||||
import axios from 'axios';
|
||||
import config from './config.json' with { type: "json" };
|
||||
const client = new Client();
|
||||
|
||||
function newAIMessage(text) {
|
||||
return { role: 'user', content: text }
|
||||
}
|
||||
|
||||
function requestAIMessage(prevmessages) {
|
||||
return ollama.chat({ model: config.modelname, messages: prevmessages, stream: false})
|
||||
}
|
||||
|
||||
client.on('ready', async () => {
|
||||
console.log(`${client.user.username} is ready!`);
|
||||
})
|
||||
|
||||
let savedMessage;
|
||||
let history = [{ role: 'system', content: config.systemd }];
|
||||
let count = 0;
|
||||
|
||||
function isAllowedUser(id) {
|
||||
@ -17,53 +28,25 @@ function isAllowedUser(id) {
|
||||
}
|
||||
|
||||
async function getMessageContent(message) {
|
||||
if (message.attachments.size > 0) {
|
||||
try {
|
||||
const attachment = message.attachments.first();
|
||||
|
||||
if (!attachment.url) {
|
||||
console.error('URL вложения не найден.');
|
||||
return "Я нихуя не понял.";
|
||||
}
|
||||
|
||||
const response = await axios.get(attachment.url, { responseType: 'arraybuffer' });
|
||||
|
||||
if (!response.data) {
|
||||
console.error('Ошибка: response.data is undefined.');
|
||||
return "Я нихуя не понял.";
|
||||
}
|
||||
|
||||
const buffer = Buffer.from(response.data, 'binary');
|
||||
const file = new MessageAttachment(buffer, attachment.name);
|
||||
|
||||
if (message.content) return { content: `${message.author.displayName}: ${message.content} `, files: [file] };
|
||||
else return {files: [file]};
|
||||
} catch (error) {
|
||||
console.error('Ошибка при получении файла:', error.message);
|
||||
return message.author.displayName + ": " + message.content + " ";
|
||||
}
|
||||
} else {
|
||||
if (!message.reference) return message.author.displayName + ": " + message.content;
|
||||
else {
|
||||
let reply = message.channel.messages.fetch(message.reference.messageId);
|
||||
return message.author.displayName + ": " + message.content + " `Ответ на: " + reply.author.displayName + ": " + reply.content + "`";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
client.on("messageCreate", async function(message){
|
||||
try {
|
||||
let shapeGuild = config.shapeGuild
|
||||
history.push(newAIMessage(await getMessageContent(message)));
|
||||
if (message.author.id == config.admin && message.content.startsWith("e ")) {
|
||||
eval(message.content.substring(1));
|
||||
}
|
||||
else if (message.guild.id != shapeGuild && (message.author.id != client.user.id && (message.mentions.users.get(client.user.id) || isAllowedUser(message.author.id) || (!isAllowedUser && count % 5 == 0) || (message.reference && message.channel.messages.cache.get(message.reference.messageId).author.id == client.user.id)))) {
|
||||
else if ((message.author.id != client.user.id && (message.mentions.users.get(client.user.id) || isAllowedUser(message.author.id) || (!isAllowedUser && count % 5 == 0) || (message.reference && message.channel.messages.cache.get(message.reference.messageId).author.id == client.user.id)))) {
|
||||
savedMessage = message;
|
||||
client.guilds.cache.get(shapeGuild).channels.cache.get(config.shapeChannel).send(await getMessageContent(message));
|
||||
}
|
||||
else if (message.guild.id == shapeGuild && message.author.bot && savedMessage) {
|
||||
savedMessage.channel.sendTyping();
|
||||
savedMessage.channel.send("<@" + savedMessage.author.id + "> " + message.content);
|
||||
let aimessage = (await requestAIMessage(history)).message.content
|
||||
history.push({role: 'assistant', content: aimessage});
|
||||
savedMessage.channel.send("<@" + savedMessage.author.id + "> " + aimessage);
|
||||
}
|
||||
if (!isAllowedUser(message.author.id)) count++;
|
||||
} catch(error) {
|
||||
|
18
package-lock.json
generated
18
package-lock.json
generated
@ -10,7 +10,8 @@
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"axios": "^1.7.5",
|
||||
"discord.js-selfbot-v13": "^3.3.0"
|
||||
"discord.js-selfbot-v13": "^3.3.0",
|
||||
"ollama": "^0.5.8"
|
||||
}
|
||||
},
|
||||
"node_modules/@discordjs/builders": {
|
||||
@ -428,6 +429,15 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/ollama": {
|
||||
"version": "0.5.8",
|
||||
"resolved": "https://registry.npmjs.org/ollama/-/ollama-0.5.8.tgz",
|
||||
"integrity": "sha512-frBGdfSV34i7JybLZUeyCYDx0CMyDiG4On8xOK+cNRWM04HImhoWgIMpF4p7vTkQumadbSxOteR7SZyKqNmOXg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"whatwg-fetch": "^3.6.20"
|
||||
}
|
||||
},
|
||||
"node_modules/p-limit": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz",
|
||||
@ -663,6 +673,12 @@
|
||||
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
|
||||
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="
|
||||
},
|
||||
"node_modules/whatwg-fetch": {
|
||||
"version": "3.6.20",
|
||||
"resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.6.20.tgz",
|
||||
"integrity": "sha512-EqhiFU6daOA8kpjOWTL0olhVOF3i7OrFzSYiGsEMB8GcXS+RrzauAERX65xMeNWVqxA6HXH2m69Z9LaKKdisfg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/whatwg-url": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
|
||||
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
"name": "prankbot",
|
||||
"type": "module",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
@ -9,7 +10,8 @@
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"axios": "^1.7.5",
|
||||
"discord.js-selfbot-v13": "^3.3.0",
|
||||
"axios": "^1.7.5"
|
||||
"ollama": "^0.5.8"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user