mirror of
https://git.sr.ht/~emerson/reflectionircd
synced 2025-04-13 09:59:52 +00:00
basic privmsg/notice/emote sending
This commit is contained in:
parent
fa7748794f
commit
1af94c40b2
3 changed files with 41 additions and 4 deletions
|
@ -22,8 +22,8 @@ That said, it is usable for basic chatting.
|
||||||
|
|
||||||
| Name | M->I | I->M | Notes |
|
| Name | M->I | I->M | Notes |
|
||||||
| ---- | :--: | :--: | ----- |
|
| ---- | :--: | :--: | ----- |
|
||||||
| text, notice, emote messages | ❌ | ❌ ||
|
| text, notice, emote messages | ✅ | ✅ ||
|
||||||
| image, file, audio, video messages | ❌ | ❌ ||
|
| image, file, audio, video messages | 🟨 | ❌ | Show up as MXC links on IRC |
|
||||||
| Channel joins | ❌ | ❌ ||
|
| Channel joins | ❌ | ❌ ||
|
||||||
| Channel parts | ❌ | ❌ ||
|
| Channel parts | ❌ | ❌ ||
|
||||||
| Channel kicks | ❌ | ❌ ||
|
| Channel kicks | ❌ | ❌ ||
|
||||||
|
|
|
@ -79,10 +79,22 @@ export class Client {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'NOTICE': {
|
||||||
|
if (this.user) {
|
||||||
|
this.user.sendMessageToMatrix(message, this);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 'PING': {
|
case 'PING': {
|
||||||
this.sendMessage(this.server.name, "PONG", message.params, message.tags);
|
this.sendMessage(this.server.name, "PONG", message.params, message.tags);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'PRIVMSG': {
|
||||||
|
if (this.user) {
|
||||||
|
this.user.sendMessageToMatrix(message, this);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 'WHO': {
|
case 'WHO': {
|
||||||
if (!this.user) {
|
if (!this.user) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import { randomUUID } from "crypto";
|
||||||
import { Channel } from "./Channel.js";
|
import { Channel } from "./Channel.js";
|
||||||
import { Client } from "./Client.js";
|
import { Client } from "./Client.js";
|
||||||
|
import { IRCMessage } from "./Message.js";
|
||||||
import { Server } from "./Server.js";
|
import { Server } from "./Server.js";
|
||||||
|
|
||||||
export class IRCUser {
|
export class IRCUser {
|
||||||
|
@ -11,7 +13,7 @@ export class IRCUser {
|
||||||
private hostname: string
|
private hostname: string
|
||||||
public accountName: string
|
public accountName: string
|
||||||
public realname: string
|
public realname: string
|
||||||
private txnIdStore: Set<string>
|
private txnIdStore: Map<string, Client>
|
||||||
public nextBatch: string
|
public nextBatch: string
|
||||||
private initialSync: boolean
|
private initialSync: boolean
|
||||||
private syncIntervalID: NodeJS.Timeout;
|
private syncIntervalID: NodeJS.Timeout;
|
||||||
|
@ -24,7 +26,7 @@ export class IRCUser {
|
||||||
this.hostname = mxidSplit[1];
|
this.hostname = mxidSplit[1];
|
||||||
this.accountName = mxid.slice(1);
|
this.accountName = mxid.slice(1);
|
||||||
this.realname = this.accountName;
|
this.realname = this.accountName;
|
||||||
this.txnIdStore = new Set();
|
this.txnIdStore = new Map();
|
||||||
this.nextBatch = "";
|
this.nextBatch = "";
|
||||||
this.initialSync = false;
|
this.initialSync = false;
|
||||||
this.syncIntervalID = setInterval(this.doSync.bind(this), 15000);
|
this.syncIntervalID = setInterval(this.doSync.bind(this), 15000);
|
||||||
|
@ -72,6 +74,29 @@ export class IRCUser {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sendMessageToMatrix(message: IRCMessage, client: Client) {
|
||||||
|
const channel = this.server.matrixRooms.get(message.params[0]);
|
||||||
|
if (!channel) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let msgtype = 'm.text';
|
||||||
|
let msgbody = message.params[1];
|
||||||
|
if (message.command === 'NOTICE')
|
||||||
|
msgtype = 'm.notice';
|
||||||
|
else if (message.params[1].startsWith('\x01')) {
|
||||||
|
msgtype = 'm.emote';
|
||||||
|
msgbody = msgbody.replace(/\x01(ACTION\s)?/gi, '');
|
||||||
|
}
|
||||||
|
const roomId = channel.roomId;
|
||||||
|
const content = {
|
||||||
|
"body": msgbody,
|
||||||
|
"msgtype": msgtype,
|
||||||
|
}
|
||||||
|
const newTxnid = randomUUID();
|
||||||
|
this.txnIdStore.set(newTxnid, client);
|
||||||
|
axios.put(`https://matrix.org/_matrix/client/v3/rooms/${channel.roomId}/send/m.room.message/${newTxnid}?access_token=${this.accessToken}`, content);
|
||||||
|
}
|
||||||
|
|
||||||
sendToAll(prefix: string, command: string, params: string[], tags: Map<string, string> = new Map(), skipClient: Client|null = null) {
|
sendToAll(prefix: string, command: string, params: string[], tags: Map<string, string> = new Map(), skipClient: Client|null = null) {
|
||||||
this.clients.forEach(client => {
|
this.clients.forEach(client => {
|
||||||
if (client !== skipClient) {
|
if (client !== skipClient) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue