├── efb-wechat ├── efb_config │ └── profiles │ │ └── default │ │ ├── blueset.wechat │ │ └── config.yaml │ │ ├── patch.PatchMiddleware │ │ └── config.yaml │ │ ├── config.yaml │ │ ├── catbaron.search_msg │ │ └── config.yaml │ │ └── blueset.telegram │ │ └── config.yaml ├── requirements.txt ├── start.sh ├── Dockerfile └── configuration.py ├── .gitignore ├── docker-compose.yml ├── LICENSE ├── .github └── workflows │ └── docker-image.yml └── README.md /efb-wechat/efb_config/profiles/default/blueset.wechat/config.yaml: -------------------------------------------------------------------------------- 1 | flags: 2 | delete_on_edit: true -------------------------------------------------------------------------------- /efb-wechat/efb_config/profiles/default/patch.PatchMiddleware/config.yaml: -------------------------------------------------------------------------------- 1 | auto_mark_as_read: true 2 | remove_emoji_in_title: true 3 | strikethrough_recall_msg: true 4 | -------------------------------------------------------------------------------- /efb-wechat/efb_config/profiles/default/config.yaml: -------------------------------------------------------------------------------- 1 | master_channel: blueset.telegram 2 | slave_channels: 3 | - blueset.wechat 4 | middlewares: 5 | - patch.PatchMiddleware 6 | - catbaron.search_msg 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | venv/ 2 | 3 | *.pyc 4 | __pycache__/ 5 | 6 | instance/ 7 | 8 | .pytest_cache/ 9 | .coverage 10 | htmlcov/ 11 | 12 | dist/ 13 | build/ 14 | *.egg-info/ 15 | 16 | logs 17 | 18 | .idea -------------------------------------------------------------------------------- /efb-wechat/requirements.txt: -------------------------------------------------------------------------------- 1 | ehforwarderbot 2 | efb-telegram-master 3 | efb-telegram-master[tgs] 4 | python-telegram-bot[socks] 5 | efb-patch-middleware-itchat-uos 6 | efb-search_msg-middleware 7 | efb-wechat-slave-itchat-uos -------------------------------------------------------------------------------- /efb-wechat/efb_config/profiles/default/catbaron.search_msg/config.yaml: -------------------------------------------------------------------------------- 1 | # The name of master channel 2 | master: 'blueset.telegram' 3 | 4 | # The max number of message the middleware would show you. 5 | # Set it to 0 for no limitation. 6 | max_num: 15 -------------------------------------------------------------------------------- /efb-wechat/efb_config/profiles/default/blueset.telegram/config.yaml: -------------------------------------------------------------------------------- 1 | token: 1234567890:example 2 | admins: 3 | - 65536 4 | request_kwargs: 5 | proxy_url: socks5://example.com:1080 6 | urllib3_proxy_kwargs: 7 | proxy_user: example 8 | proxy_pass: example 9 | flags: 10 | send_image_as_file: true 11 | animated_stickers: true 12 | message_muted_on_slave: normal 13 | your_message_on_slave: silent 14 | -------------------------------------------------------------------------------- /efb-wechat/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | EWS_LOGIN_STATUS_FILE="/home/efb/efb_config/profiles/default/blueset.wechat/wxpy.pkl" 4 | 5 | if [ -e "$EWS_LOGIN_STATUS_FILE" ]; then 6 | rm "$EWS_LOGIN_STATUS_FILE" 7 | echo "Deleted previous WeChat login status file." 8 | echo "Checking environment variables" 9 | else 10 | echo "Checking environment variables" 11 | fi 12 | 13 | python3 configuration.py && ehforwarderbot -p default -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | efb-wechat: 4 | image: hogangolden/efb-wechat 5 | container_name: efb-wechat 6 | restart: unless-stopped 7 | environment: 8 | - BOT_TOKEN=example_bot_token # Required 9 | - BOT_ADMIN=example_bot_admin # Required 10 | # - PROXY_URL=http://example.com:1080 # Optional, need when your internet can not connect to Telegram. 11 | # - PROXY_USER=user # Optional, need when your proxy need authentication. 12 | # - PROXY_PASS=password # Optional, need when your proxy need authentication. 13 | # - MP_GROUP_ID=-65536 # Optional, forward every public account message to specific group. 14 | volumes: 15 | - efb-wechat-data:/home/efb/efb_config/profiles/default 16 | volumes: 17 | efb-wechat-data: 18 | -------------------------------------------------------------------------------- /efb-wechat/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:alpine as base 2 | 3 | RUN apk add --no-cache tzdata ffmpeg libmagic libwebp cairo && \ 4 | cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ 5 | echo "Asia/Shanghai" > /etc/timezone && \ 6 | apk del tzdata && \ 7 | adduser -D efb 8 | 9 | FROM base as builder 10 | 11 | COPY requirements.txt . 12 | 13 | RUN apk add --no-cache build-base openssl-dev zlib-dev jpeg-dev libwebp-dev libffi-dev && \ 14 | python3 -m pip install --upgrade pip 15 | 16 | USER efb 17 | 18 | RUN pip install --user --no-warn-script-location -r requirements.txt 19 | 20 | FROM base 21 | 22 | USER efb 23 | WORKDIR /home/efb 24 | 25 | COPY --from=builder --chown=efb:efb /home/efb/.local /home/efb/.local 26 | COPY --chown=efb:efb . /home/efb 27 | 28 | ENV PATH=/home/efb/.local/bin:${PATH} 29 | ENV EFB_DATA_PATH=/home/efb/efb_config 30 | 31 | ENTRYPOINT ["sh", "start.sh"] 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023, Hogan Golden 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /.github/workflows/docker-image.yml: -------------------------------------------------------------------------------- 1 | name: Publish Docker Image 2 | 3 | on: 4 | push: 5 | branches: [ "docker-build" ] 6 | 7 | env: 8 | DH_IMAGE_NAME: hogangolden/efb-wechat 9 | 10 | jobs: 11 | build-and-push-image: 12 | name: Push Docker image to Docker Hub 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v3 17 | - name: Docker meta 18 | id: meta 19 | uses: docker/metadata-action@v4 20 | with: 21 | # list of Docker images to use as base name for tags 22 | images: | 23 | ${{ env.DH_IMAGE_NAME }} 24 | labels: | 25 | org.opencontainers.image.title=EFB-WeChat-Telegram 26 | org.opencontainers.image.description=EFB Docker image. 将微信中的聊天消息转发到telegram 27 | # generate Docker tags based on the following events/attributes 28 | tags: | 29 | type=semver,pattern={{version}} 30 | type=raw,value=latest 31 | - name: Set up QEMU 32 | uses: docker/setup-qemu-action@v2 33 | - name: Set up Docker Buildx 34 | uses: docker/setup-buildx-action@v2 35 | - name: Login to Docker Hub 36 | uses: docker/login-action@v2 37 | with: 38 | username: ${{ secrets.DOCKERHUB_USERNAME }} 39 | password: ${{ secrets.DOCKERHUB_TOKEN }} 40 | - name: Build and push 41 | uses: docker/build-push-action@v4 42 | with: 43 | context: efb-wechat 44 | platforms: linux/amd64,linux/386,linux/arm64,linux/arm/v7 45 | push: ${{ github.event_name != 'pull_request' }} 46 | tags: ${{ steps.meta.outputs.tags }} 47 | labels: ${{ steps.meta.outputs.labels }} 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # efb-wechat-docker-itchat-uos 2 | 3 | 将微信中的聊天消息转发到telegram :drooling_face: 4 | 5 | 好处: 6 | - 可以完全关闭手机上的微信应用(禁用android上微信的自启权限,禁止微信后台运行)。android国产rom上如何开启telegram通知[参考1](https://www.v2ex.com/t/831069) [参考 2](https://github.com/kooritea/fcmfix) 7 | 8 | **注意:** 9 | - **使用该项目,微信有被封禁风险,请自行判断是否使用** [参考1](https://github.com/why2lyj/ItChat-UOS#%E6%9B%B4%E6%96%B0---20230210) [参考2](https://github.com/HoganGolden/efb-wechat-slave-itchat-uos#%E4%BD%BF%E7%94%A8%E5%89%8D%E9%A1%BB%E7%9F%A5) 10 | - 如何减少封禁:项目尽量部署在你的本地(本市范围),如家里的树莓派等。并为该本地的网络环境配置可以访问telegram的代理。代理配置[参考FQA](#FQA) 11 | 12 | # docker image 13 | 点击下面图标,跳转到docker hub 14 | 15 | [![docker: image size](https://img.shields.io/docker/image-size/hogangolden/efb-wechat)](https://hub.docker.com/r/hogangolden/efb-wechat) 16 | 17 | ## 鸣谢 18 | * [efb-wechat-docker](https://github.com/haukeng/efb-wechat-docker) 19 | * [ehForwarderBot](https://github.com/ehForwarderBot) 20 | * [ItChat-UOS](https://github.com/why2lyj/ItChat-UOS) 21 | 22 | EFB Docker image with: 23 | * [efb-telegram-master](https://github.com/ehForwarderBot/efb-telegram-master) 24 | * [efb-wechat-slave-itchat-uos](https://github.com/HoganGolden/efb-wechat-slave-itchat-uos) 25 | * [efb-patch-middleware-itchat-uos](https://github.com/HoganGolden/efb-patch-middleware-itchat-uos) 26 | * [efb-search_msg-middleware](https://github.com/ehForwarderBot/efb-search_msg-middleware) 27 | 28 | ## Features 29 | 30 | - Container run by non-root user. 31 | - Support add environment variables `PROXY_URL`, `PROXY_USER`, and `PROXY_PASS` to use proxy for ETM. 32 | - Integrate [efb-patch-middleware-itchat-uos](https://github.com/HoganGolden/efb-wechat-slave-itchat-uos) and [efb-search_msg-middleware](https://github.com/ehForwarderBot/efb-search_msg-middleware) by default. 33 | 34 | ## Build 35 | 36 | ### Use GitHub Action pre-build image 37 | 38 | ```shell 39 | docker pull hogangolden/efb-wechat 40 | ``` 41 | 42 | ### Build image manually 43 | 44 | ```shell 45 | git clone https://github.com/HoganGolden/efb-wechat-docker-itchat-uos.git 46 | cd efb-wechat-docker-itchat-uos && docker build -t hogangolden/efb-wechat efb-wechat 47 | ``` 48 | 49 | ## Usage 50 | 51 | ### Step 0 52 | 53 | Create a Telegram Bot by talking to [@BotFather](https://t.me/botfather) and it will give you the Bot Token 54 | 55 | Get your Telegram ID (**Not username**) from [@getidsbot](https://t.me/getidsbot) 56 | 57 | ### Step 1 58 | 59 | **If you prefer to use docker.** 60 | 61 | ```shell 62 | # Create volumes 63 | docker volume create efb-wechat-data 64 | 65 | # Run 66 | docker run -d -t \ 67 | --name "efb-wechat" \ 68 | -e BOT_TOKEN=xxxx \ 69 | -e BOT_ADMIN=xxxx \ 70 | -v efb-wechat-data:/home/efb/efb_config/profiles/default \ 71 | hogangolden/efb-wechat 72 | ``` 73 | 74 | (**Required**) Use your Telegram Bot Token as `BOT_TOKEN` and your Telegram ID as `BOT_ADMIN` 75 | 76 | **If you prefer to use docker-compose.** 77 | 78 | ```shell 79 | mkdir efb-wechat && cd efb-wechat 80 | wget https://raw.githubusercontent.com/HoganGolden/efb-wechat-docker-itchat-uos/main/docker-compose.yml -O docker-compose.yml 81 | ``` 82 | 83 | (**Required**) Modify the environment variables by editing docker-compose.yml, and then: 84 | 85 | ```shell 86 | docker-compose up -d 87 | ``` 88 | raspberry pi os 89 | ```shell 90 | docker compose up -d 91 | ``` 92 | 93 | ### Step 2 94 | 95 | ```shell 96 | docker logs --tail=200 -f efb-wechat 97 | # Ctrl + C to quit after your log in 98 | ``` 99 | 100 | Scan the QR code to log in 101 | 102 | ## Telegram 上机器人的设置 103 | * 允许 Bot 读取非指令信息,对 @botfather 说话: /setprivacy, 选择disable 104 | * 允许将 Bot 添加进群组,对 @botfather 说话: /setjoingroups, 选择enable 105 | * 允许 Bot 提供指令列表,对 @botfather 说话: /setcommands, 输入以下内容 (复制以下内容一次性发给botfather) 106 | 107 | 108 | help - Show commands list. 109 | link - Link a remote chat to a group. 110 | unlink_all - Unlink all remote chats from a group. 111 | info - Display information of the current Telegram chat. 112 | chat - Generate a chat head. 113 | extra - Access additional features from Slave Channels. 114 | update_info - Update info of linked Telegram group. 115 | react - Send a reaction to a message, or show a list of reactors. 116 | rm - Remove a message from its remote chat. 117 | 118 | ## Configuration Options 119 | 120 | `BOT_TOKEN` 121 | 122 | > (**Required**) Your Telegram bot token. 123 | 124 | `BOT_ADMIN` 125 | 126 | > (**Required**) Your Telegram account id. 127 | 128 | `PROXY_URL` 129 | 130 | > (Optional) Proxy url use to connect Telegram by network proxy. 131 | > 132 | > Supported both `http` and `socks5` proxy. 133 | > 134 | > For example: `http://172.17.0.1:1080` 135 | 136 | `PROXY_USER` 137 | 138 | > (Optional) Use for proxy authentication 139 | 140 | `PROXY_PASS` 141 | 142 | > (Optional) Use for roxy authentication 143 | 144 | `SEND_IMAGE_AS_FILE` 145 | 146 | > (Optional) Set the value to `0` to **disable** send all image messages as files (preventing Telegram’s image compression). 147 | > 148 | > _Enabled by default._ 149 | 150 | `ANIMATED_STICKERS` 151 | 152 | > (Optional) Set the value to `0` to **disable** support to animated stickers. 153 | > 154 | > _Enabled by default._ 155 | 156 | `MESSAGE_MUTED_ON_SLAVE` 157 | 158 | > (Optional) Behavior when a message received is muted on slave channel platform. Availiable value: `normal`, `silent` and `mute`. Go to [ehForwarderBot/efb-telegram-master](https://github.com/ehForwarderBot/efb-telegram-master#experimental-flags) to get more information. 159 | > 160 | > _`normal` is the default value_ 161 | 162 | `YOUR_MESSAGE_ON_SLAVE` 163 | 164 | > (Optional) Behavior when a message received is from you on slave channel platform. Availiable value: `normal`, `silent` and `mute`. Go to [ehForwarderBot/efb-telegram-master](https://github.com/ehForwarderBot/efb-telegram-master#experimental-flags) to get more information. 165 | > 166 | > _`silent` is the default value_ 167 | 168 | `MP_GROUP_ID` 169 | 170 | > (Optional) Telegram group id for forwarding every public account message to it. Go to [efb-patch-middleware](https://github.com/ehForwarderBot/efb-patch-middleware#usage) to get more information. 171 | 172 | `AUTO_MARK_AS_READ` 173 | 174 | > (Optional) Set the value to `0` to **disable** auto mark as read in wechat phone client. Go to [efb-patch-middleware](https://github.com/ehForwarderBot/efb-patch-middleware#usage) to get more information. 175 | > 176 | > _Enabled by default._ 177 | 178 | `REMOVE_EMOJI_IN_TITLE` 179 | 180 | > (Optional) Set the value to `0` to **disable** remove emoji in telegram group title. Go to [efb-patch-middleware](https://github.com/ehForwarderBot/efb-patch-middleware#usage) to get more information. 181 | > 182 | > _Enabled by default._ 183 | 184 | `STRIKETHROUGH_RECALL_MSG` 185 | 186 | > (Optional) Set the value to `0` to **disable** strikethrough instead of replying to a recall message. Go to [efb-patch-middleware](https://github.com/ehForwarderBot/efb-patch-middleware#usage) to get more information. 187 | > 188 | > _Enabled by default._ 189 | 190 | ## FQA 191 | 192 | ### How to use host machine proxy? 193 | 194 | Try to set `PROXY_URL` as `http://172.17.0.1:YOUR_PORT` (Socks5 works as well) 195 | 196 | * 本人使用[xray](https://github.com/XTLS/Xray-core)客户端做代理,需要配置为:大陆ip和域名直连,外网地址通过代理访问。客户端routing部分的配置参考如下: 197 | ```json 198 | { 199 | "routing": { 200 | "domainStrategy": "IPIfNonMatch", 201 | "rules": [ 202 | { 203 | "type": "field", 204 | "outboundTag": "direct", 205 | "domain": [ 206 | "geosite:cn", 207 | "geosite:private" 208 | ] 209 | }, 210 | { 211 | "type": "field", 212 | "outboundTag": "direct", 213 | "ip": [ 214 | "geoip:private", 215 | "geoip:cn" 216 | ] 217 | } 218 | ] 219 | } 220 | } 221 | ``` 222 | 223 | ## [EFB 框架及各组件常见问题](https://github.com/ehForwarderBot/efb-wechat-slave/wiki/EFB%E2%80%86%E6%A1%86%E6%9E%B6%E5%8F%8A%E5%90%84%E7%BB%84%E4%BB%B6%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98) 224 | 225 | ## LICENSE 226 | MIT 227 | -------------------------------------------------------------------------------- /efb-wechat/configuration.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | from os import getenv 3 | from os import path 4 | from re import fullmatch 5 | from ruamel.yaml import YAML 6 | 7 | 8 | class bcolors: 9 | OK = "\033[36m" 10 | WARN = "\33[33m" 11 | FAIL = "\033[33m" 12 | ENDC = "\033[0m" 13 | 14 | 15 | def config_validator(value: str, _type="OTHER") -> bool: 16 | if _type == "BOT_TOKEN": 17 | if fullmatch("^[0-9]*:[a-zA-Z0-9_-]{35}$", value) is None: 18 | return False 19 | return True 20 | elif _type == "BOT_ADMIN": 21 | admins_list = value.split("#") 22 | if len(admins_list[0]) == 0: 23 | return False 24 | else: 25 | for id in admins_list: 26 | if fullmatch("^[0-9]*$", id) is None: 27 | return False 28 | return True 29 | elif _type == "PROXY_URL": 30 | if fullmatch("^(http|socks5):\/\/.*:\d{1,5}$", value) is None: 31 | return False 32 | return True 33 | elif _type == "MP_GROUP_ID": 34 | if fullmatch("^\-[0-9]*$", value) is None: 35 | return False 36 | return True 37 | elif _type == "BOOL_NUM": 38 | if fullmatch("^(0|1)$", value) is None: 39 | return False 40 | return True 41 | elif _type == "MESSAGE_NOTICE": 42 | if fullmatch("^(normal|silent|mute)$", value.lower()) is None: 43 | return False 44 | return True 45 | elif _type == "OTHER": 46 | if len(value) == 0: 47 | return False 48 | return True 49 | else: 50 | return False 51 | 52 | 53 | def get_etm_config(): 54 | etm_config = {} 55 | etm_config_flags = { 56 | "send_image_as_file": True, 57 | "animated_stickers": True, 58 | "message_muted_on_slave": "normal", 59 | "your_message_on_slave": "silent", 60 | } 61 | 62 | bot_token = getenv("BOT_TOKEN", "") 63 | bot_admin = getenv("BOT_ADMIN", "") 64 | proxy_url = getenv("PROXY_URL", "") 65 | proxy_user = getenv("PROXY_USER", "") 66 | proxy_pass = getenv("PROXY_PASS", "") 67 | mp_group_id = getenv("MP_GROUP_ID", "") 68 | send_image_as_file = getenv("SEND_IMAGE_AS_FILE", "") 69 | animated_stickers = getenv("ANIMATED_STICKERS", "") 70 | message_muted_on_slave = getenv("MESSAGE_MUTED_ON_SLAVE", "") 71 | your_message_on_slave = getenv("YOUR_MESSAGE_ON_SLAVE", "") 72 | 73 | if config_validator(bot_token, "BOT_TOKEN"): 74 | etm_config["token"] = bot_token 75 | print(bcolors.OK + "The bot token check passed." + bcolors.ENDC) 76 | else: 77 | print( 78 | bcolors.FAIL 79 | + "The bot token isn't validated, please check it." 80 | + bcolors.ENDC 81 | ) 82 | exit(1) 83 | 84 | if config_validator(bot_admin, "BOT_ADMIN"): 85 | etm_config["admins"] = [int(x) for x in bot_admin.split("#")] 86 | print(bcolors.OK + "The bot admin list check passed." + bcolors.ENDC) 87 | else: 88 | print( 89 | bcolors.FAIL 90 | + "The bot admin list isn't validated, please check it." 91 | + bcolors.ENDC 92 | ) 93 | exit(1) 94 | 95 | if ( 96 | config_validator(proxy_url, "PROXY_URL") 97 | and config_validator(proxy_user) 98 | and config_validator(proxy_pass) 99 | ): 100 | proxy_method = fullmatch("^(http|socks5):\/\/.*:\d{1,5}$", proxy_url).group(1) 101 | if proxy_method == "http": 102 | etm_config["request_kwargs"] = { 103 | "proxy_url": proxy_url, 104 | "proxy_user": proxy_user, 105 | "proxy_pass": proxy_pass, 106 | } 107 | print( 108 | bcolors.OK 109 | + "You are using http proxy with authentication." 110 | + bcolors.ENDC 111 | ) 112 | elif proxy_method == "socks5": 113 | etm_config["request_kwargs"] = { 114 | "proxy_url": proxy_url, 115 | "urllib3_proxy_kwargs": { 116 | "proxy_user": proxy_user, 117 | "proxy_pass": proxy_pass, 118 | }, 119 | } 120 | print( 121 | bcolors.OK 122 | + "You are using socks5 proxy with authentication." 123 | + bcolors.ENDC 124 | ) 125 | else: 126 | print( 127 | bcolors.FAIL 128 | + "The proxy method is " 129 | + proxy_method 130 | + " and it was unsupported." 131 | + bcolors.ENDC 132 | ) 133 | exit(1) 134 | elif config_validator(proxy_url, "PROXY_URL"): 135 | etm_config["request_kwargs"] = {"proxy_url": proxy_url} 136 | print(bcolors.OK + "You are using proxy without authentication." + bcolors.ENDC) 137 | else: 138 | print( 139 | bcolors.WARN 140 | + "You don't use any proxy at all, make sure you can access telegram by direct!" 141 | + bcolors.ENDC 142 | ) 143 | 144 | if config_validator(mp_group_id, "MP_GROUP_ID"): 145 | print( 146 | bcolors.WARN 147 | + "All messages from WeChat Official Account will be forward to the Group " 148 | + mp_group_id 149 | + bcolors.ENDC 150 | ) 151 | etm_config["tg_mp"] = int(mp_group_id) 152 | else: 153 | print( 154 | bcolors.OK 155 | + "You message from WeChat Official Account will not be forward to the Group." 156 | + bcolors.ENDC 157 | ) 158 | 159 | if config_validator(send_image_as_file, "BOOL_NUM"): 160 | etm_config_flags["send_image_as_file"] = bool(int(send_image_as_file)) 161 | 162 | if config_validator(animated_stickers, "BOOL_NUM"): 163 | etm_config_flags["animated_stickers"] = bool(int(animated_stickers)) 164 | 165 | if config_validator(message_muted_on_slave, "MESSAGE_NOTICE"): 166 | etm_config_flags["message_muted_on_slave"] = message_muted_on_slave.lower() 167 | 168 | if config_validator(your_message_on_slave, "MESSAGE_NOTICE"): 169 | etm_config_flags["your_message_on_slave"] = your_message_on_slave.lower() 170 | 171 | etm_config["flags"] = etm_config_flags 172 | return etm_config 173 | 174 | 175 | def get_efb_patch_config(): 176 | efb_patch_config = { 177 | "auto_mark_as_read": True, 178 | "remove_emoji_in_title": True, 179 | "strikethrough_recall_msg": True, 180 | } 181 | 182 | auto_mark_as_read = getenv("AUTO_MARK_AS_READ", "") 183 | remove_emoji_in_title = getenv("REMOVE_EMOJI_IN_TITLE", "") 184 | strikethrough_recall_msg = getenv("STRIKETHROUGH_RECALL_MSG", "") 185 | 186 | if config_validator(auto_mark_as_read, "BOOL_NUM"): 187 | efb_patch_config["auto_mark_as_read"] = bool(int(auto_mark_as_read)) 188 | 189 | if config_validator(remove_emoji_in_title, "BOOL_NUM"): 190 | efb_patch_config["remove_emoji_in_title"] = bool(int(remove_emoji_in_title)) 191 | 192 | if config_validator(strikethrough_recall_msg, "BOOL_NUM"): 193 | efb_patch_config["strikethrough_recall_msg"] = bool( 194 | int(strikethrough_recall_msg) 195 | ) 196 | 197 | return efb_patch_config 198 | 199 | 200 | def main(): 201 | etm_config = get_etm_config() 202 | efb_patch_config = get_efb_patch_config() 203 | 204 | etm_config_path = "efb_config/profiles/default/blueset.telegram/config.yaml" 205 | efb_patch_config_path = ( 206 | "efb_config/profiles/default/patch.PatchMiddleware/config.yaml" 207 | ) 208 | 209 | yaml = YAML() 210 | yaml.indent(mapping=2, sequence=2, offset=0) 211 | with open(path.join(path.dirname(__file__), etm_config_path), "w") as fw_etm_config: 212 | yaml.dump(etm_config, fw_etm_config) 213 | 214 | with open( 215 | path.join(path.dirname(__file__), efb_patch_config_path), "w" 216 | ) as fw_efb_patch_config: 217 | yaml.dump(efb_patch_config, fw_efb_patch_config) 218 | 219 | 220 | if __name__ == "__main__": 221 | main() 222 | --------------------------------------------------------------------------------