~funderscore blog cgit wiki get in touch
aboutsummaryrefslogtreecommitdiff
blob: 584391d42a5ae16063fd30fde753ecc99c0d83c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# Matterpuppeter

*An API plugin for Matterbridge, that creates IRC puppets*

## Features

Turns this:

```
<Someone> rPerson, rando: hi both
<Matterbridge> [j] <rPerson> hello
<Matterbridge> [mx] <rando> Hi!
<Matterbridge> [irc2] <user> can i join in?
```

into this:

```
<Someone> rPerson|j, rando|mx: hi both
<rPerson|j> hello
--> rando|mx (934782619@matterpuppeter) (@rando:matrix.org [matrix.mxo]) has joined #chat
<rando|mx> Hi!
<user|irc2> can i join in?
```

- *Lazy puppeting*: creates a puppet only when users join or talk
- *Client limit*: limits how many puppets can connect at the same time
- *Built-in configurable pastebinning* of long codeblocks
- Works with *Matterbridge*'s REST API
- *Limited quit/join flood*: keeps connections alive during a Matterbridge 
  restart
  - Puppets are marked as "away" until Matterpuppeter can reconnect to the 
    Matterbridge API

In other words:

```
     Any protocol supported 
        by Matterbridge
  (e.g. XMPP, Discord, Matrix)
               |
               |
               v
          Matterbridge
               |
               |      Matterbridge API
               v
         Matterpuppeter
               |
               |      IRC protocol
               v
          IRC network
   (e.g. OFTC, Libera.Chat)
               |
               |
               v
          IRC channel
        (e.g. ##coffee)
```

This is not a standalone bridge.

## Caveats

- *Lazy puppeting*: while this makes client counts lower, it still means 
  people who do not have a puppet can still watch the channel on the other 
  side, without users on IRC knowing.
- *Portalling-style bridging* is not supported, on-purpose
- *Cannot bridge bans*: matterbridge does not support bridging bans and kicks
- *Private messages* are not supported
- *Connecting to multiple networks* is not supported - run Matterpuppeter 
  multiple times for each network instead

## How to

This currently requires a fork of Matterbridge: https://git.vitali64.duckdns.org/misc/matterbridge.git

Create a Matterbridge config by following [this guide](https://github.com/42wim/matterbridge/wiki/How-to-create-your-config).

Add the following at the top of your `matterbridge.toml`:

```
[api.matterpuppeter]
NoSendJoinPart=false
ShowJoinPart=true
BindAddress="127.0.0.1:4242"
Buffer=1000
RemoteNickFormat="{NICK}-{LABEL}"
Label="IRC"
```

If you're bridging to multiple IRC networks and want to use Matterpuppeter on 
all of them, you'll need one Matterpuppeter instance per network.

Add the following to one of the gateways you have configured:

```
[[gateway]]
name="gateway1"
<...>

    [[gateway.inout]]
    account="api.matterpuppeter"
    channel="api"

<...>
```

Now, you can configure Matterpuppeter itself.  The configuration is in 
`config.yaml`, and is extensively documented.  Do make sure to customise 
it, so it fits your bridging setup.

Here is a simple config file that will bridge to a `##Meow` channel on Libera.Chat:

```
irc:
  host: "irc.libera.chat"
  port: 6697
  tls: true
  nick: "_Bridger"
  gecos: "Matterpuppeter listener bot"
  message_limit: 380
  client_limit: 6

  sasl:
    enable: false

paste:
  enable: false

ident:
  enable: false

api:
  host: "http://localhost:4242"
  account: "api.matterpuppeter"

gateway:
  "gateway1": "##Meow"
```

### Pastebinning support

Long code blocks can be pastebinned to avoid spamming IRC.  This can be useful 
when it is common practise to paste snippets of code which would cause spam on 
the IRC side.  For example, the following message:

```
<f_> Here's my code:

     |  #include <stdio.h>
     |
     |  int main(int argc, char **argv)
     |  {
     |      print("This is a message\n");
     |
     |      return 0;
     |  }

```

can be bridged as:

```
<f_-X> Here's my code:
<f_-X> https://pastebin.matterpuppeter/<paste id here>
```

To configure this behaviour, first create a directory where Matterpuppeter will 
write code snippets to:

```
$ mkdir ~/pastes
```

Then, let an HTTP server serve files from that directory.  For example, when using 
nginx:

```
server {
    server_name paste.matterpuppeter;
    listen 80;
    root /home/_mp/pastes;

    location / {
        index index.html;
    }
}
```

This is a very minimal configuration, which may not be suitable in production, 
but it gives an overall idea of how things should be set up.  Also make sure that 
the `pastes` directory is readable by the user nginx runs as (typically `www-data`).

Finally, you can configure Matterpuppeter to make use of that directory:

```
paste:
  enable: true
  domain: "http://paste.matterpuppeter/"
  dir: "/home/_mp/pastes"
  maxlines: 5
```

Restart your HTTP server and Matterpuppeter, long code blocks should now be 
pastebinned!  You will need to set up cleaning up yourself at this point 
however, but this is left as an exercise to the reader.

### Identd

Matterpuppeter can integrate with an ident daemon for the purposes of identifying 
puppets.  It does this by writing to an *ident file*, which would then be read by 
your system's ident server (such as `oidentd`) and sent to the IRC server. After this 
is done Matterpuppeter clears the contents of the file.

To do this, your `/etc/oidentd.conf` file must allow the user Matterpuppeter runs as to 
spoof ident queries:

```
user "_mp" {
    default {
        allow spoof
        allow spoof_all
    }
}
```

Then create an `.oidentd.conf` file in the home directory of the Matterpuppeter user 
while logged in as that user, and make sure `oidentd` can read it:

```
$ touch ~/.oidentd.conf
$ chmod 644 ~/.oidentd.conf
$ chmod 711 ~
```

Finally, configure Matterpuppeter to write to that file:

```
<...>
ident:
  enable: true
  file: "/home/_mp/.oidentd.conf"
  format: "global { reply \"%user%\" }"
  username: "listener"
<...>
```

Then restart your ident daemon and Matterpuppeter, the puppets it creates should 
now be properly idented!

## TODO

* Possibly full puppeting support (as in, onboarding every single user joined on 
  the other side), probably not as default however
* sed-style (`s///`) or SMS-style edits
* Cleanup