signal backend, app cleanup
This commit is contained in:
parent
4b157ed1d1
commit
6f18890739
43 changed files with 695 additions and 124 deletions
41
app/signalbot/daemon.py
Normal file
41
app/signalbot/daemon.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import subprocess
|
||||
import json
|
||||
from django.conf import settings
|
||||
from django.utils import timezone
|
||||
|
||||
from . import cli
|
||||
from . import rpc
|
||||
|
||||
|
||||
def main():
|
||||
cmd = cli.BASE_CMD + [
|
||||
'daemon', '--http', '--send-read-receipts'
|
||||
]
|
||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, bufsize=1, universal_newlines=True, start_new_session=True)
|
||||
try:
|
||||
for line in p.stdout:
|
||||
try:
|
||||
msg = json.loads(line)
|
||||
except:
|
||||
if settings.DEBUG:
|
||||
print(">>", line)
|
||||
continue
|
||||
if settings.DEBUG:
|
||||
print('==', msg)
|
||||
source = msg.get('envelope', {}).get('sourceNumber')
|
||||
reaction = msg.get('envelope', {}).get('dataMessage', {}).get('reaction', {})
|
||||
emoji = reaction.get('emoji')
|
||||
target_author = reaction.get('targetAuthorNumber')
|
||||
target_ts = reaction.get('targetSentTimestamp')
|
||||
group = msg.get('envelope', {}).get('dataMessage', {}).get("groupInfo", {}).get("groupId")
|
||||
if group == settings.SIGNAL_MODERATORS_GROUP:
|
||||
if emoji == "👍" and target_author == settings.SIGNAL_ACCOUNT:
|
||||
if source in settings.SIGNAL_MODERATORS:
|
||||
from ..item import models
|
||||
now = timezone.now()
|
||||
models.Comment.objects.filter(data__moderator_ts=target_ts).update(published=now)
|
||||
rpc.send_reaction(target_author, target_ts, "🎉", group=group)
|
||||
else:
|
||||
rpc.send("Ignoring your request, you are not a moderator", group=group)
|
||||
except:
|
||||
p.kill()
|
||||
Loading…
Add table
Add a link
Reference in a new issue