Baylem
Baylem
SIASapphire - Imagine a framework
Created by Baylem on 7/3/2024 in #sapphire-support
Preconditions Help
preconditions: ['AllStaff', 'BreakRoom']
preconditions: ['AllStaff', 'BreakRoom']
The above means AllStaff AND BreakRoom right?
preconditions: [['AllStaff', 'BreakRoom']]
preconditions: [['AllStaff', 'BreakRoom']]
and then this would mean AllStaff OR BreakRoom?
5 replies
SIASapphire - Imagine a framework
Created by Baylem on 4/17/2024 in #sapphire-support
API Plugin Prefix
Hey all, for some reason my prefix isn't applying on the data paths This is my env file:
# API
API_PREFIX=v1/
API_ORIGIN=*
API_PORT=4000
# API
API_PREFIX=v1/
API_ORIGIN=*
API_PORT=4000
This is the line from the ServerOptions:
auth: parseApiAuth(),
prefix: envParseString('API_PREFIX', 'v1/'),
origin: envParseString('API_ORIGIN'),
listenOptions: { port: envParseInteger('API_PORT') }
auth: parseApiAuth(),
prefix: envParseString('API_PREFIX', 'v1/'),
origin: envParseString('API_ORIGIN'),
listenOptions: { port: envParseInteger('API_PORT') }
This is the user route in the routes folder:
export class UserRoute extends Route {
public constructor(context: Route.LoaderContext, options: Route.Options) {
super(context, {
...options,
route: 'hello-world'
});
}

public [methods.GET](_request: ApiRequest, response: ApiResponse) {
response.json({ message: 'Hello World' });
}

public [methods.POST](_request: ApiRequest, response: ApiResponse) {
response.json({ message: 'Hello World' });
}
}
export class UserRoute extends Route {
public constructor(context: Route.LoaderContext, options: Route.Options) {
super(context, {
...options,
route: 'hello-world'
});
}

public [methods.GET](_request: ApiRequest, response: ApiResponse) {
response.json({ message: 'Hello World' });
}

public [methods.POST](_request: ApiRequest, response: ApiResponse) {
response.json({ message: 'Hello World' });
}
}
So this means that it should be accessible on 127.0.0.1:4000/v1/hello-world or localhost:4000/v1/hello-world correct? I'm only getting a response from 127.0.0.1:4000/hello-world and localhost:4000/hello-world I've read through the docs and am probably missing something simple, just been overlooking it I guess or I don't understand enough about the implementation, maybe this doesn't matter unless the environment is set up with to use that route
6 replies
SIASapphire - Imagine a framework
Created by Baylem on 4/7/2024 in #sapphire-support
Splitting Subcommand functions to multiple files
I have a command that has quite a few subcommands. I was wondering if there was any way to directly place a function in the messageRun chatInputRun entries so I could split the Subcommands into their own files/classes as the main command file is roughly 2.5k lines at the moment. I know I could just have each method inside of the class then call the other classes/files inside of it (which is what I'm currently doing), just wanted to see if there was a cleaner way. Is this possible?
subcommands: [
{
name: 'link',
messageRun: <function from other class here>
chatInputRun: <function from other class here>,
preconditions: ['AgeCheck'],
subcommands: [
{
name: 'link',
messageRun: <function from other class here>
chatInputRun: <function from other class here>,
preconditions: ['AgeCheck'],
what I'm currently doing:
subcommands: [
{
name: 'link',
messageRun: 'messageLink',
chatInputRun: 'chatInputLink',
preconditions: ['AgeCheck'],
....

public async messageLink(message: Message, args: Args) {
return message.channel.send(await Link.accountLink(message, args));
}

public async chatInputList(interaction: Subcommand.ChatInputCommandInteraction) {
return interaction.reply(await Link.accountLink(interaction, interaction.options))
}
subcommands: [
{
name: 'link',
messageRun: 'messageLink',
chatInputRun: 'chatInputLink',
preconditions: ['AgeCheck'],
....

public async messageLink(message: Message, args: Args) {
return message.channel.send(await Link.accountLink(message, args));
}

public async chatInputList(interaction: Subcommand.ChatInputCommandInteraction) {
return interaction.reply(await Link.accountLink(interaction, interaction.options))
}
4 replies
SIASapphire - Imagine a framework
Created by Baylem on 11/9/2023 in #sapphire-support
Issue with code not running after using args.rest('string') (NOT SAPPHIRE ISSUE)
public async messageLink(message: Message, args: Args) {
let region = 'na';
let summoner_name;

console.log('Message Content: ' + message.content);

if (message.content.split(' ').length > 2) {
const regionText = await args.pick('string');

console.log('Region Text: ' + regionText);
if (RiotUtil.isRegion(regionText)) {
region = regionText;
} else {
summoner_name = regionText;
}
}

console.log('Region 1: ' + region);
console.log('Summoner Name 1: ' + summoner_name);


if(summoner_name) {
console.log('region was not specified, combining all args');
summoner_name = summoner_name + await args.rest('string');
console.log('Summoner Name 1.5: ' + summoner_name);
} else {
console.log('region was specified, setting summoner name');
summoner_name = await args.rest('string');
}

console.log('Region 2: ' + region);
console.log('Summoner Name 2: ' + summoner_name);
}
public async messageLink(message: Message, args: Args) {
let region = 'na';
let summoner_name;

console.log('Message Content: ' + message.content);

if (message.content.split(' ').length > 2) {
const regionText = await args.pick('string');

console.log('Region Text: ' + regionText);
if (RiotUtil.isRegion(regionText)) {
region = regionText;
} else {
summoner_name = regionText;
}
}

console.log('Region 1: ' + region);
console.log('Summoner Name 1: ' + summoner_name);


if(summoner_name) {
console.log('region was not specified, combining all args');
summoner_name = summoner_name + await args.rest('string');
console.log('Summoner Name 1.5: ' + summoner_name);
} else {
console.log('region was specified, setting summoner name');
summoner_name = await args.rest('string');
}

console.log('Region 2: ' + region);
console.log('Summoner Name 2: ' + summoner_name);
}
https://i.imgur.com/UF6eC5d.png What am I missing here that is producing these results? Is this something weird with TypeScript or am I misunderstand Args. It seems to just stop running and doesn't get to the bottom two console log outputs, or even the one directly below the line of code
4 replies
SIASapphire - Imagine a framework
Created by Baylem on 11/7/2023 in #sapphire-support
Invoking Command method from other command
Hey all, I’m not really sure if this is a “Sapphire support” type of question more than a TypeScript one (I’m new to TS in general) But is there any way to invoke a commands messageRun or the designated method from say another command class (something like Java reflection/does sapphire have a command handler to grab the appropriate method?) or is the best way to extract the code to a new file then just call that from both commands? Basically I have a command which is: $account link <region> <account name> But I also have another command which is: $verify <region> <account name> or $verify <account name> Is there any way for me to just have the verify commands call the: $account link chat input method Or is the best way to just have like a Verification.ts and have the command logic in there and call that method from every command. Honestly just trying to minimize ts files if possible
8 replies
SIASapphire - Imagine a framework
Created by Baylem on 10/16/2023 in #sapphire-support
Sapphire json Configuration
So I arranged my packages like this below: https://i.imgur.com/crYUZyB.png and I changed my .sapphirerc.json to:
{
"projectLanguage": "ts",
"locations": {
"base": "src/sapphire",
"arguments": "arguments",
"commands": "commands",
"listeners": "listeners",
"preconditions": "preconditions",
"interaction-handlers": "interaction-handlers",
"routes": "routes"
},
"customFileTemplates": {
"enabled": false,
"location": ""
}
}
{
"projectLanguage": "ts",
"locations": {
"base": "src/sapphire",
"arguments": "arguments",
"commands": "commands",
"listeners": "listeners",
"preconditions": "preconditions",
"interaction-handlers": "interaction-handlers",
"routes": "routes"
},
"customFileTemplates": {
"enabled": false,
"location": ""
}
}
But it seems sapphire is not picking anything up, what other steps would I be missing? (side note its 2am so im probably just doing this wrong)
4 replies
SIASapphire - Imagine a framework
Created by Baylem on 8/28/2023 in #sapphire-support
Broken TypeScript command (from lack of knowledge of TS)
I'm attempting to create a command following the Sapphire wiki, but it seems that I can't get the command to work at all. Note: I am very new to Typescript, I am not familiar with the syntax or the proper form to do stuff, please be gentle
import {Subcommand} from '@sapphire/plugin-subcommands';
import {Args} from "@sapphire/framework";
import {Message} from "discord.js";

export class AccountCommand extends Subcommand {
public constructor(context: Subcommand.Context, options: Subcommand.Options) {
super(context, {
...options,
name: 'account',
aliases: ['acc', 'link', 'verify'],
description: 'Link to your Discord Account',
subcommands: [
{
name: 'link',
messageRun: 'messageLink',
chatInputRun: 'chatInputLink',
default: true
},
{
name: 'list',
messageRun: 'messageList',
chatInputRun: 'chatInputList'
},
{
name: 'unlink',
messageRun: 'messageUnlink',
chatInputRun: 'chatInputUnlink',
}
]
});
}

registerApplicationCommands(registry: Subcommand.Registry) {
registry.registerChatInputCommand((builder) =>
builder
.setName(this.name)
.setDescription(this.description)
.addSubcommand((command) =>
command
.setName('link')
.setDescription('Link your Discord Account')
.addStringOption((option) =>
option.setName('summoner').setDescription('Summoner Name').setRequired(true)
)
)
.addSubcommand((command) =>
command
.setName('list')
.setDescription('View summoner names linked to your Discord Account')
)
.addSubcommand((command) =>
command
.setName('unlink')
.setDescription('Unlink a summoner name from your Discord Account')
.addStringOption((option) =>
option.setName('summoner').setDescription('Summoner Name').setRequired(true)
)
)
);
}

/** START Link Subcommand **/
public async messageLink(message: Message, args: Args) {
return message.channel.send('Account Link')
}

public async chatInputLink(interaction: Subcommand.ChatInputCommandInteraction) {
return interaction.reply('Account Link Interaction');
}
/** END link Subcommand **/

/** START List Subcommand **/
public async messageList(message: Message, args: Args) {
return message.channel.send('Account List')
}

public async chatInputList(interaction: Subcommand.ChatInputCommandInteraction) {
return interaction.reply('Account List Interaction');
}
/** END List Subcommand **/

/** START Unlink Subcommand **/
public async messageUnlink(message: Message, args: Args) {
return message.channel.send('Account Unlink')
}

public async chatInputUnlink(interaction: Subcommand.ChatInputCommandInteraction) {
return interaction.reply('Account Unlink Interaction');
}
/** END Unlink Subcommand **/
}
import {Subcommand} from '@sapphire/plugin-subcommands';
import {Args} from "@sapphire/framework";
import {Message} from "discord.js";

export class AccountCommand extends Subcommand {
public constructor(context: Subcommand.Context, options: Subcommand.Options) {
super(context, {
...options,
name: 'account',
aliases: ['acc', 'link', 'verify'],
description: 'Link to your Discord Account',
subcommands: [
{
name: 'link',
messageRun: 'messageLink',
chatInputRun: 'chatInputLink',
default: true
},
{
name: 'list',
messageRun: 'messageList',
chatInputRun: 'chatInputList'
},
{
name: 'unlink',
messageRun: 'messageUnlink',
chatInputRun: 'chatInputUnlink',
}
]
});
}

registerApplicationCommands(registry: Subcommand.Registry) {
registry.registerChatInputCommand((builder) =>
builder
.setName(this.name)
.setDescription(this.description)
.addSubcommand((command) =>
command
.setName('link')
.setDescription('Link your Discord Account')
.addStringOption((option) =>
option.setName('summoner').setDescription('Summoner Name').setRequired(true)
)
)
.addSubcommand((command) =>
command
.setName('list')
.setDescription('View summoner names linked to your Discord Account')
)
.addSubcommand((command) =>
command
.setName('unlink')
.setDescription('Unlink a summoner name from your Discord Account')
.addStringOption((option) =>
option.setName('summoner').setDescription('Summoner Name').setRequired(true)
)
)
);
}

/** START Link Subcommand **/
public async messageLink(message: Message, args: Args) {
return message.channel.send('Account Link')
}

public async chatInputLink(interaction: Subcommand.ChatInputCommandInteraction) {
return interaction.reply('Account Link Interaction');
}
/** END link Subcommand **/

/** START List Subcommand **/
public async messageList(message: Message, args: Args) {
return message.channel.send('Account List')
}

public async chatInputList(interaction: Subcommand.ChatInputCommandInteraction) {
return interaction.reply('Account List Interaction');
}
/** END List Subcommand **/

/** START Unlink Subcommand **/
public async messageUnlink(message: Message, args: Args) {
return message.channel.send('Account Unlink')
}

public async chatInputUnlink(interaction: Subcommand.ChatInputCommandInteraction) {
return interaction.reply('Account Unlink Interaction');
}
/** END Unlink Subcommand **/
}
This is the command I created, the .js version worked, but when i moved it over to TypeScript it just stopped working entirely.
63 replies