# Semaphore
[![PyPI](https://img.shields.io/pypi/v/semaphore-bot)](https://pypi.org/project/semaphore-bot/)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/lwesterhof/semaphore/python.yml)](https://github.com/lwesterhof/semaphore/actions)
[![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/lwesterhof/semaphore)](https://github.com/lwesterhof/semaphore/tags)
[![License](https://img.shields.io/github/license/lwesterhof/semaphore)](https://github.com/lwesterhof/semaphore/blob/main/LICENSE.txt)
A simple (rule-based) bot library for [Signal](https://signal.org/) Private Messenger in Python.
Please note that this library is unofficial, unapproved and not nearly as secure as the real Signal clients.
## Table of contents
* [Requirements](#requirements)
* [Installation](#installation)
* [Quick start](#quick-start)
* [Code example](#code-example)
* [Example bots](#example-bots)
* [Changelog](#changelog)
* [License](#license)
## Requirements
- ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/semaphore-bot)
- [signald](https://gitlab.com/signald/signald) [0.23.0](https://gitlab.com/signald/signald/-/tags) or later, a daemon that facilitates communication over [Signal](https://signal.org/)
## Installation
1. Install signald or build from source
```bash
$ git clone https://gitlab.com/signald/signald.git
$ cd signald
$ make installDist
$ make setup
```
2. Install Semaphore
Latest release from PyPi:
```bash
$ pip install semaphore-bot
```
From source with pip:
```bash
$ pip install git+https://github.com/lwesterhof/semaphore.git
```
From source:
```bash
$ git clone https://github.com/lwesterhof/semaphore.git
$ cd semaphore
$ make build
$ make install
```
## Quick start
1. Start signald
```bash
$ cd signald
$ build/install/signald/bin/signald
```
2. Open a new terminal and connect to signald control socket
```bash
$ nc -U $XDG_RUNTIME_DIR/signald/signald.sock
```
(or `/var/run/signald/signald.sock` for older versions of signald, [see signald docs](https://signald.org/articles/protocol/#socket-file-location))
3. Register phone number with Signal by sending following message on the control socket (replace `+xxxxxxxxxxx` with bot Signal number). Sometimes Signal requires completion of a [captcha](https://signald.org/articles/captcha/) to register.
```json
{"type": "register", "version": "v1", "account": "+xxxxxxxxxxx"}
```
4. Verify phone number with SMS verification code by sending following message on the control socket (replace `+xxxxxxxxxxx` with bot Signal number and `zzzzzz` with verification code)
```json
{"type": "verify", "version": "v1", "account": "+xxxxxxxxxxx", "code": "zzzzzz"}
```
5. Verify Signal is working by sending following message on the control socket (replace `+xxxxxxxxxxx` with bot Signal number and `+yyyyyyyyyyy` with your Signal number)
```json
{"type": "send", "version": "v1", "username": "+xxxxxxxxxxx", "recipientAddress": {"number": "+yyyyyyyyyyy"}, "messageBody": "Hello world"}
```
6. Open a new terminal and set the `SIGNAL_PHONE_NUMBER` environment variable to your phone number:
```bash
$ export SIGNAL_PHONE_NUMBER=+xxxxxxxxxxx
```
7. Start the example echo bot
```bash
$ python examples/echobot.py
```
8. Send message to Signal bot running on `+xxxxxxxxxxx` and wait for an echo
9. Now you can start writing your own bot for [Signal](https://signal.org/) Private Messenger!
## Code example
```python
import anyio
from semaphore import Bot, ChatContext
# Connect the bot to number.
bot = Bot("+xxxxxxxxxxx")
@bot.handler('')
async def echo(ctx: ChatContext) -> None:
await ctx.message.reply(ctx.message.get_body())
async def main():
async with bot:
# Set profile name.
await bot.set_profile("Semaphore example bot")
# Run the bot until you press Ctrl-C.
await bot.start()
anyio.run(main)
```
## Example bots
The following example bots can be found in [examples](examples):
- [apodbot](examples/apodbot.py), replies with Astronomy Picture of the Day
- [bbcbot](examples/bbcbot.py), replies with latest BBC headlines
- [broadcastbot](examples/broadcastbot.py), send broadcast to all subscribers
- [btcbot](examples/btcbot.py), sends notification when BTC price drops below a set price
- [echobot](examples/echobot.py), repeats received messages
- [exceptionbot](examples/exceptionbot.py), with custom exception handler
- [expirationbot](examples/expirationbot.py), sets the message expiration timer for a chat to random value
- [lovebot](examples/lovebot.py), loves everything you say!
- [profilebot](examples/profilebot.py), retrieves profile for personal touch
- [quotebot](examples/quotebot.py), quotes and repeats received messages
- [spongebot](examples/spongebot.py), repeats received messages in sPOngEbOb sqUArepAnTs text
- [stickerbot](examples/stickerbot.py), links to the sticker pack for received stickers
- [timerbot](examples/timerbot.py), sends an alert after a predefined time
- [xkcdbot](examples/xkcdbot.py), replies with latest XKCD comic
## Changelog
**v0.16.0**
* Compatibility with signald 0.23.0+
* Add method to retrieve profile of message sender
**v0.15.0**
* Compatibility with signald 0.22.0+
* Add option to automatically accept group invites
**v0.14.0**
* Compatibility with signald 0.18.0+
* Migrate to latest version of anyio (3.5.0)
* Add Dockerfile to run Signal bot in container
* Add support for link previews (thanks @Era-Dorta)
**v0.13.0**
* Compatibility with signald 0.17.0+
* Add method to set expiration timer of chat (thanks @Era-Dorta)
* Example expiration timer bot
**v0.12.0**
* Compatibility with signald 0.15.0+
* Add support for emoji and about to in profile (thanks @EsEnZeT)
* Add option to throw signals errors on send (thanks @eknoes)
**v0.11.0**
* Compatibility with signald 0.14.0+ (signald protocol v1)
* Add support for waiting on signald send confirmation (thanks @eknoes)
* Add support for sending messages to groups (thanks @brazuzan)
**v0.10.1**
* Add method to set profile name and profile picture
* Store e164 phone number and uuid for received messages
**v0.10.0**
* Add support for sending messages without previous context (thanks @eknoes)
* Add support for exception handlers (thanks @eknoes)
* Add ability to set profile picture (thanks @eknoes)
* Support signald client protocol v1
* Compatibility with signald 0.12.0+
**v0.9.1**
* Fix repeating job re-add to queue (thanks @grandchild)
**v0.9.0**
* Support for typing indicators
* Support for GroupsV2 (thanks @thefinn93)
* Example sticker bot (thanks @iomintz)
* Compatibility with signald 0.11.0+
**v0.8.0**
* Support for Python 3.9
* Support for executing multiple handlers in parallel (thanks @iomintz)
* Support incoming sticker messages (thanks @iomintz)
**v0.7.1**
* Support for decorators to register handlers
* Support for sending delivery receipts
* Mark messages as read by default
**v0.7.0**
* Compatibility with signald 0.10.0+
* Support for multiple replies/reactions by handler (thanks @iomintz)
* Marking messages as read is optional
* First release on PyPi
**v0.6.0**
* Support for message reactions
* Example message reaction bot
**v0.5.0**
* Improve the logging system
* Add logging to job queue
* Strict typing
**v0.4.0**
* Support for recurring jobs
* Example BTC price notification bot
**v0.3.0**
* Support for scheduled jobs
* Example timer bot
**v0.2.0**
* Support for quoting messages
* Example quote bot
**v0.1.0**
* First release on Github
## License
This project is licensed under the AGPL-v3 license.
The full license can be found in [LICENSE.txt](LICENSE.txt).
没有合适的资源?快使用搜索试试~ 我知道了~
SignalPrivateMessenger的简单(基于规则)机器人库。_Python_Makefile_下载.zip
共77个文件
py:39个
rst:22个
yml:6个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 82 浏览量
2023-04-26
11:32:19
上传
评论
收藏 77KB ZIP 举报
温馨提示
SignalPrivateMessenger的简单(基于规则)机器人库。_Python_Makefile_下载.zip
资源推荐
资源详情
资源评论
收起资源包目录
SignalPrivateMessenger的简单(基于规则)机器人库。_Python_Makefile_下载.zip (77个子文件)
semaphore-main
setup.py 2KB
.github
workflows
documentation.yml 687B
python.yml 1006B
docker.yml 292B
codeql-analysis.yml 2KB
FUNDING.yml 35B
LICENSE.txt 34KB
Makefile 1KB
docker
bot.py 2KB
docker-compose.yml 421B
Dockerfile 278B
README.md 2KB
examples
quotebot.py 1KB
xkcdbot.py 2KB
timerbot.py 3KB
apodbot.py 2KB
tmp
.gitignore 71B
profilebot.py 1KB
btcbot.py 3KB
echobot.py 1KB
exceptionbot.py 2KB
bbcbot.py 3KB
stickerbot.py 1KB
broadcastbot.py 3KB
spongebot.py 1KB
lovebot.py 1KB
expirationbot.py 2KB
docs
semaphore.sticker.rst 107B
semaphore.reply.rst 101B
index.rst 516B
semaphore.groupV2.rst 107B
semaphore.rst 585B
make.bat 795B
semaphore.job.rst 95B
semaphore.attachment.rst 116B
semaphore.address.rst 110B
Makefile 634B
semaphore.job_queue.rst 110B
semaphore.data_message.rst 119B
semaphore.queue.rst 125B
semaphore.sticker_pack.rst 119B
semaphore.group.rst 105B
conf.py 2KB
semaphore.message_sender.rst 125B
semaphore.chat_context.rst 119B
semaphore.link_preview.rst 119B
semaphore.exceptions.rst 121B
semaphore.message_receiver.rst 131B
semaphore.profile.rst 107B
semaphore.bot.rst 95B
semaphore.message.rst 107B
semaphore.socket.rst 104B
semaphore
__init__.py 1KB
socket.py 4KB
attachment.py 3KB
link_preview.py 2KB
job.py 3KB
chat_context.py 1KB
sticker_pack.py 2KB
bot.py 10KB
profile.py 3KB
groupV2.py 2KB
sticker.py 1KB
reply.py 1KB
queue.py 1KB
job_queue.py 5KB
message.py 4KB
group.py 1KB
message_receiver.py 6KB
message_sender.py 13KB
data_message.py 2KB
meta.py 1015B
exceptions.py 3KB
address.py 1KB
.gitignore 2KB
setup.cfg 500B
README.md 8KB
共 77 条
- 1
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9154
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功