signal backend, app cleanup
This commit is contained in:
parent
4b157ed1d1
commit
6f18890739
43 changed files with 695 additions and 124 deletions
54
app/signalbot/cli.py
Normal file
54
app/signalbot/cli.py
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import json
|
||||
import subprocess
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
BASE_CMD = ['signal-cli', '-a', settings.SIGNAL_ACCOUNT, '--output=json']
|
||||
|
||||
|
||||
def send(msg, to=None, group=None):
|
||||
cmd = BASE_CMD + [
|
||||
'send', '--message-from-stdin'
|
||||
]
|
||||
if group:
|
||||
cmd += ['-g', group]
|
||||
else:
|
||||
cmd += [to]
|
||||
r = subprocess.check_output(cmd, input=msg, encoding='utf-8')
|
||||
response = []
|
||||
if r:
|
||||
for row in r.strip().split('\n'):
|
||||
response.append(json.loads(row))
|
||||
return response
|
||||
|
||||
|
||||
def send_reaction(target_address, target_ts, emoji, to=None, group=None, remove=False):
|
||||
cmd = BASE_CMD + [
|
||||
'sendReaction', '-t', str(target_ts), '-e', emoji,
|
||||
'-a', target_address
|
||||
]
|
||||
if remove:
|
||||
cmd += ['-r']
|
||||
if group:
|
||||
cmd += ['-g', group]
|
||||
else:
|
||||
cmd += [to]
|
||||
r = subprocess.check_output(cmd, encoding='utf-8')
|
||||
response = []
|
||||
if r:
|
||||
for row in r.strip().split('\n'):
|
||||
response.append(json.loads(row))
|
||||
return response
|
||||
|
||||
|
||||
def receive(timeout=1):
|
||||
cmd = BASE_CMD + [
|
||||
'receive', '--timeout', str(timeout), '--send-read-receipts'
|
||||
]
|
||||
r = subprocess.check_output(cmd, encoding='utf-8')
|
||||
response = []
|
||||
if r:
|
||||
for row in r.strip().split('\n'):
|
||||
response.append(json.loads(row))
|
||||
return response
|
||||
Loading…
Add table
Add a link
Reference in a new issue