Added working 4chan-gpt integration

This commit is contained in:
cameron 2023-03-08 00:30:50 -05:00
parent 133393bf38
commit 6f0040e9a5
4 changed files with 94 additions and 14 deletions

View File

@ -0,0 +1,71 @@
const Discord = require("discord.js");
const fetch = require("node-fetch");
const fs = require('fs');
const server = "192.168.1.70";
class Fourchat {
async prompt(input_text) {
const response = await fetch(`http://${server}:7860/run/textgen`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
data: [
`-----
--- 865467536
${input_text}
--- 865467537
`,
200,
true,
1.99,
0.18,
1,
1.15,
30,
0,
0,
1,
0,
1,
false,
]
})
});
const response_json = await response.json();
return response_json;
}
find_response(res) {
const startIndex = res.indexOf("865467537");
const output_only = res.slice(startIndex+9);
const responseIndex = output_only.indexOf(">>865467536");
const s = output_only.slice(responseIndex+12).split("---")[0];
return s.trim();
}
constructor() {
this.matches = [ "4chat", "botmention" ];
}
async action(msg) {
let chan = msg.channel;
try {
const input_text = msg.content.replace("!4chat","").replace(/<@.+?>/,"anon").trim();
console.log(`Input Text: ${input_text}`);
const output_json = await this.prompt(input_text);
const output_text = (output_json.data[0]);
const trimmed_text = this.find_response(output_text);
chan.send(trimmed_text);
} catch (e) {
chan.send(`Error: ${e}`);
}
}
}
module.exports = Fourchat;

View File

@ -17,18 +17,16 @@ class Pepe {
//returns a dank pepe //returns a dank pepe
pepe() pepe()
{ {
let dankPepe = new Discord.RichEmbed();
let selection = Math.floor(Math.random() * (this.pepesList.length)); let selection = Math.floor(Math.random() * (this.pepesList.length));
let dankPepe = new Discord.EmbedBuilder().setImage(this.pepesList[selection]);
dankPepe.setImage(this.pepesList[selection]);
return dankPepe; return dankPepe;
} }
async action(msg) { async action(msg) {
let chan = msg.channel; let chan = msg.channel;
let pepeImg = this.pepe(); let pepeImg = this.pepe();
chan.send(pepeImg); chan.send({ embeds: [pepeImg] });
} }
} }

15
main.js
View File

@ -1,6 +1,11 @@
const Discord = require("discord.js"); const Discord = require("discord.js");
const Gamedig = require('gamedig'); const Gamedig = require('gamedig');
const client = new Discord.Client({ partials: ['REACTION', 'CHANNEL', 'MESSAGE'] }); const client = new Discord.Client({ partials: [Discord.Partials.Message, Discord.Partials.Channel, Discord.Partials.Reaction], intents: [
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildMessages,
Discord.GatewayIntentBits.MessageContent,
Discord.GatewayIntentBits.GuildMembers,
] });
const fs = require('fs'); const fs = require('fs');
const request = require('request'); const request = require('request');
const rp = require('request-promise-native'); const rp = require('request-promise-native');
@ -34,11 +39,13 @@ async function main() {
} }
console.log(triggers);
client.login('MzYyNzU1MzE3MTczNTgzODcy.DK3R1A.8M22ZkNaaoHy-ifBQwVivSU7svY'); client.login('MzYyNzU1MzE3MTczNTgzODcy.DK3R1A.8M22ZkNaaoHy-ifBQwVivSU7svY');
client.on('ready', () => { client.on('ready', () => {
console.log(`Logged into Discord as ${client.user.tag}`); console.log(`Logged into Discord as ${client.user.tag}`);
}); });
client.on('message', async (msg) => { client.on('messageCreate', async (msg) => {
for(const t in triggers) { for(const t in triggers) {
if (msg.content.startsWith(`!${t}`)) { if (msg.content.startsWith(`!${t}`)) {
console.log(`+ Bot module ${triggers[t]} triggered.`); console.log(`+ Bot module ${triggers[t]} triggered.`);
@ -46,6 +53,10 @@ async function main() {
break; break;
} }
} }
if (msg.mentions.has(client.user)) {
console.log(`Bot mentioned.`);
await bot_modules[triggers['botmention']].action(msg);
}
}); });
client.on('messageReactionAdd', async (reaction, user) => { client.on('messageReactionAdd', async (reaction, user) => {
if (reaction.partial) { if (reaction.partial) {

View File

@ -4,16 +4,16 @@
"description": "", "description": "",
"main": "main.js", "main": "main.js",
"dependencies": { "dependencies": {
"discord.js": "^12.5.1", "discord.js": "^14.7.1",
"gamedig": "^1.0.37", "gamedig": "^1.0.49",
"glob": "^7.1.2", "glob": "^7.2.3",
"markov": "0.0.7", "markov": "0.0.7",
"nodemon": "^1.12.1", "nodemon": "^1.19.4",
"npm-init": "^1.3.1", "npm-init": "^1.3.1",
"request": "^2.83.0", "request": "^2.88.2",
"request-promise-native": "^1.0.5", "request-promise-native": "^1.0.9",
"sqlite3": "^5.0.2", "sqlite3": "^5.1.4",
"striptags": "^3.1.0", "striptags": "^3.2.0",
"twitter": "^1.7.1" "twitter": "^1.7.1"
}, },
"devDependencies": {}, "devDependencies": {},