Gacha game centered around vore.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
vore-gacha/src/BaseServer.ts

92 lines
2.9 KiB

import {SavedWebhook} from "./SavedWebhook.js";
import fastify, {FastifyInstance} from "fastify";
import {SlashCreator, SlashCreatorOptions} from "slash-create";
import fastifyCookie from "fastify-cookie";
import {FastifyServerButItWorksUnlikeTheRealOne} from "./FastifyHelpers.js";
export interface BaseServerDeps {
appId: string
botToken: string
clientSecret: string
publicKey: string
listenPort: number
listenAddress: string
cookieSecret: string
gameWebhook: SavedWebhook
adminWebhook: SavedWebhook
}
export class BaseServer {
readonly server: FastifyInstance
readonly gameWebhook: SavedWebhook
readonly adminWebhook: SavedWebhook
readonly appId: string
readonly clientSecret: string
readonly listenPort: number
readonly listenAddress: string
readonly slashcmd: SlashCreator
constructor({
cookieSecret,
appId,
clientSecret,
listenPort,
listenAddress,
gameWebhook,
adminWebhook,
publicKey,
botToken,
slashCreatorOptions = {}
}: BaseServerDeps & { slashCreatorOptions?: Partial<SlashCreatorOptions> }) {
this.slashcmd = new SlashCreator({
allowedMentions: {everyone: false, roles: false, users: false},
applicationID: appId,
defaultImageFormat: "webp",
handleCommandsManually: false,
maxSignatureTimestamp: 3000,
publicKey,
requestTimeout: 10000,
token: botToken,
unknownCommandResponse: true,
endpointPath: "/interactions",
...slashCreatorOptions,
})
this.server = fastify({logger: true})
this.slashcmd.withServer(new FastifyServerButItWorksUnlikeTheRealOne(this.server, {alreadyListening: true}))
this.server.register(fastifyCookie, {
secret: cookieSecret,
})
this.appId = appId
this.clientSecret = clientSecret
this.listenPort = listenPort
this.listenAddress = listenAddress
this.gameWebhook = gameWebhook
this.adminWebhook = adminWebhook
}
async _initInternal(): Promise<void> {
return
}
async initialize(): Promise<void> {
await this._initInternal()
await this.slashcmd.syncCommandsAsync({
syncGuilds: true,
syncPermissions: true,
skipGuildErrors: false,
deleteCommands: true,
})
await this.slashcmd.startServer()
await this.server.listen(this.listenPort, this.listenAddress)
}
async _shutdownInternal(): Promise<void> {
return
}
async shutdown(): Promise<void> {
await this._shutdownInternal()
return this.server.close()
}
}