2022-06-19 00:25:21 +00:00
|
|
|
import Prefix from "./prefix";
|
|
|
|
|
|
|
|
class User {
|
2023-01-30 00:38:28 +00:00
|
|
|
modes: string[];
|
2022-06-19 00:25:21 +00:00
|
|
|
// Users in the channel have only one mode assigned
|
2023-01-30 00:38:28 +00:00
|
|
|
away: string;
|
|
|
|
nick: string;
|
|
|
|
lastMessage: number;
|
2022-06-19 00:25:21 +00:00
|
|
|
|
|
|
|
constructor(attr: Partial<User>, prefix?: Prefix) {
|
2023-01-30 00:38:28 +00:00
|
|
|
this.modes = [];
|
|
|
|
this.away = "";
|
|
|
|
this.nick = "";
|
|
|
|
this.lastMessage = 0;
|
|
|
|
|
|
|
|
if (attr) {
|
|
|
|
Object.assign(this, attr);
|
|
|
|
}
|
2022-06-19 00:25:21 +00:00
|
|
|
|
|
|
|
this.setModes(this.modes, prefix || new Prefix([]));
|
|
|
|
}
|
|
|
|
|
2023-01-30 00:38:28 +00:00
|
|
|
get mode() {
|
|
|
|
return this.modes[0] || "";
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
setModes(modes: string[], prefix: Prefix) {
|
|
|
|
// irc-framework sets character mode, but The Lounge works with symbols
|
|
|
|
this.modes = modes.map((mode) => prefix.modeToSymbol[mode]);
|
|
|
|
}
|
|
|
|
|
|
|
|
toJSON() {
|
|
|
|
return {
|
|
|
|
nick: this.nick,
|
|
|
|
modes: this.modes,
|
|
|
|
lastMessage: this.lastMessage,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default User;
|