spacecommands 1.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -55,13 +55,64 @@ client.on('ready', () => {
55
55
  featuresDir: path.join(__dirname, 'features'),
56
56
  testServers: ['YOUR_TEST_SERVER_ID'],
57
57
  botOwners: ['YOUR_USER_ID'],
58
- mongoUri: process.env.MONGO_URI, // Optional
58
+ // Database (optional - Supabase recommended)
59
+ supabaseUrl: process.env.SUPABASE_URL,
60
+ supabaseKey: process.env.SUPABASE_KEY,
59
61
  });
60
62
  });
61
63
 
62
64
  client.login(process.env.BOT_TOKEN);
63
65
  ```
64
66
 
67
+ ## Supabase Setup (Recommended)
68
+
69
+ SpaceCommands now uses Supabase for data persistence instead of MongoDB. Here's how to set it up:
70
+
71
+ ### 1. Create a Supabase Project
72
+
73
+ 1. Go to [supabase.com](https://supabase.com) and create a free account
74
+ 2. Create a new project
75
+ 3. Copy your project URL and anon/public key
76
+
77
+ ### 2. Set Up the Database
78
+
79
+ 1. In your Supabase dashboard, go to the SQL Editor
80
+ 2. Copy the contents of `supabase-schema.sql` from this package
81
+ 3. Run the SQL to create all required tables
82
+
83
+ Or download the schema:
84
+ ```bash
85
+ curl -o supabase-schema.sql https://raw.githubusercontent.com/VicToMeyeZR/SpaceCommands/main/supabase-schema.sql
86
+ ```
87
+
88
+ ### 3. Configure Your Bot
89
+
90
+ ```javascript
91
+ new SpaceCommands(client, {
92
+ commandsDir: path.join(__dirname, 'commands'),
93
+ supabaseUrl: process.env.SUPABASE_URL, // Your Supabase project URL
94
+ supabaseKey: process.env.SUPABASE_ANON_KEY, // Your Supabase anon/public key
95
+ });
96
+ ```
97
+
98
+ ### 4. Environment Variables
99
+
100
+ Create a `.env` file:
101
+ ```env
102
+ DISCORD_TOKEN=your_bot_token_here
103
+ SUPABASE_URL=https://your-project.supabase.co
104
+ SUPABASE_ANON_KEY=your_anon_key_here
105
+ ```
106
+
107
+ ### Benefits of Supabase
108
+
109
+ - ✅ **Free tier** with generous limits
110
+ - ✅ **Real-time subscriptions** (optional)
111
+ - ✅ **Built-in authentication** (if needed)
112
+ - ✅ **Auto-generated APIs**
113
+ - ✅ **Better performance** than MongoDB for most use cases
114
+ - ✅ **PostgreSQL** under the hood
115
+
65
116
  ## Creating Commands
66
117
 
67
118
  ### Slash Command Example
@@ -100,7 +151,9 @@ module.exports = {
100
151
  |--------|------|-------------|---------|
101
152
  | `commandsDir` | string | Absolute path to commands directory | Required |
102
153
  | `featuresDir` | string | Absolute path to features directory | Optional |
103
- | `mongoUri` | string | MongoDB connection URI | Optional |
154
+ | `supabaseUrl` | string | Supabase project URL | Optional |
155
+ | `supabaseKey` | string | Supabase anon/public key | Optional |
156
+ | `mongoUri` | string | MongoDB URI (deprecated, use Supabase) | Optional |
104
157
  | `testServers` | string[] | Guild IDs for testing commands | [] |
105
158
  | `botOwners` | string[] | User IDs of bot owners | [] |
106
159
  | `defaultLanguage` | string | Default language for messages | 'english' |
package/dist/index.js CHANGED
@@ -38,7 +38,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  const events_1 = require("events");
40
40
  const FeatureHandler_1 = __importDefault(require("./FeatureHandler"));
41
- const mongo_1 = __importStar(require("./mongo"));
41
+ const supabase_1 = __importDefault(require("./supabase"));
42
42
  const prefixes_1 = __importDefault(require("./models/prefixes"));
43
43
  const message_handler_1 = __importDefault(require("./message-handler"));
44
44
  const SlashCommands_1 = __importDefault(require("./SlashCommands"));
@@ -55,7 +55,7 @@ class SpaceCommands extends events_1.EventEmitter {
55
55
  _defaultPrefix = '!';
56
56
  _commandsDir = 'commands';
57
57
  _featuresDir = '';
58
- _mongoConnection = null;
58
+ _supabaseClient = null;
59
59
  _displayName = '';
60
60
  _prefixes = {};
61
61
  _categories = new Map(); // <Category Name, Emoji Icon>
@@ -89,10 +89,26 @@ class SpaceCommands extends events_1.EventEmitter {
89
89
  if (!client) {
90
90
  throw new Error('No Discord JS Client provided as first argument!');
91
91
  }
92
- let { commandsDir = '', commandDir = '', featuresDir = '', featureDir = '', componentsDir, modalsDir, contextMenusDir, messagesPath, mongoUri, showWarns = true, delErrMsgCooldown = -1, defaultLanguage = 'english', ignoreBots = true, dbOptions, testServers, botOwners, disabledDefaultCommands = [], typeScript = false, ephemeral = true, debug = false, } = options || {};
93
- if (mongoUri) {
94
- await (0, mongo_1.default)(mongoUri, this, dbOptions);
95
- this._mongoConnection = (0, mongo_1.getMongoConnection)();
92
+ let { commandsDir = '', commandDir = '', featuresDir = '', featureDir = '', componentsDir, modalsDir, contextMenusDir, messagesPath, supabaseUrl, supabaseKey, mongoUri, // Deprecated - use supabaseUrl and supabaseKey instead
93
+ showWarns = true, delErrMsgCooldown = -1, defaultLanguage = 'english', ignoreBots = true, dbOptions, testServers, botOwners, disabledDefaultCommands = [], typeScript = false, ephemeral = true, debug = false, } = options || {};
94
+ // Support for Supabase (recommended) or MongoDB (deprecated)
95
+ if (supabaseUrl && supabaseKey) {
96
+ this._supabaseClient = await (0, supabase_1.default)(supabaseUrl, supabaseKey, this);
97
+ // Load prefixes from Supabase
98
+ const results = await prefixes_1.default.find({});
99
+ for (const result of results) {
100
+ const { _id, prefix } = result;
101
+ this._prefixes[_id] = prefix;
102
+ }
103
+ }
104
+ else if (mongoUri) {
105
+ // MongoDB support deprecated but still available
106
+ if (showWarns) {
107
+ console.warn('SpaceCommands > MongoDB support is deprecated. Please migrate to Supabase. See documentation for details.');
108
+ }
109
+ const mongo = await Promise.resolve().then(() => __importStar(require('./mongo')));
110
+ await mongo.default(mongoUri, this, dbOptions);
111
+ this._supabaseClient = null;
96
112
  const results = await prefixes_1.default.find({});
97
113
  for (const result of results) {
98
114
  const { _id, prefix } = result;
@@ -101,7 +117,7 @@ class SpaceCommands extends events_1.EventEmitter {
101
117
  }
102
118
  else {
103
119
  if (showWarns) {
104
- console.warn('SpaceCommands > No MongoDB connection URI provided. Some features might not work!');
120
+ console.warn('SpaceCommands > No database connection provided. Some features might not work! Please provide supabaseUrl and supabaseKey.');
105
121
  }
106
122
  this.emit(Events_1.default.DATABASE_CONNECTED, null, '');
107
123
  }
@@ -260,12 +276,15 @@ class SpaceCommands extends events_1.EventEmitter {
260
276
  get commandHandler() {
261
277
  return this._commandHandler;
262
278
  }
279
+ get supabaseClient() {
280
+ return this._supabaseClient;
281
+ }
263
282
  get mongoConnection() {
264
- return this._mongoConnection;
283
+ // Deprecated: For backwards compatibility only
284
+ return this._supabaseClient;
265
285
  }
266
286
  isDBConnected() {
267
- const connection = this.mongoConnection;
268
- return !!(connection && connection.readyState === 1);
287
+ return !!this._supabaseClient;
269
288
  }
270
289
  setTagPeople(tagPeople) {
271
290
  this._tagPeople = tagPeople;
@@ -1,49 +1,93 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // @ts-nocheck
4
+ const supabase_1 = require("../supabase");
5
+ const TABLE_NAME = 'spacecommands_channel_commands';
6
+ exports.default = {
7
+ async find(filter = {}) {
8
+ const client = (0, supabase_1.getSupabaseClient)();
9
+ if (!client)
10
+ return [];
11
+ let query = client.from(TABLE_NAME).select('*');
12
+ if (filter.guildId) {
13
+ query = query.eq('guild_id', filter.guildId);
14
+ }
15
+ if (filter.command) {
16
+ query = query.eq('command', filter.command);
17
+ }
18
+ const { data, error } = await query;
19
+ if (error) {
20
+ console.error('SpaceCommands > Error fetching channel commands:', error);
21
+ return [];
22
+ }
23
+ return (data || []).map((row) => ({
24
+ guildId: row.guild_id,
25
+ command: row.command,
26
+ channels: row.channels,
27
+ }));
28
+ },
29
+ async findOne(filter) {
30
+ const client = (0, supabase_1.getSupabaseClient)();
31
+ if (!client)
32
+ return null;
33
+ let query = client.from(TABLE_NAME).select('*');
34
+ if (filter.guildId) {
35
+ query = query.eq('guild_id', filter.guildId);
36
+ }
37
+ if (filter.command) {
38
+ query = query.eq('command', filter.command);
39
+ }
40
+ const { data, error } = await query.single();
41
+ if (error) {
42
+ if (error.code === 'PGRST116')
43
+ return null;
44
+ console.error('SpaceCommands > Error finding channel command:', error);
45
+ return null;
46
+ }
47
+ return {
48
+ guildId: data.guild_id,
49
+ command: data.command,
50
+ channels: data.channels,
24
51
  };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- const mongoose_1 = __importStar(require("mongoose"));
36
- const reqString = {
37
- type: String,
38
- required: true,
39
- };
40
- const schema = new mongoose_1.Schema({
41
- guildId: reqString,
42
- command: reqString,
43
- channels: {
44
- type: [String],
45
- required: true,
46
52
  },
47
- });
48
- const name = 'spacecommands-channel-commands';
49
- module.exports = mongoose_1.default.models[name] || mongoose_1.default.model(name, schema, name);
53
+ async findOneAndUpdate(filter, update, options = {}) {
54
+ const client = (0, supabase_1.getSupabaseClient)();
55
+ if (!client)
56
+ return null;
57
+ const guildId = filter.guildId;
58
+ const command = filter.command || update.command || update.$set?.command;
59
+ const channels = update.channels || update.$set?.channels;
60
+ const { data, error } = await client
61
+ .from(TABLE_NAME)
62
+ .upsert({ guild_id: guildId, command, channels }, { onConflict: 'guild_id,command' })
63
+ .select()
64
+ .single();
65
+ if (error) {
66
+ console.error('SpaceCommands > Error upserting channel command:', error);
67
+ return null;
68
+ }
69
+ return {
70
+ guildId: data.guild_id,
71
+ command: data.command,
72
+ channels: data.channels,
73
+ };
74
+ },
75
+ async deleteOne(filter) {
76
+ const client = (0, supabase_1.getSupabaseClient)();
77
+ if (!client)
78
+ return { deletedCount: 0 };
79
+ let query = client.from(TABLE_NAME).delete();
80
+ if (filter.guildId) {
81
+ query = query.eq('guild_id', filter.guildId);
82
+ }
83
+ if (filter.command) {
84
+ query = query.eq('command', filter.command);
85
+ }
86
+ const { error } = await query;
87
+ if (error) {
88
+ console.error('SpaceCommands > Error deleting channel command:', error);
89
+ return { deletedCount: 0 };
90
+ }
91
+ return { deletedCount: 1 };
92
+ },
93
+ };
@@ -1,51 +1,102 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // @ts-nocheck
4
+ const supabase_1 = require("../supabase");
5
+ const TABLE_NAME = 'spacecommands_cooldowns';
6
+ exports.default = {
7
+ async find(filter = {}) {
8
+ const client = (0, supabase_1.getSupabaseClient)();
9
+ if (!client)
10
+ return [];
11
+ let query = client.from(TABLE_NAME).select('*');
12
+ // Apply filters
13
+ if (filter._id) {
14
+ query = query.eq('id', filter._id);
15
+ }
16
+ if (filter.name) {
17
+ query = query.eq('name', filter.name);
18
+ }
19
+ if (filter.type) {
20
+ query = query.eq('type', filter.type);
21
+ }
22
+ const { data, error } = await query;
23
+ if (error) {
24
+ console.error('SpaceCommands > Error fetching cooldowns:', error);
25
+ return [];
26
+ }
27
+ return (data || []).map((row) => ({
28
+ _id: row.id,
29
+ name: row.name,
30
+ type: row.type,
31
+ cooldown: row.cooldown,
32
+ }));
33
+ },
34
+ async findOne(filter) {
35
+ const client = (0, supabase_1.getSupabaseClient)();
36
+ if (!client)
37
+ return null;
38
+ let query = client.from(TABLE_NAME).select('*');
39
+ if (filter._id) {
40
+ query = query.eq('id', filter._id);
41
+ }
42
+ const { data, error } = await query.single();
43
+ if (error) {
44
+ if (error.code === 'PGRST116')
45
+ return null;
46
+ console.error('SpaceCommands > Error finding cooldown:', error);
47
+ return null;
48
+ }
49
+ return {
50
+ _id: data.id,
51
+ name: data.name,
52
+ type: data.type,
53
+ cooldown: data.cooldown,
24
54
  };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- const mongoose_1 = __importStar(require("mongoose"));
36
- const reqString = {
37
- type: String,
38
- required: true,
39
- };
40
- const schema = new mongoose_1.Schema({
41
- // Command-GuildID or Command-GuildID-UserID
42
- _id: reqString,
43
- name: reqString,
44
- type: reqString,
45
- cooldown: {
46
- type: Number,
47
- required: true,
48
55
  },
49
- });
50
- const name = 'spacecommands-cooldowns';
51
- module.exports = mongoose_1.default.models[name] || mongoose_1.default.model(name, schema, name);
56
+ async findOneAndUpdate(filter, update, options = {}) {
57
+ const client = (0, supabase_1.getSupabaseClient)();
58
+ if (!client)
59
+ return null;
60
+ const id = filter._id;
61
+ const updateData = {};
62
+ if (update.cooldown !== undefined)
63
+ updateData.cooldown = update.cooldown;
64
+ if (update.name !== undefined)
65
+ updateData.name = update.name;
66
+ if (update.type !== undefined)
67
+ updateData.type = update.type;
68
+ if (update.$set) {
69
+ Object.assign(updateData, update.$set);
70
+ }
71
+ const { data, error } = await client
72
+ .from(TABLE_NAME)
73
+ .upsert({ id, ...updateData }, { onConflict: 'id' })
74
+ .select()
75
+ .single();
76
+ if (error) {
77
+ console.error('SpaceCommands > Error upserting cooldown:', error);
78
+ return null;
79
+ }
80
+ return {
81
+ _id: data.id,
82
+ name: data.name,
83
+ type: data.type,
84
+ cooldown: data.cooldown,
85
+ };
86
+ },
87
+ async deleteMany(filter) {
88
+ const client = (0, supabase_1.getSupabaseClient)();
89
+ if (!client)
90
+ return { deletedCount: 0 };
91
+ let query = client.from(TABLE_NAME).delete();
92
+ if (filter.cooldown?.$lte !== undefined) {
93
+ query = query.lte('cooldown', filter.cooldown.$lte);
94
+ }
95
+ const { error, count } = await query;
96
+ if (error) {
97
+ console.error('SpaceCommands > Error deleting cooldowns:', error);
98
+ return { deletedCount: 0 };
99
+ }
100
+ return { deletedCount: count || 0 };
101
+ },
102
+ };
@@ -1,45 +1,89 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // @ts-nocheck
4
+ const supabase_1 = require("../supabase");
5
+ const TABLE_NAME = 'spacecommands_disabled_commands';
6
+ exports.default = {
7
+ async find(filter = {}) {
8
+ const client = (0, supabase_1.getSupabaseClient)();
9
+ if (!client)
10
+ return [];
11
+ let query = client.from(TABLE_NAME).select('*');
12
+ if (filter.guildId) {
13
+ query = query.eq('guild_id', filter.guildId);
14
+ }
15
+ if (filter.command) {
16
+ query = query.eq('command', filter.command);
17
+ }
18
+ const { data, error } = await query;
19
+ if (error) {
20
+ console.error('SpaceCommands > Error fetching disabled commands:', error);
21
+ return [];
22
+ }
23
+ return (data || []).map((row) => ({
24
+ guildId: row.guild_id,
25
+ command: row.command,
26
+ }));
27
+ },
28
+ async findOne(filter) {
29
+ const client = (0, supabase_1.getSupabaseClient)();
30
+ if (!client)
31
+ return null;
32
+ let query = client.from(TABLE_NAME).select('*');
33
+ if (filter.guildId) {
34
+ query = query.eq('guild_id', filter.guildId);
35
+ }
36
+ if (filter.command) {
37
+ query = query.eq('command', filter.command);
38
+ }
39
+ const { data, error } = await query.single();
40
+ if (error) {
41
+ if (error.code === 'PGRST116')
42
+ return null;
43
+ console.error('SpaceCommands > Error finding disabled command:', error);
44
+ return null;
45
+ }
46
+ return {
47
+ guildId: data.guild_id,
48
+ command: data.command,
24
49
  };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- const mongoose_1 = __importStar(require("mongoose"));
36
- const reqString = {
37
- type: String,
38
- required: true,
50
+ },
51
+ async findOneAndUpdate(filter, update, options = {}) {
52
+ const client = (0, supabase_1.getSupabaseClient)();
53
+ if (!client)
54
+ return null;
55
+ const guildId = filter.guildId;
56
+ const command = filter.command || update.command || update.$set?.command;
57
+ const { data, error } = await client
58
+ .from(TABLE_NAME)
59
+ .upsert({ guild_id: guildId, command }, { onConflict: 'guild_id,command' })
60
+ .select()
61
+ .single();
62
+ if (error) {
63
+ console.error('SpaceCommands > Error upserting disabled command:', error);
64
+ return null;
65
+ }
66
+ return {
67
+ guildId: data.guild_id,
68
+ command: data.command,
69
+ };
70
+ },
71
+ async deleteOne(filter) {
72
+ const client = (0, supabase_1.getSupabaseClient)();
73
+ if (!client)
74
+ return { deletedCount: 0 };
75
+ let query = client.from(TABLE_NAME).delete();
76
+ if (filter.guildId) {
77
+ query = query.eq('guild_id', filter.guildId);
78
+ }
79
+ if (filter.command) {
80
+ query = query.eq('command', filter.command);
81
+ }
82
+ const { error } = await query;
83
+ if (error) {
84
+ console.error('SpaceCommands > Error deleting disabled command:', error);
85
+ return { deletedCount: 0 };
86
+ }
87
+ return { deletedCount: 1 };
88
+ },
39
89
  };
40
- const schema = new mongoose_1.Schema({
41
- guildId: reqString,
42
- command: reqString,
43
- });
44
- const name = 'spacecommands-disabled-commands';
45
- module.exports = mongoose_1.default.models[name] || mongoose_1.default.model(name, schema, name);
@@ -1,46 +1,65 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // @ts-nocheck
4
+ const supabase_1 = require("../supabase");
5
+ const TABLE_NAME = 'spacecommands_languages';
6
+ exports.default = {
7
+ async find(filter = {}) {
8
+ const client = (0, supabase_1.getSupabaseClient)();
9
+ if (!client)
10
+ return [];
11
+ let query = client.from(TABLE_NAME).select('*');
12
+ if (filter._id) {
13
+ query = query.eq('guild_id', filter._id);
14
+ }
15
+ const { data, error } = await query;
16
+ if (error) {
17
+ console.error('SpaceCommands > Error fetching languages:', error);
18
+ return [];
19
+ }
20
+ return (data || []).map((row) => ({
21
+ _id: row.guild_id,
22
+ language: row.language,
23
+ }));
24
+ },
25
+ async findOne(filter) {
26
+ const client = (0, supabase_1.getSupabaseClient)();
27
+ if (!client)
28
+ return null;
29
+ const { data, error } = await client
30
+ .from(TABLE_NAME)
31
+ .select('*')
32
+ .eq('guild_id', filter._id)
33
+ .single();
34
+ if (error) {
35
+ if (error.code === 'PGRST116')
36
+ return null;
37
+ console.error('SpaceCommands > Error finding language:', error);
38
+ return null;
39
+ }
40
+ return {
41
+ _id: data.guild_id,
42
+ language: data.language,
24
43
  };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- const mongoose_1 = __importStar(require("mongoose"));
36
- const reqString = {
37
- type: String,
38
- required: true,
44
+ },
45
+ async findOneAndUpdate(filter, update, options = {}) {
46
+ const client = (0, supabase_1.getSupabaseClient)();
47
+ if (!client)
48
+ return null;
49
+ const guildId = filter._id;
50
+ const language = update.language || update.$set?.language;
51
+ const { data, error } = await client
52
+ .from(TABLE_NAME)
53
+ .upsert({ guild_id: guildId, language }, { onConflict: 'guild_id' })
54
+ .select()
55
+ .single();
56
+ if (error) {
57
+ console.error('SpaceCommands > Error upserting language:', error);
58
+ return null;
59
+ }
60
+ return {
61
+ _id: data.guild_id,
62
+ language: data.language,
63
+ };
64
+ },
39
65
  };
40
- const schema = new mongoose_1.Schema({
41
- // GuildID
42
- _id: reqString,
43
- language: reqString,
44
- });
45
- const name = 'spacecommands-languages';
46
- module.exports = mongoose_1.default.models[name] || mongoose_1.default.model(name, schema, name);
@@ -1,46 +1,81 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // @ts-nocheck
4
+ const supabase_1 = require("../supabase");
5
+ const TABLE_NAME = 'spacecommands_prefixes';
6
+ exports.default = {
7
+ async find(filter = {}) {
8
+ const client = (0, supabase_1.getSupabaseClient)();
9
+ if (!client)
10
+ return [];
11
+ let query = client.from(TABLE_NAME).select('*');
12
+ // Apply filters if provided
13
+ if (filter._id) {
14
+ query = query.eq('guild_id', filter._id);
15
+ }
16
+ const { data, error } = await query;
17
+ if (error) {
18
+ console.error('SpaceCommands > Error fetching prefixes:', error);
19
+ return [];
20
+ }
21
+ // Transform to match Mongoose format
22
+ return (data || []).map((row) => ({
23
+ _id: row.guild_id,
24
+ prefix: row.prefix,
25
+ }));
26
+ },
27
+ async findOne(filter) {
28
+ const client = (0, supabase_1.getSupabaseClient)();
29
+ if (!client)
30
+ return null;
31
+ const { data, error } = await client
32
+ .from(TABLE_NAME)
33
+ .select('*')
34
+ .eq('guild_id', filter._id)
35
+ .single();
36
+ if (error) {
37
+ if (error.code === 'PGRST116')
38
+ return null; // No rows found
39
+ console.error('SpaceCommands > Error finding prefix:', error);
40
+ return null;
41
+ }
42
+ return {
43
+ _id: data.guild_id,
44
+ prefix: data.prefix,
24
45
  };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- const mongoose_1 = __importStar(require("mongoose"));
36
- const reqString = {
37
- type: String,
38
- required: true,
46
+ },
47
+ async findOneAndUpdate(filter, update, options = {}) {
48
+ const client = (0, supabase_1.getSupabaseClient)();
49
+ if (!client)
50
+ return null;
51
+ const guildId = filter._id;
52
+ const prefix = update.prefix || update.$set?.prefix;
53
+ const { data, error } = await client
54
+ .from(TABLE_NAME)
55
+ .upsert({ guild_id: guildId, prefix }, { onConflict: 'guild_id' })
56
+ .select()
57
+ .single();
58
+ if (error) {
59
+ console.error('SpaceCommands > Error upserting prefix:', error);
60
+ return null;
61
+ }
62
+ return {
63
+ _id: data.guild_id,
64
+ prefix: data.prefix,
65
+ };
66
+ },
67
+ async deleteOne(filter) {
68
+ const client = (0, supabase_1.getSupabaseClient)();
69
+ if (!client)
70
+ return { deletedCount: 0 };
71
+ const { error } = await client
72
+ .from(TABLE_NAME)
73
+ .delete()
74
+ .eq('guild_id', filter._id);
75
+ if (error) {
76
+ console.error('SpaceCommands > Error deleting prefix:', error);
77
+ return { deletedCount: 0 };
78
+ }
79
+ return { deletedCount: 1 };
80
+ },
39
81
  };
40
- const schema = new mongoose_1.Schema({
41
- // Guild ID
42
- _id: reqString,
43
- prefix: reqString,
44
- });
45
- const name = 'spacecommands-prefixes';
46
- module.exports = mongoose_1.default.models[name] || mongoose_1.default.model(name, schema, name);
@@ -1,49 +1,93 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // @ts-nocheck
4
+ const supabase_1 = require("../supabase");
5
+ const TABLE_NAME = 'spacecommands_required_roles';
6
+ exports.default = {
7
+ async find(filter = {}) {
8
+ const client = (0, supabase_1.getSupabaseClient)();
9
+ if (!client)
10
+ return [];
11
+ let query = client.from(TABLE_NAME).select('*');
12
+ if (filter.guildId) {
13
+ query = query.eq('guild_id', filter.guildId);
14
+ }
15
+ if (filter.command) {
16
+ query = query.eq('command', filter.command);
17
+ }
18
+ const { data, error } = await query;
19
+ if (error) {
20
+ console.error('SpaceCommands > Error fetching required roles:', error);
21
+ return [];
22
+ }
23
+ return (data || []).map((row) => ({
24
+ guildId: row.guild_id,
25
+ command: row.command,
26
+ requiredRoles: row.required_roles,
27
+ }));
28
+ },
29
+ async findOne(filter) {
30
+ const client = (0, supabase_1.getSupabaseClient)();
31
+ if (!client)
32
+ return null;
33
+ let query = client.from(TABLE_NAME).select('*');
34
+ if (filter.guildId) {
35
+ query = query.eq('guild_id', filter.guildId);
36
+ }
37
+ if (filter.command) {
38
+ query = query.eq('command', filter.command);
39
+ }
40
+ const { data, error } = await query.single();
41
+ if (error) {
42
+ if (error.code === 'PGRST116')
43
+ return null;
44
+ console.error('SpaceCommands > Error finding required roles:', error);
45
+ return null;
46
+ }
47
+ return {
48
+ guildId: data.guild_id,
49
+ command: data.command,
50
+ requiredRoles: data.required_roles,
24
51
  };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- const mongoose_1 = __importStar(require("mongoose"));
36
- const reqString = {
37
- type: String,
38
- required: true,
39
- };
40
- const schema = new mongoose_1.Schema({
41
- guildId: reqString,
42
- command: reqString,
43
- requiredRoles: {
44
- type: [String],
45
- required: true,
46
52
  },
47
- });
48
- const name = 'spacecommands-required-roles';
49
- module.exports = mongoose_1.default.models[name] || mongoose_1.default.model(name, schema, name);
53
+ async findOneAndUpdate(filter, update, options = {}) {
54
+ const client = (0, supabase_1.getSupabaseClient)();
55
+ if (!client)
56
+ return null;
57
+ const guildId = filter.guildId;
58
+ const command = filter.command || update.command || update.$set?.command;
59
+ const requiredRoles = update.requiredRoles || update.$set?.requiredRoles;
60
+ const { data, error } = await client
61
+ .from(TABLE_NAME)
62
+ .upsert({ guild_id: guildId, command, required_roles: requiredRoles }, { onConflict: 'guild_id,command' })
63
+ .select()
64
+ .single();
65
+ if (error) {
66
+ console.error('SpaceCommands > Error upserting required roles:', error);
67
+ return null;
68
+ }
69
+ return {
70
+ guildId: data.guild_id,
71
+ command: data.command,
72
+ requiredRoles: data.required_roles,
73
+ };
74
+ },
75
+ async deleteOne(filter) {
76
+ const client = (0, supabase_1.getSupabaseClient)();
77
+ if (!client)
78
+ return { deletedCount: 0 };
79
+ let query = client.from(TABLE_NAME).delete();
80
+ if (filter.guildId) {
81
+ query = query.eq('guild_id', filter.guildId);
82
+ }
83
+ if (filter.command) {
84
+ query = query.eq('command', filter.command);
85
+ }
86
+ const { error } = await query;
87
+ if (error) {
88
+ console.error('SpaceCommands > Error deleting required roles:', error);
89
+ return { deletedCount: 0 };
90
+ }
91
+ return { deletedCount: 1 };
92
+ },
93
+ };
package/dist/mongo.js CHANGED
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getMongoConnection = void 0;
7
+ // @ts-nocheck
7
8
  const mongoose_1 = __importDefault(require("mongoose"));
8
9
  const Events_1 = __importDefault(require("./enums/Events"));
9
10
  const results = {
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getSupabaseClient = void 0;
7
+ // @ts-nocheck
8
+ const supabase_js_1 = require("@supabase/supabase-js");
9
+ const Events_1 = __importDefault(require("./enums/Events"));
10
+ let supabaseClient = null;
11
+ exports.default = async (supabaseUrl, supabaseKey, instance) => {
12
+ supabaseClient = (0, supabase_js_1.createClient)(supabaseUrl, supabaseKey);
13
+ // Test the connection
14
+ const { error } = await supabaseClient.from('spacecommands_prefixes').select('count').limit(1);
15
+ if (error && error.code !== 'PGRST116') { // PGRST116 is "no rows returned" which is fine
16
+ console.error('SpaceCommands > Supabase connection error:', error);
17
+ instance.emit(Events_1.default.DATABASE_CONNECTED, null, 'Error');
18
+ throw new Error(`Failed to connect to Supabase: ${error.message}`);
19
+ }
20
+ instance.emit(Events_1.default.DATABASE_CONNECTED, supabaseClient, 'Connected');
21
+ return supabaseClient;
22
+ };
23
+ const getSupabaseClient = () => {
24
+ return supabaseClient;
25
+ };
26
+ exports.getSupabaseClient = getSupabaseClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spacecommands",
3
- "version": "1.0.0",
3
+ "version": "3.0.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "./typings.d.ts",
6
6
  "typings": "./typings.d.ts",
@@ -40,7 +40,7 @@
40
40
  "dependencies": {
41
41
  "discord.js": "^14.25.1",
42
42
  "dotenv": "^16.4.7",
43
- "mongoose": "^8.10.0"
43
+ "@supabase/supabase-js": "^2.39.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@types/node": "^22.10.5",
package/typings.d.ts CHANGED
@@ -99,7 +99,9 @@ interface OptionsWithS {
99
99
  modalsDir?: string
100
100
  contextMenusDir?: string
101
101
  messagesPath?: string
102
- mongoUri?: string
102
+ supabaseUrl?: string
103
+ supabaseKey?: string
104
+ mongoUri?: string // Deprecated - use supabaseUrl and supabaseKey
103
105
  showWarns?: boolean
104
106
  delErrMsgCooldown?: number
105
107
  defaultLanguage?: string
@@ -123,7 +125,9 @@ interface OptionsWithoutS {
123
125
  modalsDir?: string
124
126
  contextMenusDir?: string
125
127
  messagesPath?: string
126
- mongoUri?: string
128
+ supabaseUrl?: string
129
+ supabaseKey?: string
130
+ mongoUri?: string // Deprecated - use supabaseUrl and supabaseKey
127
131
  showWarns?: boolean
128
132
  delErrMsgCooldown?: number
129
133
  defaultLanguage?: string