0.2.0 • Published 1 year ago

scalecord.ts v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Scalecord.ts

Powerful Discord API library based on Discordeno components, allowing vertical and horizontal scaling.

Features

  • Standalone Rest Proxy - Features
  • Standalone Gateway Proxy - Features
  • On Work Cache Proxy
  • On Work Structures
  • Support of Node.js & Deno (experimental) runtime

See below for the Guide

If you need help, feel free to join our Discord server. ☺

Seperate Gateway/Rest

The seperate gateway/rest setup requires you to have two processes. One, which will have the standalone gateway/rest and the other your bot, where the Discord Payloads will be transmitted to.

It is also possible creating two seperate processes for the standalone gateway & rest for the sake of simplicity the example below will show both together.

File: Server.js

  • Starts the Rest Proxy, which will forward the requests from your Bot to Discord and respond with the result back
  • Starts the Gateway Proxy, which will connect to the Discord Gateway and send the Discord Gateway Packets to the connected Machines.
import { GatewayServerProvider, RestServerProvider , Server} from 'scalecord.ts'; // change to lib import
import { GatewayIntents } from 'discordeno/types';
import config from './config.json'
const server = new Server({
    token: config.token,
    providers: {
        rest: new RestServerProvider({
            secretKey: '111',
            customUrl: 'http://localhost:3000'
        }),
        gateway: new GatewayServerProvider({
            secretKey: '111',
            customUrl: 'http://localhost:3001',
            intents: GatewayIntents.GuildMessages | GatewayIntents.MessageContent,
            // tcpOptions: Opt-into tls & certificate mode, when you want to use it on a public machine
            // -> https://github.com/meister03/discord-cross-hosting#42-certificate-mode
            totalMachines: 1,
        })
    }
})

server.gateway?.start()

File: Bot.js

  • Connects the GatewayProvider to the TCP Server on the Server.js file and receives the Packets from it
  • Rest requests are forwarded to the rest proxy
  • Based on the amount of totalMachines provided in the Server.js file, that amount of Bot.js file has to be started. (Will be done soon by discord-hybrid-sharding)
import { RestClientProvider, createBot, GatewayClientProvider } from 'scalecord.ts';
import config from './config.json'

const bot = createBot({
    token: config.token,
    events: {
        messageCreate: (bot, message)=>{
            if(message.isFromBot) return;
            // do your stuff
        }
    }
},
    {
        rest: new RestClientProvider({
            secretKey: '111',
            customUrl: 'http://localhost:3000',
        }),
        gateway: new GatewayClientProvider({
            secretKey: '111',
            customUrl: 'http://localhost:3001',
            // tcpOptions: Opt-into tls & certificate mode, when you want to use it on a public machine
            // -> https://github.com/meister03/discord-cross-hosting#42-certificate-mode
        })
    }
)
bot.gateway?.start()

Status:

  • A Cache implementation is currently on work
  • The internal functions can be overwritten inorder to create an other implementation

Bugs, glitches and issues

If you encounter any problems feel free to open an issue in our GitHub repository or join the Discord server.