-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
114 lines (101 loc) · 4.35 KB
/
main.js
File metadata and controls
114 lines (101 loc) · 4.35 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
const discord = require('discord.js');
const client = new discord.Client({
intents: [
discord.GatewayIntentBits.Guilds,
discord.GatewayIntentBits.GuildMembers,
discord.GatewayIntentBits.GuildModeration,
discord.GatewayIntentBits.GuildMessages,
discord.GatewayIntentBits.GuildMessageReactions,
discord.GatewayIntentBits.GuildInvites,
discord.GatewayIntentBits.GuildMessageTyping,
discord.GatewayIntentBits.GuildPresences,
],
});
const config = require('./config.js');
async function updateStats() {
// console.log('Updating Stats...')
const rolestats = config.stats.roles;
const channelstats = config.stats.channels;
const messagestats = config.stats.messages;
let guild
try {
guild = await client.guilds.fetch(config.guildid);
} catch (error) {
console.log("Please ensure that the bot is on the server and you have enterd to correct Guild ID in the config.js file.")
process.exit(1)
}
rolestats.forEach(async rolestat => {
if (rolestat.enabled) {
const role = guild.roles.cache.get(rolestat.role);
const members = role.members.size;
const channel = guild.channels.cache.get(rolestat.channel);
channel.setName(rolestat.name.replace('{counter}', members));
}
})
channelstats.forEach(channelstat => {
if (channelstat.enabled) {
let channels = 0
channelstat.categorys.forEach(async category => {
const categorychannels = guild.channels.cache.filter(channel => channel.parentId === category);
channels += categorychannels.size;
})
const channel = guild.channels.cache.get(channelstat.channel);
channel.setName(channelstat.name.replace('{counter}', channels));
}
})
messagestats.forEach(async messagestat => {
if (messagestat.enabled) {
const channel = guild.channels.cache.get(messagestat.channel_of_messages);
const channelmessages = await channel.messages.fetch()
const ammountofmsgs = channelmessages.size
const channel2 = guild.channels.cache.get(messagestat.channel);
channel2.setName(messagestat.name.replace('{counter}', ammountofmsgs));
}
})
Object.keys(config.stats.guild).forEach(async key => {
if (config.stats.guild[key].enabled) {
const channel = guild.channels.cache.get(config.stats.guild[key].channel);
if (key === 'users')
channel.setName(config.stats.guild[key].name.replace('{counter}', guild.memberCount));
else if (key === 'boosts')
channel.setName(config.stats.guild[key].name.replace('{counter}', guild.premiumSubscriptionCount));
else if (key === 'roles') {
channel.setName(config.stats.guild[key].name.replace('{counter}', guild.roles.cache.size));
} else if (key === 'channels') {
channel.setName(config.stats.guild[key].name.replace('{counter}', guild.channels.cache.size));
} else if (key === 'emojis') {
channel.setName(config.stats.guild[key].name.replace('{counter}', guild.emojis.cache.size));
} else if (key === 'bans') {
channel.setName(config.stats.guild[key].name.replace('{counter}', guild.bans.cache.size));
} else if (key === 'invites') {
const invites = await guild.fetchInvites();
channel.setName(config.stats.guild[key].name.replace('{counter}', invites.size));
}
}
})
}
client.on('ready', () => {
console.log('Logged in as ' + client.user.tag + '!')
updateStats();
setInterval(async () => {
await updateStats();
}, config.stats.intervall)
if (!config.bot.activitys) return
if (!config.bot.intervall) return
if (!config.bot.activity_enabled) return
let i = 0
let j = config.bot.activitys.length - 1
setInterval(() => {
const activity = config.bot.activitys[i]
client.user.setPresence({
activities: [{
name: activity.name,
type: discord.ActivityType[activity.type]
}],
status: activity.status
});
i++
if (i > j) i = 0
}, config.bot.intervall);
})
client.login(config.bot.token);