mirror of
https://github.com/sern-handler/handler
synced 2026-06-26 17:52:14 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d0c3b7469e | ||
|
|
eabfb81819 | ||
|
|
1789ccb2f2 |
@@ -1,5 +1,13 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [4.0.3](https://github.com/sern-handler/handler/compare/v4.0.2...v4.0.3) (2024-10-06)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* async presence ([#369](https://github.com/sern-handler/handler/issues/369)) ([eabfb81](https://github.com/sern-handler/handler/commit/eabfb81819b53a4656d8eac6e21cfb488b724a42))
|
||||||
|
* fix eventModule typing for Discord events ([#368](https://github.com/sern-handler/handler/issues/368)) ([1789ccb](https://github.com/sern-handler/handler/commit/1789ccb2f22f502f87538fecdb07106ff7110434))
|
||||||
|
|
||||||
## [4.0.2](https://github.com/sern-handler/handler/compare/v4.0.1...v4.0.2) (2024-08-13)
|
## [4.0.2](https://github.com/sern-handler/handler/compare/v4.0.1...v4.0.2) (2024-08-13)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@sern/handler",
|
"name": "@sern/handler",
|
||||||
"packageManager": "yarn@3.5.0",
|
"packageManager": "yarn@3.5.0",
|
||||||
"version": "4.0.2",
|
"version": "4.0.3",
|
||||||
"description": "A complete, customizable, typesafe, & reactive framework for discord bots.",
|
"description": "A complete, customizable, typesafe, & reactive framework for discord bots.",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export function commandModule(mod: InputCommand): Module {
|
|||||||
* The wrapper function to define event modules for sern
|
* The wrapper function to define event modules for sern
|
||||||
* @param mod
|
* @param mod
|
||||||
*/
|
*/
|
||||||
export function eventModule(mod: InputEvent): Module {
|
export function eventModule<T extends keyof ClientEvents = keyof ClientEvents>(mod: InputEvent<T>): Module {
|
||||||
const [onEvent, plugins] = partitionPlugins(mod.plugins);
|
const [onEvent, plugins] = partitionPlugins(mod.plugins);
|
||||||
if(onEvent.length !== 0) throw Error("Event modules cannot have ControlPlugins");
|
if(onEvent.length !== 0) throw Error("Event modules cannot have ControlPlugins");
|
||||||
return { ...mod,
|
return { ...mod,
|
||||||
@@ -35,8 +35,9 @@ export function eventModule(mod: InputEvent): Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Create event modules from discord.js client events,
|
/** Create event modules from discord.js client events,
|
||||||
* This is an {@link eventModule} for discord events,
|
* This was an {@link eventModule} for discord events,
|
||||||
* where typings can be very bad.
|
* where typings were bad.
|
||||||
|
* @deprecated Use {@link eventModule} instead
|
||||||
* @param mod
|
* @param mod
|
||||||
*/
|
*/
|
||||||
export function discordEvent<T extends keyof ClientEvents>(mod: {
|
export function discordEvent<T extends keyof ClientEvents>(mod: {
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import type { ActivitiesOptions } from "discord.js";
|
import type { ActivitiesOptions } from "discord.js";
|
||||||
import type { IntoDependencies } from "./ioc";
|
import type { IntoDependencies } from "./ioc";
|
||||||
import type { Emitter } from "./interfaces";
|
import type { Emitter } from "./interfaces";
|
||||||
|
import { Awaitable } from "../types/utility";
|
||||||
|
|
||||||
type Status = 'online' | 'idle' | 'invisible' | 'dnd'
|
type Status = 'online' | 'idle' | 'invisible' | 'dnd'
|
||||||
type PresenceReduce = (previous: Presence.Result) => Presence.Result;
|
type PresenceReduce = (previous: Presence.Result) => Awaitable<Presence.Result>;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export const Presence = {
|
export const Presence = {
|
||||||
/**
|
/**
|
||||||
@@ -50,7 +49,7 @@ export const Presence = {
|
|||||||
export declare namespace Presence {
|
export declare namespace Presence {
|
||||||
export type Config<T extends (keyof Dependencies)[]> = {
|
export type Config<T extends (keyof Dependencies)[]> = {
|
||||||
inject?: [...T]
|
inject?: [...T]
|
||||||
execute: (...v: IntoDependencies<T>) => Presence.Result;
|
execute: (...v: IntoDependencies<T>) => Awaitable<Presence.Result>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +59,7 @@ export declare namespace Presence {
|
|||||||
activities?: ActivitiesOptions[];
|
activities?: ActivitiesOptions[];
|
||||||
shardId?: number[];
|
shardId?: number[];
|
||||||
repeat?: number | [Emitter, string];
|
repeat?: number | [Emitter, string];
|
||||||
onRepeat?: (previous: Result) => Result;
|
onRepeat?: PresenceReduce
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { concatMap, from, interval, of, map, scan, startWith, fromEvent, take } from "rxjs"
|
import { concatMap, from, interval, of, map, scan, startWith, fromEvent, take, mergeScan } from "rxjs"
|
||||||
import { Presence } from "../core/presences";
|
import { Presence } from "../core/presences";
|
||||||
import { Services } from "../core/ioc";
|
import { Services } from "../core/ioc";
|
||||||
import assert from "node:assert";
|
import assert from "node:assert";
|
||||||
@@ -14,7 +14,7 @@ const parseConfig = async (conf: Promise<Presence.Result>) => {
|
|||||||
const src$ = typeof repeat === 'number'
|
const src$ = typeof repeat === 'number'
|
||||||
? interval(repeat)
|
? interval(repeat)
|
||||||
: fromEvent(...repeat);
|
: fromEvent(...repeat);
|
||||||
return src$.pipe(scan(onRepeat, s),
|
return src$.pipe(mergeScan(async (args) => onRepeat(args), s),
|
||||||
startWith(s));
|
startWith(s));
|
||||||
}
|
}
|
||||||
return of(s).pipe(take(1));
|
return of(s).pipe(take(1));
|
||||||
|
|||||||
@@ -167,9 +167,9 @@ export interface CommandModuleDefs {
|
|||||||
[CommandType.Modal]: ModalSubmitCommand;
|
[CommandType.Modal]: ModalSubmitCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EventModuleDefs {
|
export interface EventModuleDefs<T extends keyof ClientEvents = keyof ClientEvents> {
|
||||||
[EventType.Sern]: SernEventCommand;
|
[EventType.Sern]: SernEventCommand;
|
||||||
[EventType.Discord]: DiscordEventCommand;
|
[EventType.Discord]: DiscordEventCommand<T>;
|
||||||
[EventType.External]: ExternalEventCommand;
|
[EventType.External]: ExternalEventCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,12 +186,12 @@ export interface SernAutocompleteData
|
|||||||
type CommandModuleNoPlugins = {
|
type CommandModuleNoPlugins = {
|
||||||
[T in CommandType]: Omit<CommandModuleDefs[T], 'plugins' | 'onEvent' | 'meta' | 'locals'>;
|
[T in CommandType]: Omit<CommandModuleDefs[T], 'plugins' | 'onEvent' | 'meta' | 'locals'>;
|
||||||
};
|
};
|
||||||
type EventModulesNoPlugins = {
|
type EventModulesNoPlugins<K extends keyof ClientEvents = keyof ClientEvents> = {
|
||||||
[T in EventType]: Omit<EventModuleDefs[T], 'plugins' | 'onEvent' | 'meta' | 'locals'> ;
|
[T in EventType]: Omit<EventModuleDefs<K>[T], 'plugins' | 'onEvent' | 'meta' | 'locals'> ;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type InputEvent = {
|
export type InputEvent<K extends keyof ClientEvents = keyof ClientEvents> = {
|
||||||
[T in EventType]: EventModulesNoPlugins[T] & {
|
[T in EventType]: EventModulesNoPlugins<K>[T] & {
|
||||||
once?: boolean;
|
once?: boolean;
|
||||||
plugins?: InitPlugin[]
|
plugins?: InitPlugin[]
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user