Compare commits

7 Commits

Author SHA1 Message Date
ea56f82f51 Use notify for systemd 2021-06-13 21:19:22 +09:00
9aceae2317 Initial Systemd services 2021-06-13 21:19:22 +09:00
0d849cf2bb JSON stringify objects before logging them
Because Eclipse/Wild Web Developer messes them up
2021-06-10 02:52:25 -04:00
e37a7c41bf Minor formatting changes 2021-06-10 02:52:13 -04:00
1cf840e3d9 maunium -> miscworks 2021-06-10 02:51:23 -04:00
02cc6ce0e4 Add missing await 2021-06-10 02:19:24 -04:00
d8b209b04f Send delivery receipts for double-puppeted messages 2021-06-10 02:19:12 -04:00
10 changed files with 81 additions and 15 deletions

View File

@@ -45,7 +45,7 @@ appservice:
# Display name and avatar for bot. Set to "remove" to remove display name/avatar, leave empty # Display name and avatar for bot. Set to "remove" to remove display name/avatar, leave empty
# to leave display name/avatar as-is. # to leave display name/avatar as-is.
bot_displayname: LINE bridge bot bot_displayname: LINE bridge bot
bot_avatar: mxc://maunium.net/VuvevQiMRlOxuBVMBNEZZrxi bot_avatar: mxc://miscworks.net/uyHgFSLDDtATVGjtjWKwxrkK
# Community ID for bridged users (changes registration file) and rooms. # Community ID for bridged users (changes registration file) and rooms.
# Must be created manually. # Must be created manually.

View File

@@ -132,6 +132,7 @@ class Portal(DBPortal, BasePortal):
elif ((message.get(self.bridge.real_user_content_key, elif ((message.get(self.bridge.real_user_content_key,
False) and await p.Puppet.get_by_custom_mxid(sender.mxid))): False) and await p.Puppet.get_by_custom_mxid(sender.mxid))):
self.log.debug(f"Ignoring puppet-sent message by confirmed puppet user {sender.mxid}") self.log.debug(f"Ignoring puppet-sent message by confirmed puppet user {sender.mxid}")
await self._send_delivery_receipt(event_id)
return return
# TODO deduplication of outgoing messages # TODO deduplication of outgoing messages
text = message.body text = message.body
@@ -232,7 +233,7 @@ class Portal(DBPortal, BasePortal):
self.log.warning(f"Could not find ID of LINE user who sent event {evt.id}") self.log.warning(f"Could not find ID of LINE user who sent event {evt.id}")
sender = await p.Puppet.get_by_profile(evt.sender, source.client) sender = await p.Puppet.get_by_profile(evt.sender, source.client)
intent = sender.intent intent = sender.intent
intent.ensure_joined(self.mxid) await intent.ensure_joined(self.mxid)
if evt.image and evt.image.url: if evt.image and evt.image.url:
if not evt.image.is_sticker or self.config["bridge.receive_stickers"]: if not evt.image.is_sticker or self.config["bridge.receive_stickers"]:
@@ -562,7 +563,7 @@ class Portal(DBPortal, BasePortal):
@property @property
def bridge_info_state_key(self) -> str: def bridge_info_state_key(self) -> str:
return f"net.maunium.line://line/{self.chat_id}" return f"net.miscworks.line://line/{self.chat_id}"
@property @property
def bridge_info(self) -> Dict[str, Any]: def bridge_info(self) -> Dict[str, Any]:

View File

@@ -64,8 +64,8 @@ class ProvisioningAPI:
return None return None
for part in auth_parts: for part in auth_parts:
part = part.strip() part = part.strip()
if part.startswith("net.maunium.line.auth-"): if part.startswith("net.miscworks.line.auth-"):
return part[len("net.maunium.line.auth-"):] return part[len("net.miscworks.line.auth-"):]
return None return None
def check_token(self, request: web.Request) -> Awaitable['u.User']: def check_token(self, request: web.Request) -> Awaitable['u.User']:
@@ -107,7 +107,7 @@ class ProvisioningAPI:
if status.is_logged_in: if status.is_logged_in:
raise web.HTTPConflict(text='{"error": "Already logged in"}', headers=self._headers) raise web.HTTPConflict(text='{"error": "Already logged in"}', headers=self._headers)
ws = web.WebSocketResponse(protocols=["net.maunium.line.login"]) ws = web.WebSocketResponse(protocols=["net.miscworks.line.login"])
await ws.prepare(request) await ws.prepare(request)
try: try:
async for url in user.client.login(): async for url in user.client.login():

View File

@@ -20,6 +20,7 @@
"dependencies": { "dependencies": {
"arg": "^4.1.3", "arg": "^4.1.3",
"chrono-node": "^2.1.7", "chrono-node": "^2.1.7",
"systemd-daemon": "^1.1.2",
"puppeteer": "5.5.0" "puppeteer": "5.5.0"
}, },
"devDependencies": { "devDependencies": {

View File

@@ -15,6 +15,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import process from "process" import process from "process"
import fs from "fs" import fs from "fs"
import sd from "systemd-daemon"
import arg from "arg" import arg from "arg"
@@ -55,6 +56,7 @@ function stop() {
api.start().then(() => { api.start().then(() => {
process.once("SIGINT", stop) process.once("SIGINT", stop)
process.once("SIGTERM", stop) process.once("SIGTERM", stop)
sd.notify("READY=1")
}, err => { }, err => {
console.error("[Main] Error starting:", err) console.error("[Main] Error starting:", err)
process.exit(2) process.exit(2)

View File

@@ -409,7 +409,7 @@ export default class MessagesPuppeteer {
this.mostRecentMessages.set(chatID, messageID) this.mostRecentMessages.set(chatID, messageID)
} }
this.log("Updated most recent message ID map:") this.log("Updated most recent message ID map:")
this.log(this.mostRecentMessages) this.log(JSON.stringify(this.mostRecentMessages))
} }
async readImage(imageUrl) { async readImage(imageUrl) {
@@ -500,8 +500,7 @@ export default class MessagesPuppeteer {
} }
async _getChatInfoUnsafe(chatID) { async _getChatInfoUnsafe(chatID) {
const chatListItem = await this.page.$(this._listItemSelector(chatID)) const chatListInfo = await this.page.$eval(this._listItemSelector(chatID),
const chatListInfo = await chatListItem.evaluate(
(element, chatID) => window.__mautrixController.parseChatListItem(element, chatID), (element, chatID) => window.__mautrixController.parseChatListItem(element, chatID),
chatID) chatID)
@@ -520,12 +519,12 @@ export default class MessagesPuppeteer {
let participants let participants
if (!isDirect) { if (!isDirect) {
this.log("Found multi-user chat, so clicking chat header to get participants") this.log("Found multi-user chat, so viewing it to get participants")
// TODO This will mark the chat as "read"! // TODO This will mark the chat as "read"!
await this._switchChat(chatID) await this._switchChat(chatID)
const participantList = await this.page.$("#_chat_detail_area > .mdRGT02Info ul.mdRGT13Ul") const participantList = await this.page.$("#_chat_detail_area > .mdRGT02Info ul.mdRGT13Ul")
// TODO Is a group not actually created until a message is sent(?) // TODO Is a group not actually created until a message is sent(?)
// If so, maybe don't create a portal until there is a message. // If so, maybe don't create a portal until there is a message.
participants = await participantList.evaluate( participants = await participantList.evaluate(
element => window.__mautrixController.parseParticipantList(element)) element => window.__mautrixController.parseParticipantList(element))
} else { } else {
@@ -541,15 +540,15 @@ export default class MessagesPuppeteer {
this.log("Found participants:") this.log("Found participants:")
for (const participant of participants) { for (const participant of participants) {
this.log(participant) this.log(JSON.stringify(participant))
} }
return {participants, ...chatListInfo} return {participants, ...chatListInfo}
} }
// TODO Catch "An error has occurred" dialog // TODO Catch "An error has occurred" dialog
// Selector is just "dialog", then "button" // Selector is just "dialog", then "button"
// Child of "#layer_contents" // Child of "#layer_contents"
// Always present, just made visible via classes // Always present, just made visible via classes
async _sendMessageUnsafe(chatID, text) { async _sendMessageUnsafe(chatID, text) {
await this._switchChat(chatID) await this._switchChat(chatID)

View File

@@ -226,6 +226,13 @@ base64-js@^1.0.2:
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.1.tgz#58ece8cb75dd07e71ed08c736abc5fac4dbf8df1" resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.1.tgz#58ece8cb75dd07e71ed08c736abc5fac4dbf8df1"
integrity sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g== integrity sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==
bindings@^1.3.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df"
integrity sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==
dependencies:
file-uri-to-path "1.0.0"
bl@^4.0.1: bl@^4.0.1:
version "4.0.2" version "4.0.2"
resolved "https://registry.yarnpkg.com/bl/-/bl-4.0.2.tgz#52b71e9088515d0606d9dd9cc7aa48dc1f98e73a" resolved "https://registry.yarnpkg.com/bl/-/bl-4.0.2.tgz#52b71e9088515d0606d9dd9cc7aa48dc1f98e73a"
@@ -621,6 +628,11 @@ file-entry-cache@^5.0.1:
dependencies: dependencies:
flat-cache "^2.0.1" flat-cache "^2.0.1"
file-uri-to-path@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd"
integrity sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==
find-up@^2.0.0, find-up@^2.1.0: find-up@^2.0.0, find-up@^2.1.0:
version "2.1.0" version "2.1.0"
resolved "https://registry.yarnpkg.com/find-up/-/find-up-2.1.0.tgz#45d1b7e506c717ddd482775a2b77920a3c0c57a7" resolved "https://registry.yarnpkg.com/find-up/-/find-up-2.1.0.tgz#45d1b7e506c717ddd482775a2b77920a3c0c57a7"
@@ -952,6 +964,11 @@ ms@^2.1.1:
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
nan@^2.13.2:
version "2.14.2"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.2.tgz#f5376400695168f4cc694ac9393d0c9585eeea19"
integrity sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ==
natural-compare@^1.4.0: natural-compare@^1.4.0:
version "1.4.0" version "1.4.0"
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
@@ -1374,6 +1391,13 @@ supports-color@^7.1.0:
dependencies: dependencies:
has-flag "^4.0.0" has-flag "^4.0.0"
systemd-daemon@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/systemd-daemon/-/systemd-daemon-1.1.2.tgz#63171f4353e0f96ef2d2257a5e6258cb89136cc3"
integrity sha512-1s3JH5W78WYQI6iAQdsgoz9LMO5Sj5OtanjeNopJ15iX2q6QupRvkG5SQPJIj+YN3IgUMqPbtzfWxweCVKe28g==
optionalDependencies:
unix-dgram "^2.0.2"
table@^5.2.3: table@^5.2.3:
version "5.4.6" version "5.4.6"
resolved "https://registry.yarnpkg.com/table/-/table-5.4.6.tgz#1292d19500ce3f86053b05f0e8e7e4a3bb21079e" resolved "https://registry.yarnpkg.com/table/-/table-5.4.6.tgz#1292d19500ce3f86053b05f0e8e7e4a3bb21079e"
@@ -1450,6 +1474,14 @@ unbzip2-stream@^1.3.3:
buffer "^5.2.1" buffer "^5.2.1"
through "^2.3.8" through "^2.3.8"
unix-dgram@^2.0.2:
version "2.0.4"
resolved "https://registry.yarnpkg.com/unix-dgram/-/unix-dgram-2.0.4.tgz#14d4fc21e539742b8fb027de16eccd4e5503a344"
integrity sha512-7tpK6x7ls7J7pDrrAU63h93R0dVhRbPwiRRCawR10cl+2e1VOvF3bHlVJc6WI1dl/8qk5He673QU+Ogv7bPNaw==
dependencies:
bindings "^1.3.0"
nan "^2.13.2"
uri-js@^4.2.2: uri-js@^4.2.2:
version "4.2.2" version "4.2.2"
resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.2.2.tgz#94c540e1ff772956e2299507c010aea6c8838eb0" resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.2.2.tgz#94c540e1ff772956e2299507c010aea6c8838eb0"

View File

@@ -0,0 +1,13 @@
[Unit]
Description=Matrix-puppeteer-line Chrome backend
PartOf=matrix-puppeteer-line-chrome.target
[Service]
; User=matrix
Type=notify
NotifyAccess=all
WorkingDirectory=/opt/synapse/bridges/matrix-puppeteer-line/puppet
ExecStart=/bin/xvfb-run /usr/bin/node src/main.js
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,6 @@
[Unit]
Description=Matrix puppeteer line bridge target
Requires=multi-user.target network.target
After=multi-user.target network.target
BindsTo=matrix-puppeteer-line-chrome.service
PartOf=matrix-puppeteer-line.service

View File

@@ -0,0 +1,12 @@
[Unit]
Description=Matrix-puppeteer-line bridge
Requires=matrix-puppeteer-line-chrome.target
After=matrix-puppeteer-line-chrome.target
[Service]
; User=matrix
WorkingDirectory=/opt/synapse/bridges/matrix-puppeteer-line
ExecStart=/opt/synapse/bridges/matrix-puppeteer-line/.venv/bin/python -m matrix_puppeteer_line
[Install]
WantedBy=multi-user.target