Basic privmsg sending

This commit is contained in:
emerson 2021-12-07 08:51:31 -05:00
parent ef8b6c49c7
commit fa7748794f
No known key found for this signature in database
GPG key ID: 270669502DA603E3
5 changed files with 17 additions and 11 deletions

View file

@ -131,8 +131,10 @@ export class Channel {
this.handleMatrixMember(event); this.handleMatrixMember(event);
break; break;
case 'm.room.message': { case 'm.room.message': {
if (this.eventIDsSeen.has(event["event_id"])) if (this.eventIDsSeen.has(event["event_id"])) {
console.log(`duplicate event_id: ${event["event_id"]}`);
return; return;
}
this.eventIDsSeen.add(event["event_id"]); this.eventIDsSeen.add(event["event_id"]);
this.handleMatrixMessage(event); this.handleMatrixMessage(event);
break; break;
@ -199,8 +201,7 @@ export class Channel {
msgArray.forEach((msg: string) => { msgArray.forEach((msg: string) => {
if (msg) { if (msg) {
this.ircUsers.forEach((user) => { this.ircUsers.forEach((user) => {
//@ts-ignore user.sendToAll(thisMatrixUser.getMask(), ircCommand, [this.name, msg], tags)
user.sendToAll(sender.getMask(), ircCommand, [this.name, msg], tags)
}); });
} }
}); });

View file

@ -187,7 +187,7 @@ export class Client {
return; return;
if (rooms['join']) { if (rooms['join']) {
for (const roomId of Object.keys(rooms.join)) { for (const roomId of Object.keys(rooms.join)) {
const targetChannel = this.server.matrixRooms.get(roomId) || new Channel(roomId, this.server); const targetChannel = this.server.getOrCreateIRCChannel(roomId);
this.user.channels.set(targetChannel.name, targetChannel); this.user.channels.set(targetChannel.name, targetChannel);
rooms.join[roomId].state.events.forEach((nextEvent: any) => targetChannel.routeMatrixEvent(nextEvent)); rooms.join[roomId].state.events.forEach((nextEvent: any) => targetChannel.routeMatrixEvent(nextEvent));
} }
@ -195,7 +195,6 @@ export class Client {
if (this.user === null) if (this.user === null)
return; return;
this.user.nextBatch = data.next_batch; this.user.nextBatch = data.next_batch;
console.log(this.user.nextBatch);
this.user.addClient(this, message.tags); this.user.addClient(this, message.tags);
}) })
} }

View file

@ -43,12 +43,9 @@ export class IRCUser {
} }
addClient(client: Client, passedTags: Map<string, string>) { addClient(client: Client, passedTags: Map<string, string>) {
console.log('adding client');
this.clients.add(client); this.clients.add(client);
if (this.nextBatch !== "") { if (this.nextBatch !== "") {
console.log('nextBatch is good');
for (const channel of this.channels.values()) { for (const channel of this.channels.values()) {
console.log('joining channel');
channel.joinNewIRCClient(client, passedTags); channel.joinNewIRCClient(client, passedTags);
} }
} }
@ -66,7 +63,7 @@ export class IRCUser {
const rooms = data.rooms; const rooms = data.rooms;
if (rooms && rooms['join']) { if (rooms && rooms['join']) {
for (const roomId of Object.keys(rooms.join)) { for (const roomId of Object.keys(rooms.join)) {
const targetChannel = this.server.matrixRooms.get(roomId) || new Channel(roomId, this.server); const targetChannel = this.server.getOrCreateIRCChannel(roomId);
rooms.join[roomId].timeline.events.forEach((nextEvent: any) => { rooms.join[roomId].timeline.events.forEach((nextEvent: any) => {
targetChannel.routeMatrixEvent(nextEvent) targetChannel.routeMatrixEvent(nextEvent)
}); });

View file

@ -101,7 +101,6 @@ export function parseIRCMessage(rawLine: string) {
if (restOfMessage.indexOf(' ') === -1) { if (restOfMessage.indexOf(' ') === -1) {
command = restOfMessage; command = restOfMessage;
console.log(parsedTags, prefix, command, params);
return new IRCMessage(parsedTags, prefix, command, params); return new IRCMessage(parsedTags, prefix, command, params);
} }

View file

@ -22,7 +22,7 @@ export class Server {
this.nickToMxid = new Map(); this.nickToMxid = new Map();
} }
getOrCreateIRCUser(mxid: string, accessToken: string) { getOrCreateIRCUser(mxid: string, accessToken: string): IRCUser {
const maybeUser = this.ircUsers.get(mxid); const maybeUser = this.ircUsers.get(mxid);
if (maybeUser) { if (maybeUser) {
return maybeUser; return maybeUser;
@ -30,6 +30,16 @@ export class Server {
return new IRCUser(mxid, accessToken, this); return new IRCUser(mxid, accessToken, this);
} }
getOrCreateIRCChannel(roomId: string): Channel {
const maybeChannel = this.matrixRooms.get(roomId);
if (maybeChannel)
return maybeChannel;
const newChannel = new Channel(roomId, this);
this.matrixRooms.set(roomId, newChannel);
return newChannel;
}
getOrCreateMatrixUser(mxid: string): MatrixUser { getOrCreateMatrixUser(mxid: string): MatrixUser {
let maybeMatrixUser = this.matrixUsers.get(mxid); let maybeMatrixUser = this.matrixUsers.get(mxid);
if (maybeMatrixUser) { if (maybeMatrixUser) {