mirror of
https://github.com/thelounge/thelounge.git
synced 2024-06-06 07:42:17 +02:00
[ts-migrate][src] Init tsconfig.json file
Co-authored-by: ts-migrate <>
This commit is contained in:
parent
e2362c836a
commit
d164784d8b
|
@ -174,7 +174,7 @@ class Client {
|
|||
return chan;
|
||||
}
|
||||
|
||||
emit(event: string, data: any) {
|
||||
emit(event: string, data?: any) {
|
||||
if (this.manager !== null) {
|
||||
this.manager.sockets.in(this.id.toString()).emit(event, data);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
"use strict";
|
||||
|
||||
if (!require("../../config").values.ldap.enable) {
|
||||
require("./add");
|
||||
require("./reset");
|
||||
import config from "../../config";
|
||||
|
||||
if (!config.values.ldap.enable) {
|
||||
import("./add");
|
||||
import("./reset");
|
||||
}
|
||||
|
||||
require("./list");
|
||||
require("./remove");
|
||||
require("./edit");
|
||||
import "./list";
|
||||
import "./remove";
|
||||
import "./edit";
|
||||
|
|
|
@ -122,7 +122,7 @@ class Identification {
|
|||
|
||||
fs.writeFile(this.oidentdFile, file, {flag: "w+"}, function (err) {
|
||||
if (err) {
|
||||
log.error("Failed to update oidentd file!", err);
|
||||
log.error("Failed to update oidentd file!", err.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
"use strict";
|
||||
|
||||
const colors = require("chalk");
|
||||
const read = require("read");
|
||||
import colors from "chalk";
|
||||
import read from "read";
|
||||
|
||||
function timestamp() {
|
||||
const datetime = new Date().toISOString().split(".")[0].replace("T", " ");
|
||||
|
@ -9,26 +9,29 @@ function timestamp() {
|
|||
return colors.dim(datetime);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
/* eslint-disable no-console */
|
||||
error(...args) {
|
||||
error(...args: string[]) {
|
||||
console.error(timestamp(), colors.red("[ERROR]"), ...args);
|
||||
},
|
||||
warn(...args) {
|
||||
warn(...args: string[]) {
|
||||
console.error(timestamp(), colors.yellow("[WARN]"), ...args);
|
||||
},
|
||||
info(...args) {
|
||||
info(...args: string[]) {
|
||||
console.log(timestamp(), colors.blue("[INFO]"), ...args);
|
||||
},
|
||||
debug(...args) {
|
||||
debug(...args: string[]) {
|
||||
console.log(timestamp(), colors.green("[DEBUG]"), ...args);
|
||||
},
|
||||
raw(...args) {
|
||||
raw(...args: string[]) {
|
||||
console.log(...args);
|
||||
},
|
||||
/* eslint-enable no-console */
|
||||
|
||||
prompt(options, callback) {
|
||||
prompt(
|
||||
options: {prompt: string; text: string},
|
||||
callback: (error, result, isDefault) => void
|
||||
): void {
|
||||
options.prompt = [timestamp(), colors.cyan("[PROMPT]"), options.text].join(" ");
|
||||
read(options, callback);
|
||||
},
|
|
@ -25,6 +25,9 @@ class Chan {
|
|||
type: ChanType;
|
||||
state: ChanState;
|
||||
|
||||
// TODO: this only exists when it's a query... should be better typed
|
||||
userAway: boolean;
|
||||
|
||||
constructor(attr: Partial<Chan>) {
|
||||
_.defaults(this, attr, {
|
||||
id: 0,
|
||||
|
|
|
@ -22,6 +22,23 @@ class Msg {
|
|||
new_ident: string;
|
||||
new_host: string;
|
||||
ctcpMessage: string;
|
||||
command: string;
|
||||
invitedYou: boolean;
|
||||
gecos: string;
|
||||
account: boolean;
|
||||
|
||||
// these are all just for error:
|
||||
error: string;
|
||||
nick: string;
|
||||
channel: string;
|
||||
reason: string;
|
||||
|
||||
raw_modes: any;
|
||||
when: Date;
|
||||
whois: any;
|
||||
users: UserInMessage[];
|
||||
statusmsgGroup: string;
|
||||
params: string[];
|
||||
|
||||
constructor(attr: Partial<Msg>) {
|
||||
// Some properties need to be copied in the Msg object instead of referenced
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
"use strict";
|
||||
|
||||
const got = require("got");
|
||||
const colors = require("chalk");
|
||||
const log = require("../log");
|
||||
const pkg = require("../../package.json");
|
||||
import got, {Response} from "got";
|
||||
import colors from "chalk";
|
||||
import log from "../log";
|
||||
import pkg from "../../package.json";
|
||||
import ClientManager from "src/clientManager";
|
||||
|
||||
const TIME_TO_LIVE = 15 * 60 * 1000; // 15 minutes, in milliseconds
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
isUpdateAvailable: false,
|
||||
fetch,
|
||||
checkForUpdates,
|
||||
|
@ -16,7 +17,11 @@ module.exports = {
|
|||
const versions = {
|
||||
current: {
|
||||
version: `v${pkg.version}`,
|
||||
changelog: undefined,
|
||||
},
|
||||
expiresAt: -1,
|
||||
latest: undefined,
|
||||
packages: undefined,
|
||||
};
|
||||
|
||||
async function fetch() {
|
||||
|
@ -50,9 +55,9 @@ async function fetch() {
|
|||
return versions;
|
||||
}
|
||||
|
||||
function updateVersions(response) {
|
||||
let i;
|
||||
let release;
|
||||
function updateVersions(response: Response<string>) {
|
||||
let i: number;
|
||||
let release: {tag_name: string; body_html: any; prerelease: boolean; html_url: any};
|
||||
let prerelease = false;
|
||||
|
||||
const body = JSON.parse(response.body);
|
||||
|
@ -90,7 +95,7 @@ function updateVersions(response) {
|
|||
}
|
||||
}
|
||||
|
||||
function checkForUpdates(manager) {
|
||||
function checkForUpdates(manager: ClientManager) {
|
||||
fetch().then((versionData) => {
|
||||
if (!module.exports.isUpdateAvailable) {
|
||||
// Check for updates every 24 hours + random jitter of <3 hours
|
|
@ -1,6 +1,7 @@
|
|||
"use strict";
|
||||
|
||||
import Network from "src/models/network";
|
||||
import {ChanType} from "src/types/models/channel";
|
||||
import {MessageType} from "src/types/models/message";
|
||||
import Chan from "../../models/chan";
|
||||
import Msg from "../../models/msg";
|
||||
|
|
|
@ -4,6 +4,7 @@ import Network from "src/models/network";
|
|||
import Chan from "src/models/chan";
|
||||
import Msg from "src/models/msg";
|
||||
import {MessageType} from "src/types/models/message";
|
||||
import {ChanType} from "src/types/models/channel";
|
||||
|
||||
const commands = ["ban", "unban", "banlist", "kickban"];
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import Chan from "src/models/chan";
|
|||
import Msg from "src/models/msg";
|
||||
import Helper from "src/helper";
|
||||
import {IgnoreListItem} from "src/types/models/network";
|
||||
import {SpecialChanType} from "src/types/models/channel";
|
||||
import {ChanType, SpecialChanType} from "src/types/models/channel";
|
||||
|
||||
const commands = ["ignore", "unignore", "ignorelist"];
|
||||
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
"use strict";
|
||||
|
||||
const Chan = require("../../models/chan");
|
||||
const Msg = require("../../models/msg");
|
||||
import Network from "src/models/network";
|
||||
import {ChanType} from "src/types/models/channel";
|
||||
import {MessageType} from "src/types/models/message";
|
||||
import Msg from "../../models/msg";
|
||||
|
||||
module.exports = function (irc, network) {
|
||||
export default function (irc: Network["irc"], network: Network) {
|
||||
const client = this;
|
||||
|
||||
irc.on("away", (data) => handleAway(Msg.Type.AWAY, data));
|
||||
irc.on("back", (data) => handleAway(Msg.Type.BACK, data));
|
||||
irc.on("away", (data) => handleAway(MessageType.AWAY, data));
|
||||
irc.on("back", (data) => handleAway(MessageType.BACK, data));
|
||||
|
||||
function handleAway(type, data) {
|
||||
const away = data.message;
|
||||
|
@ -28,7 +30,7 @@ module.exports = function (irc, network) {
|
|||
network.channels.forEach((chan) => {
|
||||
let user;
|
||||
|
||||
switch (ChanType) {
|
||||
switch (chan.type) {
|
||||
case ChanType.QUERY: {
|
||||
if (data.nick.toLowerCase() !== chan.name.toLowerCase()) {
|
||||
return;
|
||||
|
@ -70,4 +72,4 @@ module.exports = function (irc, network) {
|
|||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
"use strict";
|
||||
|
||||
const Msg = require("../../models/msg");
|
||||
const STSPolicies = require("../sts");
|
||||
import Network from "src/models/network";
|
||||
import Msg from "../../models/msg";
|
||||
import STSPolicies from "../sts";
|
||||
|
||||
module.exports = function (irc, network) {
|
||||
export default function (irc: Network["irc"], network: Network) {
|
||||
const client = this;
|
||||
|
||||
irc.on("cap ls", (data) => {
|
||||
|
@ -20,7 +21,7 @@ module.exports = function (irc, network) {
|
|||
}
|
||||
|
||||
const isSecure = irc.connection.transport.socket.encrypted;
|
||||
const values = {};
|
||||
const values = {} as any;
|
||||
|
||||
data.capabilities.sts.split(",").map((value) => {
|
||||
value = value.split("=", 2);
|
||||
|
@ -75,4 +76,4 @@ module.exports = function (irc, network) {
|
|||
client.save();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
"use strict";
|
||||
|
||||
const Msg = require("../../models/msg");
|
||||
import Network from "src/models/network";
|
||||
import {MessageType} from "src/types/models/message";
|
||||
|
||||
module.exports = function (irc, network) {
|
||||
import Msg from "src/models/msg";
|
||||
|
||||
export default function (irc: Network["irc"], network: Network) {
|
||||
const client = this;
|
||||
|
||||
// If server supports CHGHOST cap, then changing the hostname does not require
|
||||
|
@ -17,7 +20,7 @@ module.exports = function (irc, network) {
|
|||
|
||||
const msg = new Msg({
|
||||
time: data.time,
|
||||
type: Msg.Type.CHGHOST,
|
||||
type: MessageType.CHGHOST,
|
||||
new_ident: data.ident !== data.new_ident ? data.new_ident : "",
|
||||
new_host: data.hostname !== data.new_hostname ? data.new_hostname : "",
|
||||
self: data.nick === irc.user.nick,
|
||||
|
@ -27,4 +30,4 @@ module.exports = function (irc, network) {
|
|||
chan.pushMessage(client, msg);
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
import _ from "lodash";
|
||||
import log from "../../log";
|
||||
import Msg from "../../models/msg";
|
||||
import Chan from "../../models/chan";
|
||||
import Helper from "../../helper";
|
||||
import Config from "../../config";
|
||||
import Network from "src/models/network";
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
"use strict";
|
||||
|
||||
const _ = require("lodash");
|
||||
const Helper = require("../../helper");
|
||||
const Msg = require("../../models/msg");
|
||||
const User = require("../../models/user");
|
||||
const pkg = require("../../../package.json");
|
||||
import Network from "src/models/network";
|
||||
import {MessageType} from "src/types/models/message";
|
||||
|
||||
import _ from "lodash";
|
||||
import Helper from "../../helper";
|
||||
import Msg from "../../models/msg";
|
||||
import User from "../../models/user";
|
||||
import pkg from "../../../package.json";
|
||||
|
||||
const ctcpResponses = {
|
||||
CLIENTINFO: () =>
|
||||
|
@ -16,7 +19,7 @@ const ctcpResponses = {
|
|||
VERSION: () => pkg.name + " " + Helper.getVersion() + " -- " + pkg.homepage,
|
||||
};
|
||||
|
||||
module.exports = function (irc, network) {
|
||||
export default function (irc: Network["irc"], network: Network) {
|
||||
const client = this;
|
||||
const lobby = network.channels[0];
|
||||
|
||||
|
@ -36,7 +39,7 @@ module.exports = function (irc, network) {
|
|||
}
|
||||
|
||||
const msg = new Msg({
|
||||
type: Msg.Type.CTCP,
|
||||
type: MessageType.CTCP,
|
||||
time: data.time,
|
||||
from: chan.getUser(data.nick),
|
||||
ctcpMessage: data.message,
|
||||
|
@ -76,7 +79,7 @@ module.exports = function (irc, network) {
|
|||
|
||||
// Let user know someone is making a CTCP request against their nick
|
||||
const msg = new Msg({
|
||||
type: Msg.Type.CTCP_REQUEST,
|
||||
type: MessageType.CTCP_REQUEST,
|
||||
time: data.time,
|
||||
from: new User({nick: target}),
|
||||
hostmask: data.ident + "@" + data.hostname,
|
||||
|
@ -88,4 +91,4 @@ module.exports = function (irc, network) {
|
|||
{trailing: false}
|
||||
)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,19 +1,23 @@
|
|||
"use strict";
|
||||
|
||||
const Msg = require("../../models/msg");
|
||||
const Config = require("../../config");
|
||||
import Msg from "../../models/msg";
|
||||
import Config from "../../config";
|
||||
import Network from "src/models/network";
|
||||
import {MessageType} from "src/types/models/message";
|
||||
|
||||
module.exports = function (irc, network) {
|
||||
export default function (irc: Network["irc"], network: Network) {
|
||||
const client = this;
|
||||
|
||||
irc.on("irc error", function (data) {
|
||||
const msg = new Msg({
|
||||
type: Msg.Type.ERROR,
|
||||
type: MessageType.ERROR,
|
||||
error: data.error,
|
||||
showInActive: true,
|
||||
// @ts-ignore
|
||||
nick: data.nick,
|
||||
channel: data.channel,
|
||||
reason: data.reason,
|
||||
// @ts-ignore TODO
|
||||
command: data.command,
|
||||
});
|
||||
|
||||
|
@ -48,7 +52,7 @@ module.exports = function (irc, network) {
|
|||
|
||||
const lobby = network.channels[0];
|
||||
const msg = new Msg({
|
||||
type: Msg.Type.ERROR,
|
||||
type: MessageType.ERROR,
|
||||
text: message,
|
||||
showInActive: true,
|
||||
});
|
||||
|
@ -74,7 +78,7 @@ module.exports = function (irc, network) {
|
|||
irc.on("nick invalid", function (data) {
|
||||
const lobby = network.channels[0];
|
||||
const msg = new Msg({
|
||||
type: Msg.Type.ERROR,
|
||||
type: MessageType.ERROR,
|
||||
text: data.nick + ": " + (data.reason || "Nickname is invalid."),
|
||||
showInActive: true,
|
||||
});
|
||||
|
@ -89,4 +93,4 @@ module.exports = function (irc, network) {
|
|||
nick: irc.user.nick,
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
"use strict";
|
||||
|
||||
const Msg = require("../../models/msg");
|
||||
import Network from "src/models/network";
|
||||
import {MessageType} from "src/types/models/message";
|
||||
import Msg from "../../models/msg";
|
||||
|
||||
module.exports = function (irc, network) {
|
||||
export default function (irc: Network["irc"], network: Network) {
|
||||
const client = this;
|
||||
|
||||
irc.on("help", function (data) {
|
||||
|
@ -10,11 +12,11 @@ module.exports = function (irc, network) {
|
|||
|
||||
if (data.help) {
|
||||
const msg = new Msg({
|
||||
type: Msg.Type.MONOSPACE_BLOCK,
|
||||
type: MessageType.MONOSPACE_BLOCK,
|
||||
command: "help",
|
||||
text: data.help,
|
||||
});
|
||||
lobby.pushMessage(client, msg, true);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
"use strict";
|
||||
|
||||
const Msg = require("../../models/msg");
|
||||
import Network from "src/models/network";
|
||||
import {MessageType} from "src/types/models/message";
|
||||
|
||||
module.exports = function (irc, network) {
|
||||
import Msg from "../../models/msg";
|
||||
|
||||
export default function (irc: Network["irc"], network: Network) {
|
||||
const client = this;
|
||||
|
||||
irc.on("info", function (data) {
|
||||
|
@ -10,11 +13,11 @@ module.exports = function (irc, network) {
|
|||
|
||||
if (data.info) {
|
||||
const msg = new Msg({
|
||||
type: Msg.Type.MONOSPACE_BLOCK,
|
||||
type: MessageType.MONOSPACE_BLOCK,
|
||||
command: "info",
|
||||
text: data.info,
|
||||
});
|
||||
lobby.pushMessage(client, msg, true);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
"use strict";
|
||||
|
||||
const Msg = require("../../models/msg");
|
||||
import Network from "src/models/network";
|
||||
import {MessageType} from "src/types/models/message";
|
||||
import Msg from "../../models/msg";
|
||||
|
||||
module.exports = function (irc, network) {
|
||||
export default function (irc: Network["irc"], network: Network) {
|
||||
const client = this;
|
||||
|
||||
irc.on("invite", function (data) {
|
||||
|
@ -15,7 +17,7 @@ module.exports = function (irc, network) {
|
|||
const invitedYou = data.invited === irc.user.nick;
|
||||
|
||||
const msg = new Msg({
|
||||
type: Msg.Type.INVITE,
|
||||
type: MessageType.INVITE,
|
||||
time: data.time,
|
||||
from: chan.getUser(data.nick),
|
||||
target: chan.getUser(data.invited),
|
||||
|
@ -25,4 +27,4 @@ module.exports = function (irc, network) {
|
|||
});
|
||||
chan.pushMessage(client, msg);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
"use strict";
|
||||
|
||||
const Chan = require("../../models/chan");
|
||||
const Msg = require("../../models/msg");
|
||||
const User = require("../../models/user");
|
||||
import {ChanState} from "src/types/models/channel";
|
||||
import {MessageType} from "src/types/models/message";
|
||||
import {Network} from "src/types/models/network";
|
||||
|
||||
module.exports = function (irc, network) {
|
||||
import Chan from "../../models/chan";
|
||||
import Msg from "../../models/msg";
|
||||
import User from "../../models/user";
|
||||
|
||||
module.exports = function (irc: Network["irc"], network: Network) {
|
||||
const client = this;
|
||||
|
||||
irc.on("join", function (data) {
|
||||
|
@ -13,7 +17,7 @@ module.exports = function (irc, network) {
|
|||
if (typeof chan === "undefined") {
|
||||
chan = client.createChannel({
|
||||
name: data.channel,
|
||||
state: Chan.State.JOINED,
|
||||
state: ChanState.JOINED,
|
||||
});
|
||||
|
||||
client.emit("join", {
|
||||
|
@ -28,7 +32,7 @@ module.exports = function (irc, network) {
|
|||
// Request channels' modes
|
||||
network.irc.raw("MODE", chan.name);
|
||||
} else if (data.nick === irc.user.nick) {
|
||||
chan.state = Chan.State.JOINED;
|
||||
chan.state = ChanState.JOINED;
|
||||
|
||||
client.emit("channel:state", {
|
||||
chan: chan.id,
|
||||
|
@ -43,7 +47,7 @@ module.exports = function (irc, network) {
|
|||
hostmask: data.ident + "@" + data.hostname,
|
||||
gecos: data.gecos,
|
||||
account: data.account,
|
||||
type: Msg.Type.JOIN,
|
||||
type: MessageType.JOIN,
|
||||
self: data.nick === irc.user.nick,
|
||||
});
|
||||
chan.pushMessage(client, msg);
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
"use strict";
|
||||
|
||||
const Chan = require("../../models/chan");
|
||||
const Msg = require("../../models/msg");
|
||||
import Network from "src/models/network";
|
||||
import {ChanState} from "src/types/models/channel";
|
||||
import {MessageType} from "src/types/models/message";
|
||||
|
||||
module.exports = function (irc, network) {
|
||||
import Chan from "../../models/chan";
|
||||
import Msg from "../../models/msg";
|
||||
|
||||
export default function (irc: Network["irc"], network: Network) {
|
||||
const client = this;
|
||||
|
||||
irc.on("kick", function (data) {
|
||||
|
@ -14,7 +18,7 @@ module.exports = function (irc, network) {
|
|||
}
|
||||
|
||||
const msg = new Msg({
|
||||
type: Msg.Type.KICK,
|
||||
type: MessageType.KICK,
|
||||
time: data.time,
|
||||
from: chan.getUser(data.nick),
|
||||
target: chan.getUser(data.kicked),
|
||||
|
@ -26,7 +30,7 @@ module.exports = function (irc, network) {
|
|||
|
||||
if (data.kicked === irc.user.nick) {
|
||||
chan.users = new Map();
|
||||
chan.state = Chan.State.PARTED;
|
||||
chan.state = ChanState.PARTED;
|
||||
|
||||
client.emit("channel:state", {
|
||||
chan: chan.id,
|
||||
|
@ -36,4 +40,4 @@ module.exports = function (irc, network) {
|
|||
chan.removeUser(msg.target);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,18 +1,23 @@
|
|||
"use strict";
|
||||
|
||||
const cheerio = require("cheerio");
|
||||
const got = require("got");
|
||||
const URL = require("url").URL;
|
||||
const mime = require("mime-types");
|
||||
const Config = require("../../config");
|
||||
const {findLinksWithSchema} = require("../../../client/js/helpers/ircmessageparser/findLinks");
|
||||
const storage = require("../storage");
|
||||
import * as cheerio from "cheerio";
|
||||
import got from "got";
|
||||
import {URL} from "url";
|
||||
import mime from "mime-types";
|
||||
|
||||
import Config from "../../config";
|
||||
import {findLinksWithSchema} from "client/js/helpers/ircmessageparser/findLinks";
|
||||
import storage from "../storage";
|
||||
import log from "src/log";
|
||||
import Client from "src/client";
|
||||
import Chan from "src/models/chan";
|
||||
import Msg from "src/models/msg";
|
||||
|
||||
const currentFetchPromises = new Map();
|
||||
const imageTypeRegex = /^image\/.+/;
|
||||
const mediaTypeRegex = /^(audio|video)\/.+/;
|
||||
const log = require("../../log");
|
||||
|
||||
module.exports = function (client, chan, msg, cleanText) {
|
||||
export default function (client: Client, chan: Chan, msg: Msg, cleanText: string) {
|
||||
if (!Config.values.prefetch) {
|
||||
return;
|
||||
}
|
||||
|
@ -43,6 +48,8 @@ module.exports = function (client, chan, msg, cleanText) {
|
|||
size: -1,
|
||||
link: link.link, // Send original matched link to the client
|
||||
shown: null,
|
||||
error: undefined,
|
||||
message: undefined,
|
||||
};
|
||||
|
||||
cleanLinks.push(preview);
|
||||
|
@ -63,9 +70,9 @@ module.exports = function (client, chan, msg, cleanText) {
|
|||
|
||||
return cleanLinks;
|
||||
}, []);
|
||||
};
|
||||
}
|
||||
|
||||
function parseHtml(preview, res, client) {
|
||||
function parseHtml(preview, res, client: Client) {
|
||||
return new Promise((resolve) => {
|
||||
const $ = cheerio.load(res.data);
|
||||
|
||||
|
@ -128,7 +135,7 @@ function parseHtml(preview, res, client) {
|
|||
});
|
||||
}
|
||||
|
||||
function parseHtmlMedia($, preview, client) {
|
||||
function parseHtmlMedia($: cheerio.CheerioAPI, preview, client) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (Config.values.disableMediaPreview) {
|
||||
reject();
|
||||
|
@ -202,8 +209,8 @@ function parseHtmlMedia($, preview, client) {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
function parse(msg, chan, preview, res, client) {
|
||||
// TODO: type preview
|
||||
function parse(msg: Msg, chan: Chan, preview: any, res, client: Client) {
|
||||
let promise;
|
||||
|
||||
preview.size = res.size;
|
||||
|
@ -467,7 +474,7 @@ function fetch(uri, headers) {
|
|||
return promise;
|
||||
}
|
||||
|
||||
function normalizeURL(link, baseLink, disallowHttp = false) {
|
||||
function normalizeURL(link: string, baseLink?: string, disallowHttp = false) {
|
||||
try {
|
||||
const url = new URL(link, baseLink);
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
const Chan = require("../../models/chan");
|
||||
|
||||
module.exports = function (irc, network) {
|
||||
module.exports = function (irc: Network["irc"], network: Network) {
|
||||
const client = this;
|
||||
const MAX_CHANS = 500;
|
||||
|
||||
|
|
|
@ -1,33 +1,35 @@
|
|||
"use strict";
|
||||
|
||||
const Chan = require("../../models/chan");
|
||||
const Msg = require("../../models/msg");
|
||||
const LinkPrefetch = require("./link");
|
||||
const cleanIrcMessage = require("../../../client/js/helpers/ircmessageparser/cleanIrcMessage");
|
||||
const Helper = require("../../helper");
|
||||
import Msg from "../../models/msg";
|
||||
import LinkPrefetch from "./link";
|
||||
import cleanIrcMessage from "../../../client/js/helpers/ircmessageparser/cleanIrcMessage";
|
||||
import Helper from "../../helper";
|
||||
import Network from "src/models/network";
|
||||
import {ChanType} from "src/types/models/channel";
|
||||
import {MessageType} from "src/types/models/message";
|
||||
const nickRegExp = /(?:\x03[0-9]{1,2}(?:,[0-9]{1,2})?)?([\w[\]\\`^{|}-]+)/g;
|
||||
|
||||
module.exports = function (irc, network) {
|
||||
export default function (irc: Network["irc"], network: Network) {
|
||||
const client = this;
|
||||
|
||||
irc.on("notice", function (data) {
|
||||
data.type = Msg.Type.NOTICE;
|
||||
data.type = MessageType.NOTICE as any;
|
||||
handleMessage(data);
|
||||
});
|
||||
|
||||
irc.on("action", function (data) {
|
||||
data.type = Msg.Type.ACTION;
|
||||
data.type = MessageType.ACTION;
|
||||
handleMessage(data);
|
||||
});
|
||||
|
||||
irc.on("privmsg", function (data) {
|
||||
data.type = Msg.Type.MESSAGE;
|
||||
data.type = MessageType.MESSAGE;
|
||||
handleMessage(data);
|
||||
});
|
||||
|
||||
irc.on("wallops", function (data) {
|
||||
data.from_server = true;
|
||||
data.type = Msg.Type.WALLOPS;
|
||||
data.type = MessageType.WALLOPS;
|
||||
handleMessage(data);
|
||||
});
|
||||
|
||||
|
@ -76,7 +78,7 @@ module.exports = function (irc, network) {
|
|||
|
||||
if (typeof chan === "undefined") {
|
||||
// Send notices that are not targeted at us into the server window
|
||||
if (data.type === Msg.Type.NOTICE) {
|
||||
if (data.type === MessageType.NOTICE) {
|
||||
showInActive = true;
|
||||
chan = network.channels[0];
|
||||
} else {
|
||||
|
@ -152,7 +154,7 @@ module.exports = function (irc, network) {
|
|||
}
|
||||
|
||||
// No prefetch URLs unless are simple MESSAGE or ACTION types
|
||||
if ([Msg.Type.MESSAGE, Msg.Type.ACTION].includes(data.type)) {
|
||||
if ([MessageType.MESSAGE, MessageType.ACTION].includes(data.type)) {
|
||||
LinkPrefetch(client, chan, msg, cleanMessage);
|
||||
}
|
||||
|
||||
|
@ -163,7 +165,7 @@ module.exports = function (irc, network) {
|
|||
let title = chan.name;
|
||||
let body = cleanMessage;
|
||||
|
||||
if (msg.type === Msg.Type.ACTION) {
|
||||
if (msg.type === MessageType.ACTION) {
|
||||
// For actions, do not include colon in the message
|
||||
body = `${data.nick} ${body}`;
|
||||
} else if (chan.type !== ChanType.QUERY) {
|
||||
|
@ -213,4 +215,4 @@ module.exports = function (irc, network) {
|
|||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
"use strict";
|
||||
|
||||
const _ = require("lodash");
|
||||
const Msg = require("../../models/msg");
|
||||
import _ from "lodash";
|
||||
import Network from "src/models/network";
|
||||
import {MessageType} from "src/types/models/message";
|
||||
import Msg from "../../models/msg";
|
||||
|
||||
module.exports = function (irc, network) {
|
||||
export default function (irc: Network["irc"], network: Network) {
|
||||
const client = this;
|
||||
|
||||
// The following saves the channel key based on channel mode instead of
|
||||
|
@ -33,7 +35,7 @@ module.exports = function (irc, network) {
|
|||
});
|
||||
|
||||
const msg = new Msg({
|
||||
type: Msg.Type.MODE_CHANNEL,
|
||||
type: MessageType.MODE_CHANNEL,
|
||||
text: `${data.raw_modes} ${data.raw_params.join(" ")}`,
|
||||
});
|
||||
targetChan.pushMessage(client, msg);
|
||||
|
@ -43,7 +45,7 @@ module.exports = function (irc, network) {
|
|||
const serverChan = network.channels[0];
|
||||
|
||||
const msg = new Msg({
|
||||
type: Msg.Type.MODE_USER,
|
||||
type: MessageType.MODE_USER,
|
||||
raw_modes: data.raw_modes,
|
||||
self: false,
|
||||
showInActive: true,
|
||||
|
@ -66,7 +68,7 @@ module.exports = function (irc, network) {
|
|||
|
||||
const msg = new Msg({
|
||||
time: data.time,
|
||||
type: Msg.Type.MODE,
|
||||
type: MessageType.MODE,
|
||||
from: targetChan.getUser(data.nick),
|
||||
text: `${data.raw_modes} ${data.raw_params.join(" ")}`,
|
||||
self: data.nick === irc.user.nick,
|
||||
|
@ -144,4 +146,4 @@ module.exports = function (irc, network) {
|
|||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
"use strict";
|
||||
|
||||
const Chan = require("../../models/chan");
|
||||
const Msg = require("../../models/msg");
|
||||
import Network from "src/models/network";
|
||||
import {ChanType, SpecialChanType} from "src/types/models/channel";
|
||||
import {MessageType} from "src/types/models/message";
|
||||
|
||||
module.exports = function (irc, network) {
|
||||
import Chan from "../../models/chan";
|
||||
import Msg from "../../models/msg";
|
||||
|
||||
export default function (irc: Network["irc"], network: Network) {
|
||||
const client = this;
|
||||
|
||||
irc.on("banlist", (list) => {
|
||||
|
@ -13,7 +17,7 @@ module.exports = function (irc, network) {
|
|||
banned_at: ban.banned_at * 1000,
|
||||
}));
|
||||
|
||||
handleList(Chan.SpecialType.BANLIST, "Ban list", list.channel, data);
|
||||
handleList(SpecialChanType.BANLIST, "Ban list", list.channel, data);
|
||||
});
|
||||
|
||||
irc.on("inviteList", (list) => {
|
||||
|
@ -23,14 +27,23 @@ module.exports = function (irc, network) {
|
|||
invited_at: invite.invited_at * 1000,
|
||||
}));
|
||||
|
||||
handleList(Chan.SpecialType.INVITELIST, "Invite list", list.channel, data);
|
||||
handleList(SpecialChanType.INVITELIST, "Invite list", list.channel, data);
|
||||
});
|
||||
|
||||
function handleList(type, name, channel, data) {
|
||||
function handleList(
|
||||
type: SpecialChanType,
|
||||
name: string,
|
||||
channel: string,
|
||||
data: {
|
||||
hostmask: string;
|
||||
invited_by?: string;
|
||||
inivted_at?: number;
|
||||
}[]
|
||||
) {
|
||||
if (data.length === 0) {
|
||||
const msg = new Msg({
|
||||
time: Date.now(),
|
||||
type: Msg.Type.ERROR,
|
||||
time: new Date(),
|
||||
type: MessageType.ERROR,
|
||||
text: `${name} is empty`,
|
||||
});
|
||||
let chan = network.getChannel(channel);
|
||||
|
@ -62,6 +75,7 @@ module.exports = function (irc, network) {
|
|||
index: network.addChannel(chan),
|
||||
});
|
||||
} else {
|
||||
//@ts-ignore TODO
|
||||
chan.data = data;
|
||||
|
||||
client.emit("msg:special", {
|
||||
|
@ -70,4 +84,4 @@ module.exports = function (irc, network) {
|
|||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
"use strict";
|
||||
|
||||
const Msg = require("../../models/msg");
|
||||
import Network from "src/models/network";
|
||||
import {MessageType} from "src/types/models/message";
|
||||
import Msg from "../../models/msg";
|
||||
|
||||
module.exports = function (irc, network) {
|
||||
export default function (irc: Network["irc"], network: Network) {
|
||||
const client = this;
|
||||
|
||||
irc.on("motd", function (data) {
|
||||
|
@ -10,7 +12,7 @@ module.exports = function (irc, network) {
|
|||
|
||||
if (data.motd) {
|
||||
const msg = new Msg({
|
||||
type: Msg.Type.MONOSPACE_BLOCK,
|
||||
type: MessageType.MONOSPACE_BLOCK,
|
||||
command: "motd",
|
||||
text: data.motd,
|
||||
});
|
||||
|
@ -19,11 +21,11 @@ module.exports = function (irc, network) {
|
|||
|
||||
if (data.error) {
|
||||
const msg = new Msg({
|
||||
type: Msg.Type.MONOSPACE_BLOCK,
|
||||
type: MessageType.MONOSPACE_BLOCK,
|
||||
command: "motd",
|
||||
text: data.error,
|
||||
});
|
||||
lobby.pushMessage(client, msg);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
"use strict";
|
||||
|
||||
module.exports = function (irc, network) {
|
||||
import Network from "src/models/network";
|
||||
|
||||
export default function (irc: Network["irc"], network: Network) {
|
||||
const client = this;
|
||||
|
||||
irc.on("userlist", function (data) {
|
||||
|
@ -25,4 +27,4 @@ module.exports = function (irc, network) {
|
|||
chan: chan.id,
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
"use strict";
|
||||
|
||||
const Msg = require("../../models/msg");
|
||||
import Network from "src/models/network";
|
||||
import {MessageType} from "src/types/models/message";
|
||||
import Msg from "../../models/msg";
|
||||
|
||||
module.exports = function (irc, network) {
|
||||
export default function (irc: Network["irc"], network: Network) {
|
||||
const client = this;
|
||||
|
||||
irc.on("nick", function (data) {
|
||||
|
@ -34,7 +36,7 @@ module.exports = function (irc, network) {
|
|||
const msg = new Msg({
|
||||
time: data.time,
|
||||
from: user,
|
||||
type: Msg.Type.NICK,
|
||||
type: MessageType.NICK,
|
||||
new_nick: data.new_nick,
|
||||
});
|
||||
chan.pushMessage(client, msg);
|
||||
|
@ -48,4 +50,4 @@ module.exports = function (irc, network) {
|
|||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
"use strict";
|
||||
|
||||
const Msg = require("../../models/msg");
|
||||
import Network from "src/models/network";
|
||||
import {MessageType} from "src/types/models/message";
|
||||
|
||||
module.exports = function (irc, network) {
|
||||
import Msg from "../../models/msg";
|
||||
|
||||
export default function (irc: Network["irc"], network: Network) {
|
||||
const client = this;
|
||||
|
||||
irc.on("part", function (data) {
|
||||
|
@ -14,7 +17,7 @@ module.exports = function (irc, network) {
|
|||
|
||||
const user = chan.getUser(data.nick);
|
||||
const msg = new Msg({
|
||||
type: Msg.Type.PART,
|
||||
type: MessageType.PART,
|
||||
time: data.time,
|
||||
text: data.message || "",
|
||||
hostmask: data.ident + "@" + data.hostname,
|
||||
|
@ -29,4 +32,4 @@ module.exports = function (irc, network) {
|
|||
chan.removeUser(user);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
"use strict";
|
||||
|
||||
const Msg = require("../../models/msg");
|
||||
import Network from "src/models/network";
|
||||
import {MessageType} from "src/types/models/message";
|
||||
import Msg from "../../models/msg";
|
||||
|
||||
module.exports = function (irc, network) {
|
||||
export default function (irc: Network["irc"], network: Network) {
|
||||
const client = this;
|
||||
|
||||
irc.on("quit", function (data) {
|
||||
|
@ -15,7 +17,7 @@ module.exports = function (irc, network) {
|
|||
|
||||
const msg = new Msg({
|
||||
time: data.time,
|
||||
type: Msg.Type.QUIT,
|
||||
type: MessageType.QUIT,
|
||||
text: data.message || "",
|
||||
hostmask: data.ident + "@" + data.hostname,
|
||||
from: user,
|
||||
|
@ -31,4 +33,4 @@ module.exports = function (irc, network) {
|
|||
network.keepNick = null;
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
"use strict";
|
||||
|
||||
const Msg = require("../../models/msg");
|
||||
import Network from "src/models/network";
|
||||
import {MessageType} from "src/types/models/message";
|
||||
|
||||
module.exports = function (irc, network) {
|
||||
import Msg from "../../models/msg";
|
||||
|
||||
export default function (irc: Network["irc"], network: Network) {
|
||||
const client = this;
|
||||
|
||||
irc.on("loggedin", (data) => {
|
||||
const lobby = network.channels[0];
|
||||
|
||||
const msg = new Msg({
|
||||
type: Msg.Type.LOGIN,
|
||||
type: MessageType.LOGIN,
|
||||
text: "Logged in as: " + data.account,
|
||||
});
|
||||
lobby.pushMessage(client, msg, true);
|
||||
|
@ -19,9 +22,9 @@ module.exports = function (irc, network) {
|
|||
const lobby = network.channels[0];
|
||||
|
||||
const msg = new Msg({
|
||||
type: Msg.Type.LOGOUT,
|
||||
type: MessageType.LOGOUT,
|
||||
text: "Logged out",
|
||||
});
|
||||
lobby.pushMessage(client, msg, true);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
"use strict";
|
||||
|
||||
const Msg = require("../../models/msg");
|
||||
import Network from "src/models/network";
|
||||
import {MessageType} from "src/types/models/message";
|
||||
import Msg from "../../models/msg";
|
||||
|
||||
module.exports = function (irc, network) {
|
||||
export default function (irc: Network["irc"], network: Network) {
|
||||
const client = this;
|
||||
|
||||
irc.on("topic", function (data) {
|
||||
|
@ -14,7 +16,7 @@ module.exports = function (irc, network) {
|
|||
|
||||
const msg = new Msg({
|
||||
time: data.time,
|
||||
type: Msg.Type.TOPIC,
|
||||
type: MessageType.TOPIC,
|
||||
from: data.nick && chan.getUser(data.nick),
|
||||
text: data.topic,
|
||||
self: data.nick === irc.user.nick,
|
||||
|
@ -36,11 +38,11 @@ module.exports = function (irc, network) {
|
|||
}
|
||||
|
||||
const msg = new Msg({
|
||||
type: Msg.Type.TOPIC_SET_BY,
|
||||
type: MessageType.TOPIC_SET_BY,
|
||||
from: chan.getUser(data.nick),
|
||||
when: new Date(data.when * 1000),
|
||||
self: data.nick === irc.user.nick,
|
||||
});
|
||||
chan.pushMessage(client, msg);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
"use strict";
|
||||
|
||||
const Msg = require("../../models/msg");
|
||||
import Network from "src/models/network";
|
||||
import {MessageType} from "src/types/models/message";
|
||||
import Msg from "../../models/msg";
|
||||
|
||||
module.exports = function (irc, network) {
|
||||
export default function (irc: Network["irc"], network: Network) {
|
||||
const client = this;
|
||||
|
||||
irc.on("unknown command", function (command) {
|
||||
|
@ -27,11 +29,11 @@ module.exports = function (irc, network) {
|
|||
target.pushMessage(
|
||||
client,
|
||||
new Msg({
|
||||
type: Msg.Type.UNHANDLED,
|
||||
type: MessageType.UNHANDLED,
|
||||
command: command.command,
|
||||
params: command.params,
|
||||
}),
|
||||
true
|
||||
);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
"use strict";
|
||||
|
||||
const Msg = require("../../models/msg");
|
||||
import Network from "src/models/network";
|
||||
import Msg from "../../models/msg";
|
||||
|
||||
module.exports = function (irc, network) {
|
||||
export default function (irc: Network["irc"], network: Network) {
|
||||
const client = this;
|
||||
|
||||
irc.on("registered", function (data) {
|
||||
|
@ -20,4 +21,4 @@ module.exports = function (irc, network) {
|
|||
nick: data.nick,
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
"use strict";
|
||||
|
||||
const Chan = require("../../models/chan");
|
||||
const Msg = require("../../models/msg");
|
||||
import Network from "src/models/network";
|
||||
import {ChanType} from "src/types/models/channel";
|
||||
import {MessageType} from "src/types/models/message";
|
||||
import Msg from "../../models/msg";
|
||||
|
||||
module.exports = function (irc, network) {
|
||||
export default function (irc: Network["irc"], network: Network) {
|
||||
const client = this;
|
||||
|
||||
irc.on("whois", handleWhois);
|
||||
|
@ -42,7 +44,7 @@ module.exports = function (irc, network) {
|
|||
|
||||
if (data.error) {
|
||||
msg = new Msg({
|
||||
type: Msg.Type.ERROR,
|
||||
type: MessageType.ERROR,
|
||||
text: "No such nick: " + data.nick,
|
||||
});
|
||||
} else {
|
||||
|
@ -51,11 +53,11 @@ module.exports = function (irc, network) {
|
|||
// Absolute datetime in milliseconds when nick logged on.
|
||||
data.logonTime = data.logon * 1000;
|
||||
msg = new Msg({
|
||||
type: Msg.Type.WHOIS,
|
||||
type: MessageType.WHOIS,
|
||||
whois: data,
|
||||
});
|
||||
}
|
||||
|
||||
chan.pushMessage(client, msg);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ class TextFileMessageStorage implements MessageStorage {
|
|||
line,
|
||||
(e) => {
|
||||
if (e) {
|
||||
log.error("Failed to write user log", e);
|
||||
log.error("Failed to write user log", e.message);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
@ -51,7 +51,7 @@ module.exports = class PublicClient {
|
|||
chan.pushMessage(
|
||||
this.client,
|
||||
new Msg({
|
||||
type: Msg.Type.PLUGIN,
|
||||
type: MessageType.PLUGIN,
|
||||
text: text,
|
||||
from: {
|
||||
nick: this.packageInfo.name || this.packageInfo.packageName,
|
||||
|
|
4
src/types/config.d.ts
vendored
4
src/types/config.d.ts
vendored
|
@ -52,6 +52,10 @@ type ServerConfiguration = Config & {
|
|||
stylesheets: string[];
|
||||
};
|
||||
|
||||
type IndexTemplateConfiguration = ServerConfiguration & {
|
||||
cacheBust: string;
|
||||
};
|
||||
|
||||
// TODO: Type this
|
||||
type WebIRC = {
|
||||
[key: string]: any;
|
||||
|
|
5
src/types/modules/irc-framework.d.ts
vendored
5
src/types/modules/irc-framework.d.ts
vendored
|
@ -17,6 +17,7 @@ declare module "irc-framework" {
|
|||
|
||||
transport: any;
|
||||
write: (data: string) => void;
|
||||
end: () => void;
|
||||
};
|
||||
|
||||
export class Client extends EventEmitter {
|
||||
|
@ -29,11 +30,13 @@ declare module "irc-framework" {
|
|||
CHANTYPES: string;
|
||||
PREFIX: any;
|
||||
CHANMODES: string;
|
||||
NICKLEN: string;
|
||||
};
|
||||
cap: {
|
||||
isEnabled: (cap: string) => boolean;
|
||||
enabled: string[];
|
||||
};
|
||||
extractTargetGroup: (target: string) => any;
|
||||
};
|
||||
// End of added by Max
|
||||
|
||||
|
@ -258,6 +261,7 @@ declare module "irc-framework" {
|
|||
message: string;
|
||||
nick: string;
|
||||
time?: any;
|
||||
channel?: string;
|
||||
}
|
||||
interface Mode {
|
||||
mode: string;
|
||||
|
@ -310,6 +314,7 @@ declare module "irc-framework" {
|
|||
nick: string;
|
||||
username: string;
|
||||
gecos: string;
|
||||
host: string;
|
||||
}
|
||||
|
||||
class IrcChannel extends EventEmitter {
|
||||
|
|
Loading…
Reference in a new issue