spacecommands 3.6.0 → 3.6.2

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.
@@ -89,13 +89,16 @@ class CommandHandler {
89
89
  }
90
90
  });
91
91
  for (const cmd of commandsToSync.values()) {
92
- await commands_1.default.upsert({
93
- id: cmd.names[0],
92
+ const result = await commands_1.default.upsert({
93
+ name: cmd.names[0],
94
94
  category: cmd.category,
95
95
  description: cmd.description,
96
96
  aliases: cmd.names.slice(1),
97
97
  is_slash: !!cmd.slash
98
98
  });
99
+ if (result && result.id) {
100
+ cmd.setDbId(result.id);
101
+ }
99
102
  }
100
103
  }
101
104
  this._commands.forEach(async (command) => {
@@ -11,6 +11,22 @@ module.exports = {
11
11
  minArgs: 2,
12
12
  maxArgs: 2,
13
13
  expectedArgs: '<command> <none-or-roleid>',
14
+ options: [
15
+ {
16
+ name: 'command',
17
+ description: 'The command to set required roles for',
18
+ required: true,
19
+ type: 'STRING',
20
+ autocomplete: true,
21
+ },
22
+ {
23
+ name: 'none-or-roleid',
24
+ description: 'The role ID to require, or "none" to clear',
25
+ required: true,
26
+ type: 'STRING',
27
+ autocomplete: true,
28
+ }
29
+ ],
14
30
  cooldown: '2s',
15
31
  slash: 'both',
16
32
  autocomplete: async (interaction, instance) => {
@@ -18,17 +34,37 @@ module.exports = {
18
34
  if (focusedOption.name === 'command') {
19
35
  const commandsModel = require('../models/commands').default;
20
36
  // Fetch all commands (optimisation: maybe cache this?)
21
- // For now, let's fetch all (filtered by DB query if possible, but here we just get matches)
22
- // Actually Supabase 'like' or 'ilike' would be better.
23
- // But our model uses exact match find or all.
24
- // Let's assume we fetch all and filter in memory for list size < 100
25
- const commands = await commandsModel.find();
37
+ let commands = [];
38
+ try {
39
+ commands = await commandsModel.find();
40
+ }
41
+ catch (e) {
42
+ console.warn('SpaceCommands > Failed to fetch commands for autocomplete:', e);
43
+ return interaction.respond([]);
44
+ }
26
45
  const filtered = commands.filter((cmd) => cmd.name && cmd.name.toLowerCase().startsWith(focusedOption.value.toLowerCase()));
27
46
  return interaction.respond(filtered.slice(0, 25).map((cmd) => ({
28
47
  name: cmd.name,
29
48
  value: cmd.id,
30
49
  })));
31
50
  }
51
+ else if (focusedOption.name === 'none-or-roleid') {
52
+ const guild = interaction.guild;
53
+ if (!guild)
54
+ return interaction.respond([]);
55
+ const filter = focusedOption.value.toLowerCase();
56
+ const roles = guild.roles.cache
57
+ .filter((r) => r.name.toLowerCase().includes(filter))
58
+ .map((r) => ({ name: r.name, value: r.id }));
59
+ const options = [];
60
+ if ('none'.includes(filter)) {
61
+ options.push({ name: 'None (Clear Roles)', value: 'none' });
62
+ }
63
+ // Add roles, limit total to 25
64
+ const remainingSlots = 25 - options.length;
65
+ options.push(...roles.slice(0, remainingSlots));
66
+ return interaction.respond(options);
67
+ }
32
68
  },
33
69
  callback: async (options) => {
34
70
  const { channel, args, instance } = options;
@@ -10,7 +10,10 @@ const commands = {
10
10
  return [];
11
11
  let query = client.from(exports.TABLE_NAME).select('*');
12
12
  if (filter.name) {
13
- query = query.eq('id', filter.name);
13
+ query = query.eq('name', filter.name);
14
+ }
15
+ if (filter.id) {
16
+ query = query.eq('id', filter.id);
14
17
  }
15
18
  const { data, error } = await query;
16
19
  if (error) {
@@ -23,14 +26,16 @@ const commands = {
23
26
  const client = (0, supabase_1.getSupabaseClient)();
24
27
  if (!client)
25
28
  return null;
26
- const { error } = await client
29
+ const { data, error } = await client
27
30
  .from(exports.TABLE_NAME)
28
- .upsert(commandData, { onConflict: 'id' });
31
+ .upsert(commandData, { onConflict: 'name' })
32
+ .select()
33
+ .single();
29
34
  if (error) {
30
35
  console.error('SpaceCommands > Error upserting command:', error);
31
36
  return null;
32
37
  }
33
- return true;
38
+ return data;
34
39
  },
35
40
  delete: async (id) => {
36
41
  const client = (0, supabase_1.getSupabaseClient)();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spacecommands",
3
- "version": "3.6.0",
3
+ "version": "3.6.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "./typings.d.ts",
6
6
  "typings": "./typings.d.ts",