-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
180 lines (173 loc) · 6.95 KB
/
Copy pathindex.js
File metadata and controls
180 lines (173 loc) · 6.95 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
console.clear();
//basic loaders
const fs = require('fs'), { Client, Collection, GatewayIntentBits, Partials, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle} = require('discord.js')
const client = new Client({
ws: {
properties: { browser: 'Discord Android' }
},
intents: [
GatewayIntentBits.Guilds, //1
GatewayIntentBits.GuildMembers, //2
GatewayIntentBits.GuildModeration, //4
GatewayIntentBits.GuildEmojisAndStickers, //8
GatewayIntentBits.GuildIntegrations, //16
//GatewayIntentBits.GuildWebhooks, //32
GatewayIntentBits.GuildInvites, //64
GatewayIntentBits.GuildVoiceStates, //128
//FUCK GatewayIntentBits.GuildPresences, //256
GatewayIntentBits.GuildMessages, //512
GatewayIntentBits.GuildMessageReactions, //1024
//GatewayIntentBits.GuildMessageTyping, //2048
GatewayIntentBits.DirectMessages, //4096
GatewayIntentBits.DirectMessageReactions, //8192
//GatewayIntentBits.DirectMessageTyping //16384
//FUCK GatewayIntentBits.MessageContent, //32768
GatewayIntentBits.GuildScheduledEvents, //65536
GatewayIntentBits.AutoModerationConfiguration, //1048576
GatewayIntentBits.AutoModerationExecution //2097152
],
partials: [
Partials.Channel,
Partials.GuildMember,
Partials.GuildScheduledEvent,
Partials.Message,
Partials.Reaction,
Partials.User,
//Partials.ThreadMember
]
});
client.commands = new Collection();
//Enmap - server side settings
const Enmap = require('enmap');
client.settings = new Enmap({
name: "settings",
fetchAll: true,
autoFetch: true,
cloneLevel: 'deep',
autoEnsure: {
welcome: false,
welcomeUserCheck: false,
goodbye: false,
messageLogs: false,
messageLogsBlacklistChannel: [],
messageLogsBlacklistRoles: [],
memberUpdateLogs: false,
invitesLogs: false,
schedulesLogs: false,
banKickLogs: false,
welcomeMessage: "**Welcome to the server!** \nHope you enjoy your stay! \nThe bot works with only slash commands.\n(nsfw only in nsfw channels)",
enableNSFW: false,
welcomeRoles: [],
freeRoles: [],
moderationChannel: "",
enableRandomReactions: false,
randomReactionChannelBlacklist: [],
singleChannelMessageLogger: [],
redditFeed: false,
redditFeedSub1: "",
lastRedditFeedPost1: "",
redditFeedChannel1: "",
redditFeedSub2: "",
lastRedditFeedPost2: "",
redditFeedChannel2: "",
redditFeedSub3: "",
lastRedditFeedPost3: "",
redditFeedChannel3: "",
}
});
let commandFuck = []
//command file reader
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command_files = require(`./commands/${file}`);
client.commands.set(command_files.data.name, command_files);
commandFuck.push(command_files)
}
//event handler
const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'));
const guildInvites = new Map()
const vanityInvites = new Map()
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once) {client.once(event.name, (...args) => event.execute(...args, client, guildInvites, vanityInvites))}
else {client.on(event.name, (...args) => event.execute(...args, client, guildInvites, vanityInvites))}
}
const dashboardInit = require(`./dashboard/dashInit.js`)
client.on(`ready`, (...args) => dashboardInit.execute(...args, client, commandFuck))
//Bot token
require('dotenv').config();
var token = process.env.token;
var debug_level = process.env.debug_level;
client.login(token)
//error handler
console.log(client)
client.on("error", (e) => console.error(e));
client.on("warn", (e) => console.warn(e));
process.on('unhandledRejection', error => console.error('-----\nUncaught Rejection:\n-----\n', error));
process.on('uncaughtException', error => console.error('-----\nUncaught Exception:\n-----\n', error));
if (debug_level >= 3) {
client.on("debug", (e) => console.log(e))
}
let redditFeedSub = []
let redditFeedChannel = []
setInterval(() => {
client.guilds.cache.forEach(guild => {
let tr = client.settings.get(guild.id, "redditFeed")
if (!tr) return;
redditFeedSub[0] = client.settings.get(guild.id, "redditFeedSub1")
redditFeedSub[1] = client.settings.get(guild.id, "redditFeedSub2")
redditFeedSub[2] = client.settings.get(guild.id, "redditFeedSub3")
redditFeedChannel[0] = client.settings.get(guild.id, "redditFeedChannel1")
redditFeedChannel[1] = client.settings.get(guild.id, "redditFeedChannel2")
redditFeedChannel[2] = client.settings.get(guild.id, "redditFeedChannel3")
for (i = 0; i < redditFeedSub.length; i++){
if (redditFeedSub[i] == '') return;
if (redditFeedChannel[i] == '') return;
else { redditFetchFunction(redditFeedChannel[i], redditFeedSub[i], i, guild) }
}
})
}, 240000)
async function redditFetchFunction(channel, sub, i, guild) {
let feedChannel = await client.channels.cache.get(channel)
if (feedChannel == undefined) return;
let post = await fetch(`https://www.reddit.com/r/${sub}/new.json`)
.then(res => res.json()).then(body => {
let found = body.data.children;
if (!found.length) return channel.send(`Unable to find a post. The subreddit "${subreddit}" does not exist, or it has no available post data.`);
return found[0].data;
})
if (i == 0) {
let lastID = client.settings.get(guild.id, "lastRedditFeedPost1")
if (lastID == post.id) return;
else { client.settings.set(guild.id, post.id, "lastRedditFeedPost1") }
} else if (i == 1) {
let lastID = client.settings.get(guild.id, "lastRedditFeedPost2")
if (lastID == post.id) return;
else { client.settings.set(guild.id, post.id, "lastRedditFeedPost2") }
} else if (i == 2) {
let lastID = client.settings.get(guild.id, "lastRedditFeedPost3")
if (lastID == post.id) return;
else { client.settings.set(guild.id, post.id, "lastRedditFeedPost3") }
} else return;
//console.log(post)
const embed = new EmbedBuilder()
.setColor('#A020F0')
.setTitle(post.title)
.setURL(`https://reddit.com${post.permalink}`)
.setAuthor({ name: post.author})
.setTimestamp()
const linkButton = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setLabel('Link')
.setStyle(ButtonStyle.Link)
.setEmoji('🖥️')
.setURL(`https://reddit.com${post.permalink}`)
)
if (post.url != null) {
embed.setImage(post.url)
feedChannel.send({embeds: [embed], components: [linkButton]})
}
else {
feedChannel.send({embeds: [embed], components: [linkButton]})
}
}