Skip to content

Commit

Permalink
fix: async presence (#369)
Browse files Browse the repository at this point in the history
* fix: async presence

* fixes to typings
  • Loading branch information
jacoobes authored Oct 6, 2024
1 parent 1789ccb commit eabfb81
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions src/core/presences.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { ActivitiesOptions } from "discord.js";
import type { IntoDependencies } from "./ioc";
import type { Emitter } from "./interfaces";
import { Awaitable } from "../types/utility";

type Status = 'online' | 'idle' | 'invisible' | 'dnd'
type PresenceReduce = (previous: Presence.Result) => Presence.Result;


type PresenceReduce = (previous: Presence.Result) => Awaitable<Presence.Result>;

export const Presence = {
/**
Expand Down Expand Up @@ -50,7 +49,7 @@ export const Presence = {
export declare namespace Presence {
export type Config<T extends (keyof Dependencies)[]> = {
inject?: [...T]
execute: (...v: IntoDependencies<T>) => Presence.Result;
execute: (...v: IntoDependencies<T>) => Awaitable<Presence.Result>;

}

Expand All @@ -60,7 +59,7 @@ export declare namespace Presence {
activities?: ActivitiesOptions[];
shardId?: number[];
repeat?: number | [Emitter, string];
onRepeat?: (previous: Result) => Result;
onRepeat?: PresenceReduce
}
}

4 changes: 2 additions & 2 deletions src/handlers/presence.ts
Original file line number Diff line number Diff line change
@@ -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 { Services } from "../core/ioc";
import assert from "node:assert";
Expand All @@ -14,7 +14,7 @@ const parseConfig = async (conf: Promise<Presence.Result>) => {
const src$ = typeof repeat === 'number'
? interval(repeat)
: fromEvent(...repeat);
return src$.pipe(scan(onRepeat, s),
return src$.pipe(mergeScan(async (args) => onRepeat(args), s),
startWith(s));
}
return of(s).pipe(take(1));
Expand Down

0 comments on commit eabfb81

Please sign in to comment.