-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
134 lines (117 loc) · 4.34 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
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
require('dotenv').config();
const fs = require('node:fs');
const path = require('node:path');
const { REST } = require('@discordjs/rest');
const { Client, Collection, GatewayIntentBits, ApplicationCommandType } = require('discord.js');
const rest = new REST({ version: '10' }).setToken(process.env.CLIENT_TOKEN);
const client = new Client({ intents: [
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.DirectMessageTyping,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.GuildBans,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildIntegrations,
GatewayIntentBits.GuildInvites,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMessageTyping,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildScheduledEvents,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildWebhooks,
GatewayIntentBits.Guilds,
GatewayIntentBits.MessageContent
] });
const { QuickDB } = require('quick.db');
const swapActivityTime = 10000;
let currentActivity = 0;
const db = new QuickDB();
client.db = db;
client.once('ready', () => {
console.log('Bot inicializado!');
swapStatus();
registerCommands();
registerEvents();
});
client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(client, interaction);
} catch (error) {
console.error(error);
}
});
client.on("messageCreate", async function(message){
if(message.type != 0) return;
if(message.author.bot) return;
const value = Math.floor(Math.random() * 100);
if(Math.random() < 0.07){
const author = message.author.id;
await db.add("morangos_" + author, value)
message.author.send({content: "Você colheu **" + value + " morangos**, quem sabe não dá pra fazer uma torta deliciosa?", ephemeral: true})
return;
}
if(Math.random() < 0.038){
const author = message.author.id;
await db.add("melancias_" + author, value)
message.author.send({content: "Você colheu **" + value + " melancias**, estão tãããão fofinhasss", ephemeral: true})
return;
}
});
client.login(process.env.CLIENT_TOKEN);
function registerCommands(){
const commands = [];
client.commands = new Collection();
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
command.data.type = ApplicationCommandType.ChatInput
client.commands.set(command.data.name, command);
commands.push(command.data.toJSON());
}
client.application.commands.set(commands)
}
function registerEvents(){
client.events = new Collection();
const eventsPath = path.join(__dirname, 'events');
const eventsFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
for (const file of eventsFiles) {
const filePath = path.join(eventsPath, file);
const event = require(filePath);
client.once(event.name, (...args) => event.execute(...args, client));
client.events.set(event.name, event);
}
console.log(client.events)
}
function swapStatus(){
client.user.setStatus('online');
setInterval(() => {
const activities = [
"amor para meus súditos",
"Estou viva por " + getUpTime()
];
client.user.setActivity(activities[currentActivity]);
currentActivity++;
if (currentActivity === activities.length) currentActivity = 0;
}, swapActivityTime);
}
function getUpTime(){
const uptime = [];
let totalSeconds = (client.uptime / 1000);
let days = Math.floor(totalSeconds / 86400);
if(days > 0) uptime.push(days + "d");
totalSeconds %= 86400;
let hours = Math.floor(totalSeconds / 3600);
if(hours > 0) uptime.push(hours + "h");
totalSeconds %= 3600;
let minutes = Math.floor(totalSeconds / 60);
if(minutes > 0) uptime.push(minutes + "m");
let seconds = Math.floor(totalSeconds % 60);
if(seconds > 0) uptime.push(seconds + "s");
return uptime.join(" ");
}