fix: async presence (#369)

* fix: async presence

* fixes to typings
This commit is contained in:
Jacob Nguyen
2024-10-06 11:51:07 -05:00
committed by GitHub
parent 1789ccb2f2
commit eabfb81819
2 changed files with 6 additions and 7 deletions

View File

@@ -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
} }
} }

View File

@@ -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));