-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathindex.js
67 lines (57 loc) · 2.28 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import 'dotenv/config'
import { Client, GatewayIntentBits, Partials, ChannelType } from 'discord.js'
import config from './config/config.js'
import { askQuestion } from './chatgpt/chatgpt.js'
import { initDiscordCommands, handle_interaction_ask, handle_interaction_image, handle_interaction_remix, commandExecuters } from './discord/discord_commands.js'
import { splitAndSendResponse, MAX_RESPONSE_CHUNK_LENGTH } from './discord/discord_helpers.js'
import { initDashboard } from './dashboard/dasboard.js'
async function main() {
await initDiscordCommands()
initDashboard()
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildIntegrations,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageTyping,
GatewayIntentBits.MessageContent
],
partials: [Partials.Channel]
});
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
console.log(new Date())
});
client.on("messageCreate", async message => {
if (config.get("ENABLE_DIRECT_MESSAGES") !== true || message.channel.type != ChannelType.DM || message.author.bot) {
return;
}
const user = message.author
console.log("----Direct Message---")
console.log("Date : " + new Date())
console.log("UserId : " + user.id)
console.log("User : " + user.username)
console.log("Message : " + message.content)
console.log("--------------")
try {
let sentMessage = await user.send("Hmm, let me think...")
askQuestion(message.content, async (response) => {
if (response.length >= MAX_RESPONSE_CHUNK_LENGTH) {
splitAndSendResponse(response, user)
} else {
await sentMessage.edit(response)
}
})
} catch (e) {
console.error(e)
}
})
client.on("interactionCreate", async interaction => {
if(commandExecuters[interaction.commandName]){
commandExecuters[interaction.commandName](interaction,client)
}
});
client.login(process.env.DISCORD_BOT_TOKEN);
}
main()