Skip to content

Commit

Permalink
Revert "Merge pull request #39 from spongedsc/bun"
Browse files Browse the repository at this point in the history
This reverts commit 1239864, reversing
changes made to 26ff658.
  • Loading branch information
artifishvr committed Apr 29, 2024
1 parent 1239864 commit e663a86
Show file tree
Hide file tree
Showing 6 changed files with 1,146 additions and 30 deletions.
11 changes: 1 addition & 10 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,2 @@
node_modules
Dockerfile*
docker-compose*
.dockerignore
.git
.gitignore
README.md
.vscode
.env
.editorconfig
temp
node_modules
11 changes: 6 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
FROM oven/bun:alpine
FROM node:lts-alpine
ENV NODE_ENV=production

RUN npm install -g pnpm

WORKDIR /app

COPY ["package.json", "bun.lockb", "./"]
COPY ["package.json", "pnpm-lock.yaml", "./"]

RUN bun install --frozen-lockfile --production
RUN pnpm install --prod

COPY . .

USER bun
CMD ["bun", "run", "index.js"]
CMD ["node", "index.js"]
Binary file removed bun.lockb
Binary file not shown.
33 changes: 21 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { Client, GatewayIntentBits } from 'discord.js';
import { joinVoiceChannel, createAudioPlayer, createAudioResource } from '@discordjs/voice';

import { constants } from 'node:fs';
import { access, mkdir } from "node:fs/promises";
import fs from 'fs';
import path from 'path';
import { DateTime } from 'luxon';
import axios from 'axios';

import { io } from "socket.io-client";
import { MsEdgeTTS } from "msedge-tts";

import * as dotenv from 'dotenv'

dotenv.config()

const channels = process.env.CHANNELIDS.split(",");

const backendsocket = io(process.env.BACKEND_URL, {
Expand All @@ -29,12 +34,7 @@ backendsocket.on("connect_error", (err) => {
console.error(`Error connecting to backend: ${err.message}`);
});

// Create the temp directory if it doesn't exist
try {
await access("./temp", constants.F_OK);
} catch (e) {
await mkdir("./temp", { recursive: true });
}
if (!fs.existsSync('./temp')) fs.mkdirSync('./temp');

// Map to store the last message timestamp per person
const cooldowns = new Map();
Expand Down Expand Up @@ -63,8 +63,17 @@ function shouldIReply(message) {
async function getPronouns(userid) {
// this is spagetti i'm sorry
try {
const response = await fetch(`https://pronoundb.org/api/v2/lookup?platform=discord&ids=${userid}`);
let pronounsresponse = await response.json();;
const response = await axios.get('/api/v2/lookup', {
baseURL: 'https://pronoundb.org',
params: {
platform: 'discord',
ids: userid
}
});

let pronounsresponse = response.data;



for (let userId in pronounsresponse) {
if (pronounsresponse[userId].sets.hasOwnProperty('en')) {
Expand Down Expand Up @@ -134,7 +143,7 @@ client.on("messageCreate", async message => {

// Handle long responses
if (response.length >= 2000) {
await Bun.write('./temp/how.txt', response);
fs.writeFileSync(path.resolve('./temp/how.txt'), response);
message.reply({ content: "", files: ["./temp/how.txt"], failIfNotExists: false });
return;
}
Expand Down Expand Up @@ -207,7 +216,7 @@ async function tts(message, text) {
});

const player = createAudioPlayer();
const resource = createAudioResource(Bun.file(filePath).stream());
const resource = createAudioResource(fs.createReadStream(filePath));

connection.subscribe(player);
player.play(resource);
Expand Down
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
{
"name": "spongegpt",
"version": "1.29.0",
"version": "1.28.4",
"description": "custom AI chatbot for discord",
"main": "index.js",
"type": "module",
"scripts": {
"start": "bun index.js",
"dev": "bun --watch index.js "
"start": "node index.js",
"dev": "nodemon index.js"
},
"author": "artifish",
"license": "AGPL-3.0",
"dependencies": {
"@discordjs/voice": "^0.16.1",
"axios": "^1.6.8",
"discord.js": "^14.13.0",
"dotenv": "^16.3.1",
"ffmpeg-static": "^5.2.0",
"libsodium-wrappers": "^0.7.13",
"luxon": "^3.4.4",
"msedge-tts": "^1.3.4",
"socket.io-client": "^4.7.2"
},
"devDependencies": {
"nodemon": "^3.1.0"
}
}
Loading

0 comments on commit e663a86

Please sign in to comment.