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);
break;
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;
}
this.eventIDsSeen.add(event["event_id"]);
this.handleMatrixMessage(event);
break;
@ -199,8 +201,7 @@ export class Channel {
msgArray.forEach((msg: string) => {
if (msg) {
this.ircUsers.forEach((user) => {
//@ts-ignore
user.sendToAll(sender.getMask(), ircCommand, [this.name, msg], tags)
user.sendToAll(thisMatrixUser.getMask(), ircCommand, [this.name, msg], tags)
});
}
});

View file

@ -187,7 +187,7 @@ export class Client {
return;
if (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);
rooms.join[roomId].state.events.forEach((nextEvent: any) => targetChannel.routeMatrixEvent(nextEvent));
}
@ -195,7 +195,6 @@ export class Client {
if (this.user === null)
return;
this.user.nextBatch = data.next_batch;
console.log(this.user.nextBatch);
this.user.addClient(this, message.tags);
})
}

View file

@ -43,12 +43,9 @@ export class IRCUser {
}
addClient(client: Client, passedTags: Map<string, string>) {
console.log('adding client');
this.clients.add(client);
if (this.nextBatch !== "") {
console.log('nextBatch is good');
for (const channel of this.channels.values()) {
console.log('joining channel');
channel.joinNewIRCClient(client, passedTags);
}
}
@ -66,7 +63,7 @@ export class IRCUser {
const rooms = data.rooms;
if (rooms && 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) => {
targetChannel.routeMatrixEvent(nextEvent)
});

View file

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

View file

@ -22,7 +22,7 @@ export class Server {
this.nickToMxid = new Map();
}
getOrCreateIRCUser(mxid: string, accessToken: string) {
getOrCreateIRCUser(mxid: string, accessToken: string): IRCUser {
const maybeUser = this.ircUsers.get(mxid);
if (maybeUser) {
return maybeUser;
@ -30,6 +30,16 @@ export class Server {
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 {
let maybeMatrixUser = this.matrixUsers.get(mxid);
if (maybeMatrixUser) {