Skip to content

Instantly share code, notes, and snippets.

@jameshi16
Last active July 11, 2022 12:28
Show Gist options
  • Save jameshi16/71764cc0bac84adda717e9ddb0b44364 to your computer and use it in GitHub Desktop.
Save jameshi16/71764cc0bac84adda717e9ddb0b44364 to your computer and use it in GitHub Desktop.
[Mine] Supporting Gists for Signal bot blogpost
FROM ubuntu:latest
RUN apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y python3 python3-pip openjdk-18-jre coreutils curl wget libcairo2-dev libgirepository1.0-dev
WORKDIR /tmp
RUN curl -s https://api.github.com/repos/AsamK/signal-cli/releases/latest \
| grep "browser_download_url.*Linux.tar.gz\"$" \
| cut -d : -f 2,3 \
| tr -d \" \
| grep ".gz$" \
| wget -qi -
RUN mkdir -p /opt/cli && mkdir -p /opt/bot && tar xvf *.tar.gz -C /opt/cli && mv /opt/cli/signal* /opt/cli/signal
WORKDIR /opt/bot
RUN pip install pydbus PyGObject
#!/usr/bin/python3
# (c)2017 mh-g
# (c)2021 jameshi16
def msgRcv (timestamp, source, groupID, message, attachments):
print ("msgRcv called")
print (message)
return
from pydbus import SessionBus
from gi.repository import GLib
bus = SessionBus()
loop = GLib.MainLoop()
signal = bus.get('org.asamk.Signal', '/org/asamk/Signal')
signal.onMessageReceived = msgRcv
loop.run()
!/usr/bin/python3
# Does 8-ball things
import random
responses = ['It is Certain.', 'It is decidedly so.', 'Without a doubt.', 'Yes definitely.', 'You may rely on it.', 'As I see it, yes.', 'Most likely.', 'Outlook good.', 'Yes.', 'Signs point to yes.', 'Reply hazy, try again.', 'Ask again later.', 'Better not tell you now.', 'Cannot predict now.', 'Concentrate and ask again.', 'Don\'t count on it.', 'My reply is no.', 'My sources say no.', 'Outlook not so good.', 'Very doubtful.']
def msgRcv (timestamp, sender, groupID, message, attachments):
if len(message) > 0 and message[0] == '/':
if '8ball' in message[1:]:
signal.sendGroupMessage('8ball: ' + random.choice(responses), [], groupID)
return
def syncMsgRcv(timestamp, source, destination, groupID, message, attachments):
msgRcv(timestamp, source, groupID, message, attachments)
return
from pydbus import SessionBus
from gi.repository import GLib
bus = SessionBus()
loop = GLib.MainLoop()
signal = bus.get('org.asamk.Signal', '/org/asamk/Signal')
signal.onSyncMessageReceived = syncMsgRcv
signal.onMessageReceived = msgRcv
loop.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment