irc-events/message: fix types

This commit is contained in:
Reto Brunner 2024-04-15 07:54:12 +02:00
parent 92a0affba1
commit e2b56cf16b
2 changed files with 22 additions and 22 deletions

View file

@ -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 <IrcEventHandler>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 <IrcEventHandler>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 <IrcEventHandler>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,

View file

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