Spaces:
Runtime error
Runtime error
Upload 9 files
Browse files- .gitignore +7 -0
- Dockerfile +23 -0
- events/messageCreate.ts +59 -0
- events/ready.ts +5 -0
- main.ts +61 -0
- nodemon.json +7 -0
- package-lock.json +0 -0
- package.json +27 -0
- tsconfig.json +13 -0
.gitignore
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
node_modules
|
2 |
+
.env
|
3 |
+
main.js
|
4 |
+
.data
|
5 |
+
spotify.data
|
6 |
+
youtube.data
|
7 |
+
test.ts
|
Dockerfile
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM ghcr.io/puppeteer/puppeteer:latest
|
2 |
+
|
3 |
+
# Set environment variables
|
4 |
+
ENV TOKEN=MTAyOTExOTAzMzEwODM0NDg0Mw.GHRuSg.UJGFPx7vbUBU23sHWzUPastwQXwsi1aWZnKjho \
|
5 |
+
MSGCHANNEL=1226099247963832351 \
|
6 |
+
ACCESS_TOKEN=2f763b38ad6c26368f5b6d3c86b2089bb98acfd4 \
|
7 |
+
CHARACTER_ID=PH7dDFG7FXHnEIcTw8maMJypt142z7HLYqt6Vdz88YE
|
8 |
+
|
9 |
+
# Set the working directory
|
10 |
+
WORKDIR /code
|
11 |
+
|
12 |
+
# Copy package.json and install dependencies
|
13 |
+
COPY package*.json ./
|
14 |
+
RUN npm install
|
15 |
+
|
16 |
+
# Copy the rest of the application code
|
17 |
+
COPY . .
|
18 |
+
|
19 |
+
# Expose any necessary ports
|
20 |
+
EXPOSE 7860
|
21 |
+
|
22 |
+
# Command to run the application
|
23 |
+
CMD ["npm", "start", "--host", "0.0.0.0", "--port", "7860"]
|
events/messageCreate.ts
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const { PermissionsBitField } = require("discord.js");
|
2 |
+
|
3 |
+
async function cleanDiscordMessageContent(messageContent: any) {
|
4 |
+
messageContent = messageContent.replace(/<@!?\d+>/g, "");
|
5 |
+
messageContent = messageContent.replace(/<#\d+>/g, "");
|
6 |
+
messageContent = messageContent.replace(/<@&\d+>/g, "");
|
7 |
+
messageContent = messageContent.replace(/<a?:\w+:\d+>|[\x00-\x19]/g, "");
|
8 |
+
messageContent = messageContent.replace(/[^ -~]+/g, "");
|
9 |
+
return messageContent.trim();
|
10 |
+
}
|
11 |
+
|
12 |
+
module.exports = async (
|
13 |
+
client: any,
|
14 |
+
message: any,
|
15 |
+
chatClient: any,
|
16 |
+
characterName: string
|
17 |
+
) => {
|
18 |
+
if (message.author.bot || !message.content) {
|
19 |
+
return;
|
20 |
+
}
|
21 |
+
if (!(message.channel.id === process.env.MSGCHANNEL)) {
|
22 |
+
return;
|
23 |
+
}
|
24 |
+
|
25 |
+
try {
|
26 |
+
let msgContent = await cleanDiscordMessageContent(message.content);
|
27 |
+
if (!chatClient) {
|
28 |
+
return;
|
29 |
+
}
|
30 |
+
try {
|
31 |
+
if (
|
32 |
+
!message.member
|
33 |
+
.permissionsIn(message.channel)
|
34 |
+
.has(PermissionsBitField.Flags.KickMembers)
|
35 |
+
) {
|
36 |
+
message?.member?.setNickname(`Talking to: ${characterName}`);
|
37 |
+
}
|
38 |
+
} catch (error) {
|
39 |
+
console.log(error);
|
40 |
+
}
|
41 |
+
await message.channel.permissionOverwrites.edit(
|
42 |
+
message.channel.guild.roles.everyone,
|
43 |
+
{ SendMessages: false }
|
44 |
+
);
|
45 |
+
const response = await chatClient.sendAndAwaitResponse(
|
46 |
+
`${msgContent}`,
|
47 |
+
true
|
48 |
+
);
|
49 |
+
await message.channel.send(`${response.text}`);
|
50 |
+
await message.channel.permissionOverwrites.edit(
|
51 |
+
message.channel.guild.roles.everyone,
|
52 |
+
{ SendMessages: true }
|
53 |
+
);
|
54 |
+
|
55 |
+
return;
|
56 |
+
} catch (error) {
|
57 |
+
console.error(error);
|
58 |
+
}
|
59 |
+
};
|
events/ready.ts
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
module.exports = (client: any, a: any, b: any, characterName: any) => {
|
2 |
+
console.log(
|
3 |
+
`Logged in as ${client.user.tag}!, the character is ${characterName}`
|
4 |
+
);
|
5 |
+
};
|
main.ts
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import "dotenv/config";
|
2 |
+
import { ActivityType, Client, GatewayIntentBits } from "discord.js";
|
3 |
+
import CharacterAI = require("node_characterai");
|
4 |
+
const {
|
5 |
+
Guilds,
|
6 |
+
MessageContent,
|
7 |
+
GuildMessages,
|
8 |
+
GuildMembers,
|
9 |
+
GuildVoiceStates,
|
10 |
+
} = GatewayIntentBits;
|
11 |
+
const client = new Client({
|
12 |
+
intents: [
|
13 |
+
Guilds,
|
14 |
+
MessageContent,
|
15 |
+
GuildMessages,
|
16 |
+
GuildMembers,
|
17 |
+
GuildVoiceStates,
|
18 |
+
],
|
19 |
+
});
|
20 |
+
const characterAI = new CharacterAI();
|
21 |
+
|
22 |
+
const fs = require("fs");
|
23 |
+
const eventFiles = fs
|
24 |
+
.readdirSync("./events")
|
25 |
+
.filter((file: any) => file.endsWith(".ts"));
|
26 |
+
|
27 |
+
let chatClient: any;
|
28 |
+
let characterName: any;
|
29 |
+
const connectCai = async () => {
|
30 |
+
try {
|
31 |
+
await characterAI.authenticateWithToken(process.env.ACCESS_TOKEN);
|
32 |
+
} catch (error) {
|
33 |
+
console.log(error);
|
34 |
+
}
|
35 |
+
try {
|
36 |
+
chatClient = await characterAI.createOrContinueChat(
|
37 |
+
process.env.CHARACTER_ID
|
38 |
+
);
|
39 |
+
let characterinfo = await characterAI.fetchCharacterInfo(
|
40 |
+
process.env.CHARACTER_ID
|
41 |
+
);
|
42 |
+
characterName = characterinfo.name;
|
43 |
+
await client.user.setPresence({
|
44 |
+
activities: [
|
45 |
+
{ name: `${characterinfo.name}`, type: ActivityType.Playing },
|
46 |
+
],
|
47 |
+
});
|
48 |
+
for (const file of eventFiles) {
|
49 |
+
const event = require(`./events/${file}`);
|
50 |
+
const eventName = file.split(".")[0]; // Assuming your files are named "eventname.js"
|
51 |
+
client.on(eventName, (message) => {
|
52 |
+
event(client, message, chatClient, characterName);
|
53 |
+
});
|
54 |
+
}
|
55 |
+
} catch (error) {
|
56 |
+
console.log(error);
|
57 |
+
}
|
58 |
+
};
|
59 |
+
|
60 |
+
connectCai();
|
61 |
+
client.login(process.env.TOKEN);
|
nodemon.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"exec": "ts-node -r tsconfig-paths/register",
|
3 |
+
"watch": ["./"],
|
4 |
+
"ext": "ts",
|
5 |
+
"ignore": ["node_modules/*",".env"],
|
6 |
+
"delay": "1000"
|
7 |
+
}
|
package-lock.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
package.json
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"dependencies": {
|
3 |
+
"axios": "^1.4.0",
|
4 |
+
"discord.js": "^14.11.0",
|
5 |
+
"dotenv": "^16.1.3",
|
6 |
+
"node_characterai": "^1.2.1",
|
7 |
+
"nodemon": "^2.0.22",
|
8 |
+
"ts-node": "^10.9.1"
|
9 |
+
},
|
10 |
+
"name": "miku-bot",
|
11 |
+
"version": "1.0.0",
|
12 |
+
"main": "indes.js",
|
13 |
+
"devDependencies": {
|
14 |
+
"@swc/core": "^1.3.61",
|
15 |
+
"@swc/helpers": "^0.5.1",
|
16 |
+
"regenerator-runtime": "^0.13.11",
|
17 |
+
"tsconfig-paths": "^4.2.0"
|
18 |
+
},
|
19 |
+
"scripts": {
|
20 |
+
"start": "nodemon main.ts",
|
21 |
+
"test": "nodemon test.ts"
|
22 |
+
},
|
23 |
+
"keywords": [],
|
24 |
+
"author": "ruriko123",
|
25 |
+
"license": "ISC",
|
26 |
+
"description": ""
|
27 |
+
}
|
tsconfig.json
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"compilerOptions": {
|
3 |
+
"lib": [
|
4 |
+
"es2020", "esnext"
|
5 |
+
],
|
6 |
+
"module": "commonjs",
|
7 |
+
"target": "es2020",
|
8 |
+
"baseUrl": "./",
|
9 |
+
"paths": {
|
10 |
+
"@utils/*":["utils/*"]
|
11 |
+
}
|
12 |
+
}
|
13 |
+
}
|