Raw.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { EventBuilder, EventCommon } from "./common";
  2. import type { TelegramClient } from "../client/TelegramClient";
  3. import { Api } from "../tl";
  4. interface RawInterface {
  5. types?: Function[];
  6. func?: CallableFunction;
  7. }
  8. export class Raw extends EventBuilder {
  9. private types?: Function[];
  10. constructor({ types = undefined, func = undefined }: RawInterface) {
  11. super({ func: func });
  12. this.types = types;
  13. }
  14. async resolve(client: TelegramClient) {
  15. this.resolved = true;
  16. }
  17. build(update: Api.TypeUpdate, others: any = null): Api.TypeUpdate {
  18. return update;
  19. }
  20. filter(event: EventCommon) {
  21. if (this.types) {
  22. let correct = false;
  23. for (const type of this.types) {
  24. if (event instanceof type) {
  25. correct = true;
  26. break;
  27. }
  28. }
  29. if (!correct) {
  30. return;
  31. }
  32. }
  33. if (this.func) {
  34. return this.func(event);
  35. }
  36. return event;
  37. }
  38. }