Skip to content

Commit

Permalink
Merge pull request #39 from spongedsc/bun
Browse files Browse the repository at this point in the history
Bun as package manager and runtime
  • Loading branch information
artifishvr authored Apr 24, 2024
2 parents 26ff658 + 72aea17 commit 1239864
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 1,146 deletions.
11 changes: 10 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
node_modules
Dockerfile*
docker-compose*
.dockerignore
.git
.gitignore
README.md
.vscode
.env
node_modules
.editorconfig
temp
11 changes: 5 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
FROM node:lts-alpine
FROM oven/bun:alpine
ENV NODE_ENV=production

RUN npm install -g pnpm

WORKDIR /app

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

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

COPY . .

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

import fs from 'fs';
import path from 'path';
import { constants } from 'node:fs';
import { access, mkdir } from "node:fs/promises";
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 @@ -34,7 +29,12 @@ backendsocket.on("connect_error", (err) => {
console.error(`Error connecting to backend: ${err.message}`);
});

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

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

let pronounsresponse = response.data;


const response = await fetch(`https://pronoundb.org/api/v2/lookup?platform=discord&ids=${userid}`);
let pronounsresponse = await response.json();;

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

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

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

connection.subscribe(player);
player.play(resource);
Expand Down
11 changes: 3 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
{
"name": "spongegpt",
"version": "1.28.4",
"version": "1.29.0",
"description": "custom AI chatbot for discord",
"main": "index.js",
"type": "module",
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js"
"start": "bun index.js",
"dev": "bun --watch 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 1239864

Please sign in to comment.