-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
200 lines (175 loc) · 4.83 KB
/
Copy pathindex.js
File metadata and controls
200 lines (175 loc) · 4.83 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
const fs = require('fs');
const path = require('node:path');
const {
prefix
} = require('./config.json');
require('dotenv').config();
token = process.env.TOKEN;
const {
Routes
} = require('discord-api-types/v9');
const {
quotes
} = require('./quotes.json');
//const Discord = require('discord.js');Client, Collection, Intents
const {
Client,
Collection,
Intents,
MessageActionRow,
MessageButton
} = require('discord.js');
const Scheduler = require('./libScheduler.js');
//const client = new Discord.Client();
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS
]
});
const PORT = process.env.PORT || 3000;
const express = require("express");
const server = express();
var libFlayer = require("./libFlayer.js");
let linkFlayerMap = [];
server.all("/", (req, res) => {
var htmlOutput = "LinkFlayer Bot is Ready - Sources loading <br />";
var sources = libFlayer.getSources();
sources.forEach(source => {
htmlOutput += `
<div style='margin-bottom:15px;'>
<div> Title: ${source.title} </div>
<div> Link: ${source.link} </div>
<div> category: ${source.category} </div>
</div>
<div>
<hr />
</div>
`
});
res.send(htmlOutput);
});
function keepAlive() {
server.listen(PORT, '0.0.0.0', () => {
console.log(`Keep Alive Server Running on 0.0.0.0:${PORT}`);
try {
//libFlayer.loadFeeds();
//libFlayer.feedArray = libFlayer.getFeeds();
} catch (error) {
console.log(error);
}
})
}
//libTrivia.loadTrivia();
client.commands = new Collection();
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
//const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
// Set a new item in the Collection
// With the key as the command name and the value as the exported module
client.commands.set(command.name, command);
}
/*
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
*/
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
// Initialize and start the scheduler
const scheduler = new Scheduler(client);
scheduler.start();
// Store the scheduler instance on the client
client.scheduler = scheduler;
});
client.on('interactionCreate', async interaction => {
try {
// Handle command interactions
if (interaction.isCommand()) {
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({
content: 'There was an error executing this command!',
ephemeral: true
});
}
}
// Handle button interactions
else if (interaction.isButton()) {
// Handle button interactions here
const command = client.commands.get(interaction.customId.split('_')[0]);
if (command) {
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({
content: 'There was an error handling this button!',
ephemeral: true
});
}
}
}
// Handle select menu interactions
else if (interaction.isSelectMenu()) {
if (!interaction.channel.isTextBased()) {
await interaction.reply({
content: 'This command can only be used in text channels!',
ephemeral: true
});
return;
}
// Handle select menu interactions here
const command = client.commands.get(interaction.customId.split('_')[0]);
if (command) {
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({
content: 'There was an error handling this selection!',
ephemeral: true
});
}
}
}
} catch (error) {
console.error('Error in interactionCreate:', error);
if (interaction.isRepliable()) {
await interaction.reply({
content: 'There was an error processing this interaction!',
ephemeral: true
});
}
}
});
client.on('messageCreate', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (!client.commands.has(command)) return;
try {
client.commands.get(command).execute(message, args);
} catch (error) {
console.error(error);
//message.reply('there was an error trying to execute that command!');
}
});
console.log("Link Flayer Bot Activating");
keepAlive();
client.login(token); //Load Client Discord Token
try {
//libFlayer.loadFeeds();
libFlayer.loadLocalFeeds();
} catch (error) {
console.log(error);
}