mirror of
https://github.com/chatmail/relay.git
synced 2026-05-19 20:38:05 +00:00
Compare commits
1 Commits
link2xt/fi
...
link2xt/st
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
21d105d41f |
@@ -18,14 +18,14 @@ hooks = events.HookCollection()
|
|||||||
@hooks.on(events.RawEvent)
|
@hooks.on(events.RawEvent)
|
||||||
def log_event(event):
|
def log_event(event):
|
||||||
if event.kind == EventType.INFO:
|
if event.kind == EventType.INFO:
|
||||||
logging.info("%s", event.msg)
|
logging.info(event.msg)
|
||||||
elif event.kind == EventType.WARNING:
|
elif event.kind == EventType.WARNING:
|
||||||
logging.warning("%s", event.msg)
|
logging.warning(event.msg)
|
||||||
|
|
||||||
|
|
||||||
@hooks.on(events.RawEvent(EventType.ERROR))
|
@hooks.on(events.RawEvent(EventType.ERROR))
|
||||||
def log_error(event):
|
def log_error(event):
|
||||||
logging.error("%s", event.msg)
|
logging.error(event.msg)
|
||||||
|
|
||||||
|
|
||||||
@hooks.on(events.MemberListChanged)
|
@hooks.on(events.MemberListChanged)
|
||||||
@@ -48,9 +48,6 @@ def on_group_name_changed(event):
|
|||||||
@hooks.on(events.NewMessage(func=lambda e: not e.command))
|
@hooks.on(events.NewMessage(func=lambda e: not e.command))
|
||||||
def echo(event):
|
def echo(event):
|
||||||
snapshot = event.message_snapshot
|
snapshot = event.message_snapshot
|
||||||
if snapshot.is_info:
|
|
||||||
# Ignore info messages
|
|
||||||
return
|
|
||||||
if snapshot.text or snapshot.file:
|
if snapshot.text or snapshot.file:
|
||||||
snapshot.chat.send_message(text=snapshot.text, file=snapshot.file)
|
snapshot.chat.send_message(text=snapshot.text, file=snapshot.file)
|
||||||
|
|
||||||
@@ -62,7 +59,6 @@ def help_command(event):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
logging.basicConfig(level=logging.INFO)
|
|
||||||
path = os.environ.get("PATH")
|
path = os.environ.get("PATH")
|
||||||
venv_path = sys.argv[0].strip("echobot")
|
venv_path = sys.argv[0].strip("echobot")
|
||||||
os.environ["PATH"] = path + ":" + venv_path
|
os.environ["PATH"] = path + ":" + venv_path
|
||||||
@@ -84,4 +80,5 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import pwd
|
import pwd
|
||||||
|
|
||||||
import pathlib
|
from pathlib import Path
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from socketserver import (
|
from socketserver import (
|
||||||
@@ -13,7 +13,6 @@ import sys
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
import marshal
|
|
||||||
|
|
||||||
|
|
||||||
DICTPROXY_LOOKUP_CHAR = "L"
|
DICTPROXY_LOOKUP_CHAR = "L"
|
||||||
@@ -29,33 +28,19 @@ class Notifier:
|
|||||||
self.metadata_dir = metadata_dir
|
self.metadata_dir = metadata_dir
|
||||||
self.to_notify_queue = Queue()
|
self.to_notify_queue = Queue()
|
||||||
|
|
||||||
def get_metadata(self, guid):
|
def set_token(self, guid, token):
|
||||||
guid_path = self.metadata_dir.joinpath(guid)
|
|
||||||
if guid_path.exists():
|
|
||||||
with guid_path.open("rb") as f:
|
|
||||||
return marshal.load(f)
|
|
||||||
return {}
|
|
||||||
|
|
||||||
def set_metadata(self, guid, guid_data):
|
|
||||||
guid_path = self.metadata_dir.joinpath(guid)
|
guid_path = self.metadata_dir.joinpath(guid)
|
||||||
write_path = guid_path.with_suffix(".tmp")
|
write_path = guid_path.with_suffix(".tmp")
|
||||||
with write_path.open("wb") as f:
|
write_path.write_text(token)
|
||||||
marshal.dump(guid_data, f)
|
write_path.rename(guid_path)
|
||||||
os.rename(write_path, guid_path)
|
|
||||||
|
|
||||||
def set_token(self, guid, token):
|
|
||||||
guid_data = self.get_metadata(guid)
|
|
||||||
guid_data["token"] = token
|
|
||||||
self.set_metadata(guid, guid_data)
|
|
||||||
|
|
||||||
def del_token(self, guid):
|
def del_token(self, guid):
|
||||||
guid_data = self.get_metadata(guid)
|
self.metadata_dir.joinpath(guid).unlink(missing_ok=True)
|
||||||
if "token" in guid_data:
|
|
||||||
del guid_data["token"]
|
|
||||||
self.set_metadata(guid, guid_data)
|
|
||||||
|
|
||||||
def get_token(self, guid):
|
def get_token(self, guid):
|
||||||
return self.get_metadata(guid).get("token")
|
guid_path = self.metadata_dir / guid
|
||||||
|
if guid_path.exists():
|
||||||
|
return guid_path.read_text()
|
||||||
|
|
||||||
def new_message_for_guid(self, guid):
|
def new_message_for_guid(self, guid):
|
||||||
self.to_notify_queue.put(guid)
|
self.to_notify_queue.put(guid)
|
||||||
@@ -151,7 +136,7 @@ def main():
|
|||||||
|
|
||||||
# XXX config is not currently used
|
# XXX config is not currently used
|
||||||
config = read_config(config)
|
config = read_config(config)
|
||||||
metadata_dir = pathlib.Path(metadata_dir)
|
metadata_dir = Path(metadata_dir)
|
||||||
if not metadata_dir.exists():
|
if not metadata_dir.exists():
|
||||||
metadata_dir.mkdir()
|
metadata_dir.mkdir()
|
||||||
notifier = Notifier(metadata_dir)
|
notifier = Notifier(metadata_dir)
|
||||||
|
|||||||
Reference in New Issue
Block a user