mirror of
https://github.com/sern-handler/handler
synced 2026-06-19 14:22:13 +00:00
Presence namespaced types removed
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
import path from 'node:path';
|
||||
import assert from 'assert';
|
||||
import { createRequire } from 'node:module';
|
||||
import type { Wrapper } from '../types/core';
|
||||
import { existsSync } from 'fs';
|
||||
import type { Logging } from './interfaces';
|
||||
|
||||
|
||||
export const parseCallsite = (fpath: string) => {
|
||||
@@ -54,32 +51,3 @@ export const fmtFileName = (fileName: string) => path.parse(fileName).name;
|
||||
|
||||
export const filename = (p: string) => fmtFileName(path.basename(p));
|
||||
|
||||
const requir = createRequire(import.meta.url);
|
||||
|
||||
export function loadConfig(wrapper: Wrapper | 'file', log: Logging | undefined): Wrapper {
|
||||
if (wrapper !== 'file') {
|
||||
return wrapper;
|
||||
}
|
||||
log?.info({ message: 'Experimental loading of sern.config.json'});
|
||||
const config = requir(path.resolve('sern.config.json'));
|
||||
|
||||
const makePath = (dir: PropertyKey) =>
|
||||
config.language === 'typescript'
|
||||
? path.join('dist', config.paths[dir]!)
|
||||
: path.join(config.paths[dir]!);
|
||||
|
||||
log?.info({ message: 'Loading config: ' + JSON.stringify(config, null, 4) });
|
||||
const commandsPath = makePath('commands');
|
||||
|
||||
log?.info({ message: `Commands path is set to ${commandsPath}` });
|
||||
let eventsPath: string | undefined;
|
||||
if (config.paths.events) {
|
||||
eventsPath = makePath('events');
|
||||
log?.info({ message: `Events path is set to ${eventsPath} `});
|
||||
}
|
||||
|
||||
return { defaultPrefix: config.defaultPrefix,
|
||||
commands: commandsPath,
|
||||
events: eventsPath };
|
||||
|
||||
}
|
||||
|
||||
@@ -67,9 +67,6 @@ export function discordEvent<T extends keyof ClientEvents>(mod: {
|
||||
plugins?: AnyEventPlugin[];
|
||||
execute: (...args: ClientEvents[T]) => Awaitable<unknown>;
|
||||
}) {
|
||||
return eventModule({
|
||||
type: EventType.Discord,
|
||||
...mod,
|
||||
});
|
||||
return eventModule({ type: EventType.Discord, ...mod, });
|
||||
}
|
||||
|
||||
|
||||
@@ -3,65 +3,63 @@ import type { IntoDependencies } from "../types/ioc";
|
||||
import type { Emitter } from "./interfaces";
|
||||
|
||||
type Status = 'online' | 'idle' | 'invisible' | 'dnd'
|
||||
type PresenceReduce = (previous: Result) => Result;
|
||||
type PresenceReduce = (previous: PresenceResult) => PresenceResult;
|
||||
|
||||
export interface Result {
|
||||
export interface PresenceResult {
|
||||
status?: Status;
|
||||
afk?: boolean;
|
||||
activities?: ActivitiesOptions[];
|
||||
shardId?: number[];
|
||||
repeat?: number | [Emitter, string];
|
||||
onRepeat?: (previous: Result) => Result;
|
||||
onRepeat?: (previous: PresenceResult) => PresenceResult;
|
||||
}
|
||||
|
||||
export type Config <T extends (keyof Dependencies)[]> =
|
||||
{
|
||||
export const Presence = {
|
||||
/**
|
||||
* A small wrapper to provide type inference.
|
||||
* Create a Presence module which **MUST** be put in a file called presence.(language-extension)
|
||||
* adjacent to the file where **Sern.init** is CALLED.
|
||||
*/
|
||||
module : <T extends (keyof Dependencies)[]>(conf: PresenceConfig<T>) => conf,
|
||||
/**
|
||||
* Create a Presence body which can be either:
|
||||
* - once, the presence is activated only once.
|
||||
* - repeated, per cycle or event, the presence can be changed.
|
||||
*/
|
||||
of : (root: Omit<PresenceResult, 'repeat' | 'onRepeat'>) => {
|
||||
return {
|
||||
/**
|
||||
* @example
|
||||
* Presence
|
||||
* .of({
|
||||
* activities: [{ name: "deez nuts" }]
|
||||
* }) //starts the presence with "deez nuts".
|
||||
* .repeated(prev => {
|
||||
* return {
|
||||
* afk: true,
|
||||
* activities: prev.activities?.map(s => ({ ...s, name: s.name+"s" }))
|
||||
* };
|
||||
* }, 10000)) //every 10 s, the callback sets the presence to the returned one.
|
||||
*/
|
||||
repeated: (onRepeat: PresenceReduce, repeat: number | [Emitter, string]) => {
|
||||
return { repeat, onRepeat, ...root }
|
||||
},
|
||||
/**
|
||||
* @example
|
||||
* Presence
|
||||
* .of({
|
||||
* activities: [
|
||||
* { name: "Chilling out" }
|
||||
* ]
|
||||
* })
|
||||
* .once() // Sets the presence once, with what's provided in '.of()'
|
||||
*/
|
||||
once: () => root
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export type PresenceConfig <T extends (keyof Dependencies)[]> = {
|
||||
inject?: [...T]
|
||||
execute: (...v: IntoDependencies<T>) => Result;
|
||||
execute: (...v: IntoDependencies<T>) => PresenceResult;
|
||||
};
|
||||
|
||||
/**
|
||||
* A small wrapper to provide type inference.
|
||||
* Create a Presence module which **MUST** be put in a file called presence.(language-extension)
|
||||
* adjacent to the file where **Sern.init** is CALLED.
|
||||
*/
|
||||
export const module = <T extends (keyof Dependencies)[]>(conf: Config<T>) => conf;
|
||||
|
||||
|
||||
/**
|
||||
* Create a Presence body which can be either:
|
||||
* - once, the presence is activated only once.
|
||||
* - repeated, per cycle or event, the presence can be changed.
|
||||
*/
|
||||
export function of(root: Omit<Result, 'repeat' | 'onRepeat'>) {
|
||||
return {
|
||||
/**
|
||||
* @example
|
||||
* Presence
|
||||
* .of({
|
||||
* activities: [{ name: "deez nuts" }]
|
||||
* }) //starts the presence with "deez nuts".
|
||||
* .repeated(prev => {
|
||||
* return {
|
||||
* afk: true,
|
||||
* activities: prev.activities?.map(s => ({ ...s, name: s.name+"s" }))
|
||||
* };
|
||||
* }, 10000)) //every 10 s, the callback sets the presence to the returned one.
|
||||
*/
|
||||
repeated: (onRepeat: PresenceReduce, repeat: number | [Emitter, string]) => {
|
||||
return { repeat, onRepeat, ...root }
|
||||
},
|
||||
/**
|
||||
* @example
|
||||
* Presence
|
||||
* .of({
|
||||
* activities: [
|
||||
* { name: "Chilling out" }
|
||||
* ]
|
||||
* })
|
||||
* .once() // Sets the presence once, with what's provided in '.of()'
|
||||
*/
|
||||
once: () => root
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -8,12 +8,10 @@ export class DefaultErrorHandling implements ErrorHandling {
|
||||
crash(err: Error): never {
|
||||
throw err;
|
||||
}
|
||||
|
||||
#keepAlive = 1;
|
||||
|
||||
keepAlive = 1;
|
||||
updateAlive(err: Error) {
|
||||
this.#keepAlive--;
|
||||
if (this.#keepAlive === 0) {
|
||||
this.keepAlive--;
|
||||
if (this.keepAlive === 0) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user