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
|
# ---> Node
|
||||||
# Logs
|
# Logs
|
||||||
logs
|
logs
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"token": "Token",
|
"token": "Token",
|
||||||
"ALLOWED_IDS": ["1266775948548903026", "1151129960141037659", "1275008490959667234", "1234866477086019648", "1277611369578889277", "1242022836529266708", "1275098630059200586", "1277311957405405296", "1277936618749300760", "1275899048171409528"],
|
"ALLOWED_IDS": ["1266775948548903026", "1151129960141037659", "1275008490959667234", "1234866477086019648", "1277611369578889277", "1242022836529266708", "1275098630059200586", "1277311957405405296", "1277936618749300760", "1275899048171409528"],
|
||||||
"admin": "593524756393754635",
|
"admin": "798192964911235073",
|
||||||
"shapeGuild": "1277635303363973173",
|
"modelname": "phi3:medium",
|
||||||
"shapeChannel": "1277652579547086860"
|
"systemd": ""
|
||||||
}
|
}
|
57
index.js
57
index.js
@ -1,14 +1,25 @@
|
|||||||
const { error } = require('console');
|
//const { ollama } = require('ollama');
|
||||||
const { Client, Message, MessageAttachment } = require('discord.js-selfbot-v13');
|
import ollama from 'ollama'
|
||||||
const axios = require('axios');
|
import error from 'console';
|
||||||
const config = require('./config.json');
|
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();
|
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 () => {
|
client.on('ready', async () => {
|
||||||
console.log(`${client.user.username} is ready!`);
|
console.log(`${client.user.username} is ready!`);
|
||||||
})
|
})
|
||||||
|
|
||||||
let savedMessage;
|
let savedMessage;
|
||||||
|
let history = [{ role: 'system', content: config.systemd }];
|
||||||
let count = 0;
|
let count = 0;
|
||||||
|
|
||||||
function isAllowedUser(id) {
|
function isAllowedUser(id) {
|
||||||
@ -17,53 +28,25 @@ function isAllowedUser(id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getMessageContent(message) {
|
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;
|
if (!message.reference) return message.author.displayName + ": " + message.content;
|
||||||
else {
|
else {
|
||||||
let reply = message.channel.messages.fetch(message.reference.messageId);
|
let reply = message.channel.messages.fetch(message.reference.messageId);
|
||||||
return message.author.displayName + ": " + message.content + " `Ответ на: " + reply.author.displayName + ": " + reply.content + "`";
|
return message.author.displayName + ": " + message.content + " `Ответ на: " + reply.author.displayName + ": " + reply.content + "`";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
client.on("messageCreate", async function(message){
|
client.on("messageCreate", async function(message){
|
||||||
try {
|
try {
|
||||||
let shapeGuild = config.shapeGuild
|
history.push(newAIMessage(await getMessageContent(message)));
|
||||||
if (message.author.id == config.admin && message.content.startsWith("e ")) {
|
if (message.author.id == config.admin && message.content.startsWith("e ")) {
|
||||||
eval(message.content.substring(1));
|
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;
|
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.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++;
|
if (!isAllowedUser(message.author.id)) count++;
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
|
18
package-lock.json
generated
18
package-lock.json
generated
@ -10,7 +10,8 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.7.5",
|
"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": {
|
"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": {
|
"node_modules/p-limit": {
|
||||||
"version": "2.3.0",
|
"version": "2.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz",
|
"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",
|
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
|
||||||
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="
|
"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": {
|
"node_modules/whatwg-url": {
|
||||||
"version": "5.0.0",
|
"version": "5.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "prankbot",
|
"name": "prankbot",
|
||||||
|
"type": "module",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
@ -9,7 +10,8 @@
|
|||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"axios": "^1.7.5",
|
||||||
"discord.js-selfbot-v13": "^3.3.0",
|
"discord.js-selfbot-v13": "^3.3.0",
|
||||||
"axios": "^1.7.5"
|
"ollama": "^0.5.8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user