Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
83 lines (69 loc) 路 2.86 KB
/
Copy pathindex.js
File metadata and controls
83 lines (69 loc) 路 2.86 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
const { Client, Collection, GatewayIntentBits, Events } = require('discord.js');
const { StarDB } = require('stardb');
const db = new StarDB('data.json');
const config = require('./config.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
]
});
client.once(Events.ClientReady, async readyClient => {
console.log(`Logged in as ${readyClient.user.tag}`);
if (!await db.has('users')) db.set('users', []);
});
client.on(Events.MessageCreate, async (message) => {
if (!message.content.startsWith(config.prefix)) return;
const [command, ...args] = message.content.slice(config.prefix.length).split(' ');
const users = await db.get('users');
const user = users.find(u => u.id === message.author.id);
if (!user) {
message.reply({ content: 'First you need to login to use the bot!' });
message.member.kick({ reason: 'Not logged in' }).catch(console.error);
return;
}
if (Date.now() - user.date > 7200000) {
message.reply({ content: 'You have been kicked due to inactivity!' });
await db.set('users', users.filter(u => u.id !== message.author.id));
message.member.kick({ reason: 'Inactivity' }).catch(console.error);
return;
}
if (command === 'login') {
if (args.join(' ') === config.password) {
message.reply({ content: 'You have successfully logged in!' });
await db.set('users', users.filter(u => u.id !== message.author.id));
} else {
message.reply({ content: 'Invalid password!' });
setTimeout(async () => {
message.member.kick({ reason: 'Invalid password' }).catch(console.error);
await db.set('users', users.filter(u => u.id !== message.author.id));
}, 3000);
}
} else message.reply({ content: 'Invalid command!' });
});
client.on(Events.GuildMemberAdd, async (member) => {
const users = await db.get('users');
const user = users.find(u => u.id === member.id);
if (!user) {
await db.push('users', { id: member.id, date: Date.now() });
} else {
await db.set('users', users.filter(u => u.id !== member.id));
await db.push('users', { id: member.id, date: Date.now() });
}
});
setInterval(async () => {
const users = await db.get('users');
const guild = await client.guilds.fetch(config.guildID);
if (!guild) return;
if (users.length < 1) return;
for (const user of users) {
if (Date.now() - user.date > 7200000) {
const member = await guild.members.fetch(user.id);
member.kick({ reason: 'Inactivity' }).catch(console.error);
await db.set('users', users.filter(u => u.id !== user.id));
}
}
}, 60000);
client.login(config.token).catch(console.error);