mirror of
https://github.com/thelounge/thelounge
synced 2024-11-22 03:53:08 +00:00
irc-events/message: fix types
This commit is contained in:
parent
92a0affba1
commit
e2b56cf16b
2 changed files with 22 additions and 22 deletions
|
@ -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,
|
||||
|
|
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;
|
||||
tags: {[key: string]: string};
|
||||
target: string;
|
||||
time?: any;
|
||||
type: "privmsg" | "action" | "notice" | "wallops";
|
||||
time?: number;
|
||||
}
|
||||
export interface JoinEventArgs {
|
||||
account: boolean;
|
||||
|
|
Loading…
Reference in a new issue