Brozy123 commited on
Commit
2068584
·
verified ·
1 Parent(s): 24c1814

Update roleStorage.js

Browse files
Files changed (1) hide show
  1. roleStorage.js +48 -0
roleStorage.js CHANGED
@@ -45,6 +45,54 @@ class RoleManager {
45
  const allowedRoles = this.roles[guildId] || [];
46
  return member.roles.cache.some(r => allowedRoles.includes(r.id));
47
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  }
49
 
50
  module.exports = new RoleManager();
 
45
  const allowedRoles = this.roles[guildId] || [];
46
  return member.roles.cache.some(r => allowedRoles.includes(r.id));
47
  }
48
+
49
+ async backupToOwner(client) {
50
+ try {
51
+ if (!this.ownerId) {
52
+ const app = await client.application.fetch();
53
+ this.ownerId = app.owner.ownerId || app.owner.id;
54
+ }
55
+ if (!this.ownerId) return;
56
+ const ownerUser = await client.users.fetch(this.ownerId);
57
+
58
+ const backupStr = JSON.stringify({ data: this.roles, time: Date.now() });
59
+ await ownerUser.send(`[SYSTEM_BACKUP_ROLES]\n\`\`\`json\n${backupStr}\n\`\`\``);
60
+ console.log("[*] Cloud Backup sent to Bot Owner DM.");
61
+ } catch (e) {
62
+ console.log("[!] Failed to send backup to owner DM (DMs might be closed).");
63
+ }
64
+ }
65
+
66
+ async restoreFromOwner(client) {
67
+ try {
68
+ if (!this.ownerId) {
69
+ const app = await client.application.fetch();
70
+ this.ownerId = app.owner.ownerId || app.owner.id;
71
+ }
72
+ if (!this.ownerId) return false;
73
+ const ownerUser = await client.users.fetch(this.ownerId);
74
+ const dmChannel = await ownerUser.createDM();
75
+ const messages = await dmChannel.messages.fetch({ limit: 20 });
76
+
77
+ const backupMsg = messages.find(m => m.author.id === client.user.id && m.content.includes('[SYSTEM_BACKUP_ROLES]'));
78
+ if (backupMsg) {
79
+ const match = backupMsg.content.match(/```json\n([\s\S]+?)\n```/);
80
+ if (match && match[1]) {
81
+ const parsed = JSON.parse(match[1]);
82
+ if (parsed && parsed.data) {
83
+ this.roles = parsed.data;
84
+ this.save();
85
+ console.log("[*] Restored roles from Owner DM Backup.");
86
+ return true;
87
+ }
88
+ }
89
+ }
90
+ console.log("[*] No DM backup found, starting fresh.");
91
+ } catch (e) {
92
+ console.log("[!] Failed to restore backup from owner DM (DMs might be closed).");
93
+ }
94
+ return false;
95
+ }
96
  }
97
 
98
  module.exports = new RoleManager();