diff --git a/server/plugins/irc-events/message.ts b/server/plugins/irc-events/message.ts index 21e3bffc..2e496624 100644 --- a/server/plugins/irc-events/message.ts +++ b/server/plugins/irc-events/message.ts @@ -7,20 +7,32 @@ import Chan from "../../models/chan"; import User from "../../models/user"; import {MessageType} from "../../../shared/types/msg"; import {ChanType} from "../../../shared/types/chan"; +import {MessageEventArgs} from "irc-framework"; const nickRegExp = /(?:\x03[0-9]{1,2}(?:,[0-9]{1,2})?)?([\w[\]\\`^{|}-]+)/g; +type HandleInput = { + nick: string; + hostname: string; + ident: string; + target: string; + type: MessageType; + time: number; + text?: string; + from_server?: boolean; + message: string; + group?: string; +}; + +function convertForHandle(type: MessageType, data: MessageEventArgs): HandleInput { + return {...data, time: data.time ? data.time : new Date().getTime(), type: type}; +} + export default function (irc, network) { const client = this; irc.on("notice", function (data) { - data.type = MessageType.NOTICE; - - type ModifiedData = typeof data & { - type: MessageType.NOTICE; - }; - - handleMessage(data as ModifiedData); + handleMessage(convertForHandle(MessageType.NOTICE, data)); }); irc.on("action", function (data) { @@ -39,18 +51,7 @@ export default function (irc, network) { handleMessage(data); }); - function handleMessage(data: { - nick: string; - hostname: string; - ident: string; - target: string; - type: MessageType; - time: number; - text?: string; - from_server?: boolean; - message: string; - group?: string; - }) { + function handleMessage(data: HandleInput) { let chan: Chan | undefined; let from: User; let highlight = false; @@ -128,7 +129,7 @@ export default function (irc, network) { // msg is constructed down here because `from` is being copied in the constructor const msg = new Msg({ type: data.type, - time: data.time as any, + time: new Date(data.time), text: data.message, self: self, from: from, diff --git a/server/types/modules/irc-framework.d.ts b/server/types/modules/irc-framework.d.ts index 8c0ff5c7..ef9f82df 100644 --- a/server/types/modules/irc-framework.d.ts +++ b/server/types/modules/irc-framework.d.ts @@ -33,8 +33,7 @@ declare module "irc-framework" { reply: (message: string) => void; tags: {[key: string]: string}; target: string; - time?: any; - type: "privmsg" | "action" | "notice" | "wallops"; + time?: number; } export interface JoinEventArgs { account: boolean;