Navigation Menu

Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
catbaron0 committed Jun 5, 2019
0 parents commit 9e34e07
Show file tree
Hide file tree
Showing 8 changed files with 526 additions and 0 deletions.
106 changes: 106 additions & 0 deletions .gitignore
@@ -0,0 +1,106 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

.vscode/
80 changes: 80 additions & 0 deletions README.md
@@ -0,0 +1,80 @@
# SearchMessage: A middleware for EFB

## Notice

**Middleware ID**: `catbaron.search_msg`

**SearchMessage** is a middleware for EFB, to search message from the chat history.

Usually, you may have trouble to search messages with **Chinses** key words in Telegram clients,
thus here is the middleware could help you out.

Be aware that this is a very early develop version. Please let me know if you found any problem.

You need to use **MessageBlocker** on top of [EFB](https://ehforwarderbot.readthedocs.io). Please check the document and install EFB first.

## Dependense

* Python >=3.6
* EFB >=2.0.0
* peewee
* PyYaml
* python-dateutil

## Install

* Install
```
git clone https://github.com/catbaron0/efb-search_msg-middleware
cd efb-search_msg-middleware
Python setup.py install # You may need su permission here
```
* Register to EFB
Following [this document](https://ehforwarderbot.readthedocs.io/en/latest/getting-started.html) to edit the config file. The config file by default is `~/.ehforwarderbot/profiles/default`. It should look like:
```
master_channel: foo.demo_master
slave_channels:
- foo.demo_slave
- bar.dummy
middlewares:
- foo.other_middlewares
- catbaron.search_msg
```

You only need to add the last line to your config file.

* Config the middleware

The config file by default is `$HOME/.ehforwarderbot/profiles/default/catbaron.search_msg/config.yaml`.
Please create the config file if thers is not one. Edit it as:

```
# The name of master channel
master: 'blueset.telegram'
# The max number of message the middleware would show you.
# Set it to 0 for no limitation.
max_num: 15
```

* Restart EFB.

![](./example.png)

## How to use
### The command:
`\sr [key_word] [from:datetime] [to:datetime]`
* `key_word`: text without whitespace characters
* `datetime`: Datetime string, such as `1989-6`, `2008-8-8 12:0`. Note that `from:` and `to:` are necessary and there should be no space in this argument. Messages of last 15 days will be searched by default.


### Usage
1. Sent command to a chat
* There should be at least one of the three arguments
2. Reply the command to an message
* Search message sent by the author of the replied message
* Some times the author is saved as `None` in the database, so it's not always reliable.
3. To locate the message in Telegram, you can:
* Search the full message in Telegram
* Search some segment of message splitted by non-chinese characters.
* For instance, say you have a message `这是一条被空格分开 的消息`, to locate this message, you coulde search the entire message, `这是一条被空格分开` or `的消息` in Telegram.
70 changes: 70 additions & 0 deletions README.rst
@@ -0,0 +1,70 @@
# MessageBLocker: A middleware for EFB

-------
## Notice

**Middleware ID**: `catbaron.message_blocker`

**MessageBLocker** is a middleware for EFB, to manage filters and block some specific messages.

Be aware that this is a very early develop version. Please let me know if you found any problem.

You need to use **MessageBlocker** on top of [EFB](https://ehforwarderbot.readthedocs.io). Please check the document and install EFB firset.

-------

## Dependense

* Python >=3.6
* EFB >=2.0.0
* peewee
* PyYaml

## Install

```
git clone https://github.com/catbaron/efb-msg_blocker-middleware
cd efb-msg_blocker-middleware
Python setup.py install # You may need su permission here
```
## How it works
MesageBlocker support three types of filter:

1. `user`: The unique ID of a user in a chat. It's useful when you want to block some users in a group.
2. `type`: Block some specific type of image. Support all the `MsgType` defined by `EFB`, including `image`, `audio`, `file`, `link`, `location`, `status`, `sticker`, `text`, `video`, and `unsupported`.
3. `text`: Block messages matched by a Regex string. Only effective for `text` type of messages.

A filter is a dictionary with at least one of three keys: `user`, `type` and `text`. Messages matched by all the provided filters will be blocked.

For instance, here is a filter:
```
{
"type": ["image", "video"],
"user": "e5141de3"
}
```
This filter matches messages in type of `image` or `video`, and sent by the user whose id is `e5141de3`.

## Usage
Three commands are supported by this middleware.

* `\list`: List all the filters you have added to one chat. The EFB will reply to you with a list of `json` string. e.g.:

```
{'id': 1, 'author_channel_id': 'blueset.wechat', 'author_channel_name': 'WeChat Slave', 'author_chat_name': '', 'author_chat_alias': 'None', 'chat_chat_uid': 'c00003', 'chat_chat_name': '', 'chat_chat_alias': 'None', 'filter_text': '{"type": ["image"], "user": "12345"}'}
```

`id` is the unique ID for this filter, and `filter_text` is the content of this filter. The others are information about chat where the filter is active.

* `\del {id}`: Delete a filter with filter `id`. e.g.

```
\del 1
```

* `\add {arg}`: Add filters. There are some ways to add filters.

* `arg` is one of any supported `type`, so that all the messages in the specific type will be blocked. For example `\add image` adds a filter to block all the image messages.
* `arg` is `filter_text`, like `\add {"type": ["image"]}`
* You cloud reply `\add {arg}` a message in order to block messages from one user. Foe example, after you reply `\add {"type": ["image"]}` to a message sent by user whose `id` is `12345`, it's equivalent to `\add '{"type": ["image"], "user": "12345"}`

0 comments on commit 9e34e07

Please sign in to comment.