fix: fix cloning tools from git

This commit is contained in:
DuroCodes
2024-06-20 22:39:59 -04:00
parent 68ee39407b
commit 7ea8d0bcfe
5 changed files with 203 additions and 58 deletions

View File

@@ -2,12 +2,10 @@
title: Localizer
description: Translate your bot for the world
sidebar:
order: 1
order: 2
---
# @sern/localizer
A localization module for managing translations and providing localized content in your application.
## Installation
@@ -16,25 +14,47 @@ A localization module for managing translations and providing localized content
npm i @sern/localizer
```
## Usage
**Initializing the Localizer**
```ts
import { makeDependencies } from '@sern/handler';
import { Localization } from '@sern/localizer';
await makeDependencies(({ add }) => {
add('localizer', Localization());
});
```
This localizer is **FILE BASED**.
Create the directory `assets/locals`. Each json file in here must be named after the `locale`
import { Tabs, TabItem } from "@astrojs/starlight/components";
## Usage
**Initializing the Localizer**
<Tabs>
<TabItem label ="src/index.js">
```ts {2} {6}
import { makeDependencies } from '@sern/handler';
import { Localization } from '@sern/localizer';
await makeDependencies(({ add }) => {
// add other deps
add('localizer', Localization());
});
```
</TabItem>
<TabItem label="src/dependencies.d.ts">
```ts {5}
import type { Logging, CoreDependencies } from '@sern/handler'
import type { Localizer } from '@sern/localizer'
declare global {
interface Dependencies extends CoreDependencies {
localizer: Localizer;
}
}
export {}
```
</TabItem>
</Tabs>
This localizer is **FILE BASED**.
Create the directory `assets/locals`. Each json file in here must be named after the `locale`
<Tabs>
<TabItem label="Spanish">
```json title=~/assets/locals/es.json
```json title=~/assets/locals/es-ES.json
{
"salute": {
"hello": "hola"
@@ -46,7 +66,7 @@ import { Tabs, TabItem } from "@astrojs/starlight/components";
```json title=~/assets/locals/en-US.json
{
"salute": {
"hello": "hola"
"hello": "hello"
}
}
```
@@ -62,7 +82,7 @@ execute : (ctx, { deps }) => {
//the localizer object from makeDependencies
deps.localizer
// Returns the Spanish translation for 'salute.hello'
deps.localizer.translate("salute.hello", "es");
deps.localizer.translate("salute.hello", "es-ES");
}
```
@@ -71,5 +91,5 @@ execute : (ctx, { deps }) => {
import { local } from '@sern/localizer';
// Returns the Spanish translation for 'salute.hello'
const greeting = local('salute.hello', 'es');
const greeting = local('salute.hello', 'es-ES');
```

View File

@@ -0,0 +1,106 @@
---
title: Publisher
description: Publish application commands as a Service
sidebar:
order: 1
---
## Implicits
- Requires process.env to be populated
- A common provider of this is `dotenv`
```txt title=".env"
DISCORD_TOKEN=<YOUR_TOKEN>
NODE_ENV=<production|development>
```
- Calls the discord API with the [PUT route](https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-global-application-commands). Wherever your commands directory is located, publish will override the existing application commands at Discord.
## Usage
**Initializing the Publisher**
```ts
import { makeDependencies } from '@sern/handler';
import { Publisher } from '@sern/publisher';
await makeDependencies(({ add }) => {
add('publisher', new Publisher());
});
```
## Features
- Automatically syncs api with your command base
- generates JSON file of output (**.sern/command-data-remote.json**)
- supports a configuration that is the same as the original publish plugin.
Each command file can have an extra plugin `publishConfig` that follows `ValidPublishOptions`:
## Config
```ts
type ValidMemberPermissions =
| typeof PermissionFlagBits //discord.js enum
| typeof PermissionFlagBits[] //array of discord.js enum
| string //must be a stringified number
| bigint
interface PublishConfig {
guildIds?: string[];
defaultMemberPermissions?: ValidMemberPermissions;
integrationTypes?: Array<'Guild'|'User'>
contexts: number[]
}
type ValidPublishOptions =
| PublishConfig
| (absPath: string, module: CommandModule) => PublishConfig
```
:::tip
These types are exported under @sern/publisher
:::
### Example: command published with integrationTypes
:::tip
Make sure you modify the install method in the Discord dev portal
:::
```ts title=src/commands/ping.ts
import { commandModule, CommandType } from '@sern/handler'
import { publishConfig } from '@sern/publisher'
export default commandModule( {
type: CommandType.Slash,
plugins: [
publishConfig({
integrationTypes: ['User'],
contexts: [1,2]
})
],
description: `hello worl`,
execute: (ctx) => {
ctx.reply('pong')
}
})
```
### Example: command published in guild
```ts title=src/commands/ping.ts
import { commandModule, CommandType } from '@sern/handler'
import { publishConfig } from '@sern/publisher'
export default commandModule( {
type: CommandType.Slash,
plugins: [
publishConfig({
guildIds: ["889026545715400705"]
})
],
description: `hello worl`,
execute: (ctx) => {
ctx.reply('pong')
}
})
```