Spaces:
Runtime error
Runtime error
Update storage.js
Browse files- storage.js +0 -47
storage.js
CHANGED
|
@@ -72,53 +72,6 @@ class Storage {
|
|
| 72 |
const allowedRoles = this.data.roles[guildId] || [];
|
| 73 |
return member.roles.cache.some(r => allowedRoles.includes(r.id));
|
| 74 |
}
|
| 75 |
-
|
| 76 |
-
async backupToDiscord(client) {
|
| 77 |
-
for (const guild of client.guilds.cache.values()) {
|
| 78 |
-
try {
|
| 79 |
-
let channel = guild.channels.cache.find(c => c.name === 'friendlybot-storage');
|
| 80 |
-
if (!channel) {
|
| 81 |
-
channel = await guild.channels.create({
|
| 82 |
-
name: 'friendlybot-storage',
|
| 83 |
-
permissionOverwrites: [{ id: guild.id, deny: ['ViewChannel'] }, { id: client.user.id, allow: ['ViewChannel', 'SendMessages'] }]
|
| 84 |
-
});
|
| 85 |
-
}
|
| 86 |
-
const backup = { data: this.data, time: new Date().toISOString() };
|
| 87 |
-
await channel.send(`BACKUP_DATA\n\`\`\`json\n${JSON.stringify(backup, null, 2)}\n\`\`\``);
|
| 88 |
-
} catch (e) {}
|
| 89 |
-
}
|
| 90 |
-
}
|
| 91 |
-
|
| 92 |
-
async restoreFromDiscord(client) {
|
| 93 |
-
let restored = false;
|
| 94 |
-
for (const guild of client.guilds.cache.values()) {
|
| 95 |
-
try {
|
| 96 |
-
const channel = guild.channels.cache.find(c => c.name === 'friendlybot-storage');
|
| 97 |
-
if (channel) {
|
| 98 |
-
const messages = await channel.messages.fetch({ limit: 10 });
|
| 99 |
-
const backupMsg = messages.find(m => m.content.includes('BACKUP_DATA'));
|
| 100 |
-
if (backupMsg) {
|
| 101 |
-
const match = backupMsg.content.match(/```json\n([\s\S]+?)\n```/);
|
| 102 |
-
if (match && match[1]) {
|
| 103 |
-
const parsed = JSON.parse(match[1]);
|
| 104 |
-
if (parsed && parsed.data) {
|
| 105 |
-
this.data = parsed.data;
|
| 106 |
-
this.saveAll();
|
| 107 |
-
console.log(`[*] Restored database from Discord Cloud Backup in server: ${guild.name}`);
|
| 108 |
-
restored = true;
|
| 109 |
-
break;
|
| 110 |
-
}
|
| 111 |
-
}
|
| 112 |
-
}
|
| 113 |
-
}
|
| 114 |
-
} catch (e) {
|
| 115 |
-
console.error(`Error restoring backup from ${guild.name}:`, e);
|
| 116 |
-
}
|
| 117 |
-
}
|
| 118 |
-
if (!restored) {
|
| 119 |
-
console.log(`[*] No Cloud Backup found on Discord. Starting fresh.`);
|
| 120 |
-
}
|
| 121 |
-
}
|
| 122 |
}
|
| 123 |
|
| 124 |
const storage = new Storage();
|
|
|
|
| 72 |
const allowedRoles = this.data.roles[guildId] || [];
|
| 73 |
return member.roles.cache.some(r => allowedRoles.includes(r.id));
|
| 74 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
}
|
| 76 |
|
| 77 |
const storage = new Storage();
|