mirror of
https://github.com/thelounge/thelounge.git
synced 2024-06-04 14:52:19 +02:00
irc-events/message: fix types
This commit is contained in:
parent
92a0affba1
commit
e2b56cf16b
|
@ -7,20 +7,32 @@ import Chan from "../../models/chan";
|
||||||
import User from "../../models/user";
|
import User from "../../models/user";
|
||||||
import {MessageType} from "../../../shared/types/msg";
|
import {MessageType} from "../../../shared/types/msg";
|
||||||
import {ChanType} from "../../../shared/types/chan";
|
import {ChanType} from "../../../shared/types/chan";
|
||||||
|
import {MessageEventArgs} from "irc-framework";
|
||||||
|
|
||||||
const nickRegExp = /(?:\x03[0-9]{1,2}(?:,[0-9]{1,2})?)?([\w[\]\\`^{|}-]+)/g;
|
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) {
|
export default <IrcEventHandler>function (irc, network) {
|
||||||
const client = this;
|
const client = this;
|
||||||
|
|
||||||
irc.on("notice", function (data) {
|
irc.on("notice", function (data) {
|
||||||
data.type = MessageType.NOTICE;
|
handleMessage(convertForHandle(MessageType.NOTICE, data));
|
||||||
|
|
||||||
type ModifiedData = typeof data & {
|
|
||||||
type: MessageType.NOTICE;
|
|
||||||
};
|
|
||||||
|
|
||||||
handleMessage(data as ModifiedData);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
irc.on("action", function (data) {
|
irc.on("action", function (data) {
|
||||||
|
@ -39,18 +51,7 @@ export default <IrcEventHandler>function (irc, network) {
|
||||||
handleMessage(data);
|
handleMessage(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
function handleMessage(data: {
|
function handleMessage(data: HandleInput) {
|
||||||
nick: string;
|
|
||||||
hostname: string;
|
|
||||||
ident: string;
|
|
||||||
target: string;
|
|
||||||
type: MessageType;
|
|
||||||
time: number;
|
|
||||||
text?: string;
|
|
||||||
from_server?: boolean;
|
|
||||||
message: string;
|
|
||||||
group?: string;
|
|
||||||
}) {
|
|
||||||
let chan: Chan | undefined;
|
let chan: Chan | undefined;
|
||||||
let from: User;
|
let from: User;
|
||||||
let highlight = false;
|
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
|
// msg is constructed down here because `from` is being copied in the constructor
|
||||||
const msg = new Msg({
|
const msg = new Msg({
|
||||||
type: data.type,
|
type: data.type,
|
||||||
time: data.time as any,
|
time: new Date(data.time),
|
||||||
text: data.message,
|
text: data.message,
|
||||||
self: self,
|
self: self,
|
||||||
from: from,
|
from: from,
|
||||||
|
|
3
server/types/modules/irc-framework.d.ts
vendored
3
server/types/modules/irc-framework.d.ts
vendored
|
@ -33,8 +33,7 @@ declare module "irc-framework" {
|
||||||
reply: (message: string) => void;
|
reply: (message: string) => void;
|
||||||
tags: {[key: string]: string};
|
tags: {[key: string]: string};
|
||||||
target: string;
|
target: string;
|
||||||
time?: any;
|
time?: number;
|
||||||
type: "privmsg" | "action" | "notice" | "wallops";
|
|
||||||
}
|
}
|
||||||
export interface JoinEventArgs {
|
export interface JoinEventArgs {
|
||||||
account: boolean;
|
account: boolean;
|
||||||
|
|
Loading…
Reference in a new issue