-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
132 lines (106 loc) · 4.31 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
const { Client, GatewayIntentBits, EmbedBuilder } = require('discord.js');
const axios = require('axios');
const dotenv = require('dotenv');
const {
setEmail,
getEmail,
setDailyClaimed,
isDailyClaimed,
setCoins,
getCoins,
setWeeklyClaimed,
isWeeklyClaimed,
} = require('./db'); // Import your db functions
// Load environment variables
dotenv.config();
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent],
});
client.on('ready', () => {
console.log('Bot is online!');
});
// Bot command handling
client.on('messageCreate', async (message) => {
if (message.author.bot) return;
const args = message.content.trim().split(/\s+/);
const command = args[0].toLowerCase();
const email = args.slice(1).join(' ');
if (!command.startsWith(process.env.PREFIX)) return;
const userId = message.author.id;
if (command === `${process.env.PREFIX}!mine` && args[1] === 'daily') {
const alreadyClaimed = await isDailyClaimed(userId);
if (alreadyClaimed) {
return message.channel.send('You have already claimed your daily coins.');
}
const coins = Math.floor(Math.random() * (50 - 20 + 1)) + 20;
const userEmail = await getEmail(userId);
if (!userEmail) {
return message.channel.send('Your email is not connected. Please connect it using `prefix!connect [email]`.');
}
try {
await axios.get(`${process.env.HYDREN_URL}/api/addcoins`, {
params: {
key: process.env.HYDREN_KEY,
coins,
email: userEmail,
},
});
} catch (error) {
console.error('Error adding coins:', error);
return message.channel.send('There was an error adding your coins. Please try again later.');
}
await setDailyClaimed(userId);
await setCoins(userId, coins);
const embed = new EmbedBuilder()
.setTitle('Daily Mine')
.setDescription(`You have mined your daily coins!\nYou now have ${coins} coins.`)
.setColor('#FFD700');
message.channel.send({ embeds: [embed] });
}
if (command === `${process.env.PREFIX}!mine` && args[1] === 'weekly') {
const alreadyClaimed = await isWeeklyClaimed(userId); // Check weekly claim status
if (alreadyClaimed) {
return message.channel.send('You have already claimed your weekly coins.');
}
const coins = Math.floor(Math.random() * (100 - 50 + 1)) + 50; // Adjusted for randomness
const userEmail = await getEmail(userId);
if (!userEmail) {
return message.channel.send('Your email is not connected. Please connect it using `prefix!connect [email]`.');
}
try {
await axios.get(`${process.env.HYDREN_URL}/api/addcoins`, {
params: {
key: process.env.HYDREN_KEY,
coins,
email: userEmail,
},
});
} catch (error) {
console.error('Error adding coins:', error);
return message.channel.send('There was an error adding your coins. Please try again later.');
}
await setWeeklyClaimed(userId); // Mark weekly claim
await setCoins(userId, coins);
const embed = new EmbedBuilder()
.setTitle('Weekly Mine')
.setDescription(`You have mined your weekly coins!\nYou now have ${coins} coins.`)
.setColor('#FFD700');
message.channel.send({ embeds: [embed] });
}
if (command === `${process.env.PREFIX}!connect`) {
if (!email) {
return message.channel.send('Please provide an email to connect.');
}
await setEmail(userId, email);
message.channel.send(`Your email has been connected: ${email}`);
}
if (command === `${process.env.PREFIX}!links`) {
const embed = new EmbedBuilder()
.setTitle('Links')
.setDescription(`Here is the Dashboard URL: [ClickME](${process.env.HYDREN_URL})`)
.setColor('#00FF00'); // You can change the color as needed
message.channel.send({ embeds: [embed] });
}
});
// Start the bot
client.login(process.env.TOKEN);