diff options
| author | Mistivia <i@mistivia.com> | 2025-11-02 15:27:18 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-11-02 15:27:18 +0800 |
| commit | e9c24f4af7ed56760f6db7941827d09f6db9020b (patch) | |
| tree | 62128c43b883ce5e3148113350978755779bb5de /teleirc/matterbridge/contrib | |
| parent | 58d5e7cfda4781d8a57ec52aefd02983835c301a (diff) | |
add matterbridge
Diffstat (limited to 'teleirc/matterbridge/contrib')
10 files changed, 313 insertions, 0 deletions
diff --git a/teleirc/matterbridge/contrib/api.yaml b/teleirc/matterbridge/contrib/api.yaml new file mode 100644 index 0000000..328393f --- /dev/null +++ b/teleirc/matterbridge/contrib/api.yaml @@ -0,0 +1,210 @@ +openapi: 3.0.0 +info: + contact: {} + description: A read/write API for the Matterbridge chat bridge. + license: + name: Apache 2.0 + url: 'https://github.com/42wim/matterbridge/blob/master/LICENSE' + title: Matterbridge API + version: "0.1.0-oas3" +paths: + /health: + get: + responses: + '200': + description: OK + content: + '*/*': + schema: + type: string + summary: Checks if the server is alive. + /message: + post: + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/config.OutgoingMessageResponse' + summary: Create a message + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/config.OutgoingMessage' + description: Message object to create + required: true + /messages: + get: + responses: + '200': + description: OK + content: + application/json: + schema: + items: + $ref: '#/components/schemas/config.IncomingMessage' + type: array + security: + - ApiKeyAuth: [] + summary: List new messages + /stream: + get: + responses: + '200': + description: OK + content: + application/x-json-stream: + schema: + $ref: '#/components/schemas/config.IncomingMessage' + summary: Stream realtime messages +servers: + - url: /api +components: + securitySchemes: + bearerAuth: + type: http + scheme: bearer + schemas: + config.IncomingMessage: + properties: + avatar: + description: URL to an avatar image + example: >- + https://secure.gravatar.com/avatar/1234567890abcdef1234567890abcdef.jpg + type: string + event: + description: >- + A specific matterbridge event. (see + https://github.com/42wim/matterbridge/blob/master/bridge/config/config.go#L16) + type: string + gateway: + description: Name of the gateway as configured in matterbridge.toml + example: mygateway + type: string + text: + description: Content of the message + example: 'Testing, testing, 1-2-3.' + type: string + username: + description: Human-readable username + example: alice + type: string + account: + description: Unique account name of format "[protocol].[slug]" as defined in matterbridge.toml + example: slack.myteam + type: string + channel: + description: Human-readable channel name of sending bridge + example: test-channel + type: string + id: + description: Unique ID of message on the gateway + example: slack 1541361213.030700 + type: string + parent_id: + description: Unique ID of a parent message, if threaded + example: slack 1541361213.030700 + type: string + protocol: + description: Chat protocol of the sending bridge + example: slack + type: string + timestamp: + description: Timestamp of the message + example: "1541361213.030700" + type: string + userid: + description: Userid on the sending bridge + example: U4MCXJKNC + type: string + extra: + description: Extra data that doesn't fit in other fields (eg base64 encoded files) + type: object + config.OutgoingMessage: + properties: + avatar: + description: URL to an avatar image + example: >- + https://secure.gravatar.com/avatar/1234567890abcdef1234567890abcdef.jpg + type: string + event: + description: >- + A specific matterbridge event. (see + https://github.com/42wim/matterbridge/blob/master/bridge/config/config.go#L16) + example: "" + type: string + gateway: + description: Name of the gateway as configured in matterbridge.toml + example: mygateway + type: string + text: + description: Content of the message + example: 'Testing, testing, 1-2-3.' + type: string + username: + description: Human-readable username + example: alice + type: string + type: object + required: + - gateway + - text + - username + config.OutgoingMessageResponse: + properties: + avatar: + description: URL to an avatar image + example: >- + https://secure.gravatar.com/avatar/1234567890abcdef1234567890abcdef.jpg + type: string + event: + description: >- + A specific matterbridge event. (see + https://github.com/42wim/matterbridge/blob/master/bridge/config/config.go#L16) + example: "" + type: string + gateway: + description: Name of the gateway as configured in matterbridge.toml + example: mygateway + type: string + text: + description: Content of the message + example: 'Testing, testing, 1-2-3.' + type: string + username: + description: Human-readable username + example: alice + type: string + account: + description: fixed api account + example: api.local + type: string + channel: + description: fixed api channel + example: api + type: string + id: + example: "" + type: string + parent_id: + example: "" + type: string + protocol: + description: fixed api protocol + example: api + type: string + timestamp: + description: Timestamp of the message + example: "1541361213.030700" + type: string + userid: + example: "" + type: string + extra: + example: null + type: object + type: object +security: + - bearerAuth: [] diff --git a/teleirc/matterbridge/contrib/example.tengo b/teleirc/matterbridge/contrib/example.tengo new file mode 100644 index 0000000..da4eede --- /dev/null +++ b/teleirc/matterbridge/contrib/example.tengo @@ -0,0 +1,2 @@ +text := import("text") +msgText=text.re_replace("matterbridge",msgText,"matterbridge (https://github.com/42wim/matterbridge)") diff --git a/teleirc/matterbridge/contrib/inmessage-logger.tengo b/teleirc/matterbridge/contrib/inmessage-logger.tengo new file mode 100644 index 0000000..13db04d --- /dev/null +++ b/teleirc/matterbridge/contrib/inmessage-logger.tengo @@ -0,0 +1,15 @@ +fmt := import("fmt") +os := import("os") +times := import("times") + +if msgText != "" && msgUsername != "system" { + os.chdir("/var/www/matterbridge") + file := os.open_file("inmessage.log", os.o_append|os.o_wronly|os.o_create, 0644) + file.write_string(fmt.sprintf( + "[%s] <%s> %s\n", + times.time_format(times.now(), times.format_rfc1123), + msgUsername, + msgText + )) + file.close() +} diff --git a/teleirc/matterbridge/contrib/matterbridge.openrc b/teleirc/matterbridge/contrib/matterbridge.openrc new file mode 100755 index 0000000..a3e188f --- /dev/null +++ b/teleirc/matterbridge/contrib/matterbridge.openrc @@ -0,0 +1,19 @@ +#!/sbin/openrc-run +# Copyright 2021-2022 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +command=/usr/bin/matterbridge +command_args="-conf ${MATTERBRIDGE_CONF:-/etc/matterbridge/bridge.toml} ${MATTERBRIDGE_ARGS}" +command_user="matterbridge:matterbridge" +pidfile="/run/${RC_SVCNAME}.pid" +command_background=1 +output_log="/var/log/${RC_SVCNAME}.log" +error_log="${output_log}" + +depend() { + need net +} + +start_pre() { + checkpath -f "${output_log}" -o "${command_user}" || return 1 +} diff --git a/teleirc/matterbridge/contrib/matterbridge.service b/teleirc/matterbridge/contrib/matterbridge.service new file mode 100644 index 0000000..6ae1aa4 --- /dev/null +++ b/teleirc/matterbridge/contrib/matterbridge.service @@ -0,0 +1,11 @@ +[Unit] +Description=matterbridge +After=network.target + +[Service] +ExecStart=/usr/bin/matterbridge -conf /etc/matterbridge/bridge.toml +User=matterbridge +Group=matterbridge + +[Install] +WantedBy=multi-user.target diff --git a/teleirc/matterbridge/contrib/outmessage-discordemoji.tengo b/teleirc/matterbridge/contrib/outmessage-discordemoji.tengo new file mode 100644 index 0000000..3dd61ad --- /dev/null +++ b/teleirc/matterbridge/contrib/outmessage-discordemoji.tengo @@ -0,0 +1,10 @@ +text := import("text") + +// if we're not sending to a discord bridge, +// then convert custom emoji tags into url's +if (inProtocol == "discord" && outProtocol != "discord") { + rePNG := text.re_compile(`<:.*?:([0-9]+)>`) + msgText=rePNG.replace(msgText,"https://cdn.discordapp.com/emojis/$1.png") + reGIF := text.re_compile(`<a:.*?:([0-9]+)>`) + msgText=reGIF.replace(msgText,"https://cdn.discordapp.com/emojis/$1.gif") +} diff --git a/teleirc/matterbridge/contrib/outmessage-irccolornick.tengo b/teleirc/matterbridge/contrib/outmessage-irccolornick.tengo new file mode 100644 index 0000000..a16ab64 --- /dev/null +++ b/teleirc/matterbridge/contrib/outmessage-irccolornick.tengo @@ -0,0 +1,14 @@ +// See https://github.com/42wim/matterbridge/issues/881 +// Generates a colored nick for each msgUsername, with example to filter specific codes + +text := import("text") +fmt := import("fmt") +if outProtocol == "irc" { + // generate a color for a nick, make sure it isn't 0 or 15 + colorCode := len(msgUsername)+bytes(msgUsername)[0]%14 + 2 + // example if we want to use colorCode 3 when we have calculated colorcode 14 + if colorCode == 14 { + colorCode = 3 + } + msgUsername=fmt.sprintf("\x03%02d%s\x0F", colorCode, msgUsername) +} diff --git a/teleirc/matterbridge/contrib/outmessage-irccolors.tengo b/teleirc/matterbridge/contrib/outmessage-irccolors.tengo new file mode 100644 index 0000000..fe63da4 --- /dev/null +++ b/teleirc/matterbridge/contrib/outmessage-irccolors.tengo @@ -0,0 +1,7 @@ +// See https://github.com/42wim/matterbridge/issues/798 + +// if we're not sending to an irc bridge we strip the IRC colors +if outProtocol != "irc" { + re := text.re_compile(`\x03(?:\d{1,2}(?:,\d{1,2})?)?|[[:cntrl:]]`) + msgText=re.replace(msgText,"") +} diff --git a/teleirc/matterbridge/contrib/remotenickformat-zerowidth.tengo b/teleirc/matterbridge/contrib/remotenickformat-zerowidth.tengo new file mode 100644 index 0000000..8d1d065 --- /dev/null +++ b/teleirc/matterbridge/contrib/remotenickformat-zerowidth.tengo @@ -0,0 +1,16 @@ +/* +This script will return the nick except with multi-character usernames +containing a zero-width space between the first and second character letter. + +Single character usernames will be left untouched. + +This is useful to prevent remote users from nickalerting +IRC users of the same name when the remote user speaks. + +This result can be used in {TENGO} in RemoteNickFormat. +*/ + +result = nick +if len(nick) > 1 { + result = string(nick[0]) + "" + nick[1:] +} diff --git a/teleirc/matterbridge/contrib/remotenickformat.tengo b/teleirc/matterbridge/contrib/remotenickformat.tengo new file mode 100644 index 0000000..2ca856e --- /dev/null +++ b/teleirc/matterbridge/contrib/remotenickformat.tengo @@ -0,0 +1,9 @@ +/* +This script will return the current time in kitchen format if the protocol (of the remote bridge) isn't irc +See https://github.com/d5/tengo/blob/master/docs/stdlib-times.md +This result can be used in {TENGO} in RemoteNickFormat +*/ +times := import("times") +if protocol != "irc" { + result=times.time_format(times.now(),times.format_kitchen) +} |
