-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathdiary.js
More file actions
190 lines (158 loc) · 6.43 KB
/
diary.js
File metadata and controls
190 lines (158 loc) · 6.43 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
181
182
183
184
185
186
187
188
189
190
/*
_ ______ _____ _____ _____ _ _
| |/ / ___| |_ _| ____/___ | | | |
| ' / | _ | | | _|| | | |_| |
| . \ |_| | | | | |__| |___| _ |
|_|\_\____| |_| |_____\____|_| |_|
ANYWAY, YOU MUST GIVE CREDIT TO MY CODE WHEN COPY IT
CONTACT ME HERE +237656520674
YT: KermHackTools
Github: Kgtech-cmr
*/
const fs = require("fs");
const path = require("path");
const { cmd } = require("../command");
const diaryFile = path.join(__dirname, "../my_data/diary.json");
let diaries = fs.existsSync(diaryFile) ? JSON.parse(fs.readFileSync(diaryFile, 'utf8')) : {};
// Function to save diaries to file
const saveDiaries = () => {
fs.writeFileSync(diaryFile, JSON.stringify(diaries, null, 2));
};
// URL of the image (replace with a valid URL)
const ALIVE_IMG = "https://i.ibb.co/4Zq1jCNP/lordkerm.jpg";
// ---------------------
// .diary command (open or create diary)
// ---------------------
cmd({
pattern: "diary",
desc: "Open or create a secret diary (Owner only).",
category: "private",
filename: __filename
}, async (conn, mek, m, { reply, q, from, isOwner, sender }) => {
// Check if the user is the owner
if (!isOwner) return reply("❌ Only the bot owner can use this command.");
const userId = m.sender;
if (!diaries[userId]) {
if (!q) {
return reply("📖 You don't have a diary yet. To create one, use:\n\n`.diary yourpassword`");
}
diaries[userId] = { password: q.trim(), entries: [] };
saveDiaries();
return reply(`✅ Your secret diary has been created!\nTo add an entry, use \`.setdiary your message\`\nTo open your diary, use \`.diary yourpassword\``);
}
if (!q) {
return reply("🔒 You already have a diary. To open it, enter your password like this:\n\n`.diary yourpassword`");
}
if (q.trim() !== diaries[userId].password) {
return reply("❌ Incorrect password! Please try again.");
}
if (diaries[userId].entries.length === 0) {
return reply("📖 Your diary is empty. Add entries using `.setdiary your message`.");
}
let formattedInfo = `📖 *Your Diary Entries:*\n\n`;
diaries[userId].entries.forEach((entry) => {
formattedInfo += `📅 *${entry.date}* 🕒 *${entry.time}*\n📝 ${entry.text}\n\n`;
});
// Send the image with the diary entries
await conn.sendMessage(from, {
image: { url: ALIVE_IMG },
caption: formattedInfo,
contextInfo: {
mentionedJid: [m.sender],
forwardingScore: 999,
isForwarded: true,
forwardedNewsletterMessageInfo: {
newsletterJid: '120363321386877609@newsletter',
newsletterName: '𝐊𝐄𝐑𝐌 𝐃𝐈𝐀𝐑𝐘',
serverMessageId: 143
}
}
}, { quoted: mek });
});
// ---------------------
// .setdiary command (add a new diary entry)
// ---------------------
cmd({
pattern: "setdiary",
desc: "Write a new diary entry (Owner only).",
category: "private",
filename: __filename
}, async (conn, mek, m, { reply, q, isOwner, sender }) => {
if (!isOwner) return reply("❌ Only the bot owner can use this command.");
const userId = m.sender;
if (!diaries[userId]) {
return reply("❌ You don't have a diary. Create one using `.diary yourpassword`.");
}
if (!q) {
return reply("✍️ Please provide the text you want to add to your diary.");
}
const now = new Date();
const date = now.toLocaleDateString('fr-FR'); // Date format (France)
const time = now.toLocaleTimeString('fr-FR', { hour12: false }); // 24h format
diaries[userId].entries.push({ date, time, text: q.trim() });
saveDiaries();
reply("✅ Your diary entry has been saved!");
});
// ---------------------
// .resetdiary command (delete all diary entries)
// ---------------------
cmd({
pattern: "resetdiary",
desc: "Reset your diary (delete all entries) (Owner only).",
category: "private",
filename: __filename
}, async (conn, mek, m, { reply, q, isOwner, sender }) => {
if (!isOwner) return reply("❌ Only the bot owner can use this command.");
const userId = m.sender;
if (!diaries[userId]) {
return reply("❌ You don't have a diary to reset.");
}
if (!q) {
return reply("⚠️ To reset your diary, use `.resetdiary yourpassword` to confirm your identity.");
}
if (q.trim() !== diaries[userId].password) {
return reply("❌ Incorrect password! Diary reset aborted.");
}
delete diaries[userId];
saveDiaries();
reply("✅ Your diary has been successfully reset!");
});
// ---------------------
// .resetpassword command (reset diary password; Owner only)
// ---------------------
const generateCode = () => Math.floor(100000 + Math.random() * 900000).toString(); // 6-digit code
let resetRequests = {};
cmd({
pattern: "resetpassword",
desc: "Reset your diary password (Owner only).",
category: "private",
filename: __filename
}, async (conn, mek, m, { reply, q, isOwner, sender }) => {
if (!isOwner) return reply("❌ Only the bot owner can use this command.");
const userId = m.sender;
if (!diaries[userId]) {
return reply("❌ You don't have a diary. Create one using `.diary yourpassword`.");
}
// If no argument is provided, send a reset code
if (!q) {
const resetCode = generateCode();
// Store the reset code with an expiration time of 5 minutes
resetRequests[userId] = { code: resetCode, expires: Date.now() + 5 * 60 * 1000 };
await conn.sendMessage(userId, {
text: `🔐 Your password reset code: *${resetCode}*\n\nThis code expires after 5 minutes.\nEnter this code with \'.resetpassword *code* newpassword\' to confirm.`
});
return reply("📩 A reset code has been sent to your private chat. Use it to reset your password.");
}
const args = q.split(" ");
if (args.length !== 2) {
return reply("⚠️ Incorrect format! Use:\n\n`.resetpassword code newpassword`");
}
const [code, newPassword] = args;
if (!resetRequests[userId] || resetRequests[userId].code !== code || Date.now() > resetRequests[userId].expires) {
return reply("❌ Invalid or expired code! Request a new one with `.resetpassword`.");
}
diaries[userId].password = newPassword.trim();
saveDiaries();
delete resetRequests[userId];
reply("✅ Your diary password has been successfully reset!");
});