From 46df9c99f34d9d10a4563cb0af46f74efaa7bcd1 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Sat, 22 Jan 2022 20:55:47 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Redis=20support=20password?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✨ 支持设置 Redis 数据库密码 --- .github/workflows/main.yml | 4 ---- config.gen.yml | 1 + install.sh | 1 + pagermaid/__init__.py | 10 ++++++---- pagermaid/assets/config.gen.yml | 1 + 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0720d2c..95319f2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -37,8 +37,6 @@ jobs: - name: Build run: | - FULL_VERSION=$(curl https://api.github.com/repos/just-containers/s6-overlay/releases/latest | jq -r '.tag_name') - declare -a IMAGES echo "Build amd64" @@ -47,7 +45,6 @@ jobs: --cache-to "type=local,dest=/tmp/.buildx-cache" \ --output "type=image,push=true" \ --platform linux/amd64 \ - --build-arg "S6_VERSION=${FULL_VERSION}" \ --build-arg "S6_ARCH=amd64" \ --tag "${DOCKERHUB_REPOSITORY}:latest-amd64" \ -f Dockerfile \ @@ -60,7 +57,6 @@ jobs: --cache-to "type=local,dest=/tmp/.buildx-cache" \ --output "type=image,push=true" \ --platform linux/arm64/v8 \ - --build-arg "S6_VERSION=${FULL_VERSION}" \ --build-arg "S6_ARCH=aarch64" \ --tag "${DOCKERHUB_REPOSITORY}:latest-arm64-v8" \ -f Dockerfile \ diff --git a/config.gen.yml b/config.gen.yml index 7b3fe81..68c4d63 100644 --- a/config.gen.yml +++ b/config.gen.yml @@ -27,6 +27,7 @@ redis: host: "localhost" port: "6379" db: "14" + password: "" # Locale settings application_language: "zh-cn" diff --git a/install.sh b/install.sh index 1756d3a..0d7af5e 100644 --- a/install.sh +++ b/install.sh @@ -9,6 +9,7 @@ a=$(curl --noproxy '*' -sSL https://api.myip.com/) b="China" if [[ $a == *$b* ]] then + echo "错误:本脚本不支持境内服务器使用。" 1>&2 exit 1 fi diff --git a/pagermaid/__init__.py b/pagermaid/__init__.py index 0b36b85..887fb70 100644 --- a/pagermaid/__init__.py +++ b/pagermaid/__init__.py @@ -28,7 +28,8 @@ from telethon.errors import AuthKeyError from telethon.errors.rpcerrorlist import MessageNotModifiedError, MessageIdInvalidError, ChannelPrivateError, \ ChatSendMediaForbiddenError, YouBlockedUserError, FloodWaitError, ChatWriteForbiddenError, \ AuthKeyDuplicatedError, ChatSendStickersForbiddenError, SlowModeWaitError, MessageEditTimeExpiredError, \ - PeerIdInvalidError, AuthKeyUnregisteredError, UserBannedInChannelError, UserDeactivatedBanError, PeerFloodError + PeerIdInvalidError, AuthKeyUnregisteredError, UserBannedInChannelError, UserDeactivatedBanError, PeerFloodError, \ + SessionRevokedError from telethon.errors.common import AlreadyInConversationError from requests.exceptions import ChunkedEncodingError from requests.exceptions import ConnectionError as ConnectedError @@ -173,6 +174,7 @@ mtp_secret = config.get('mtp_secret', '').strip() redis_host = config.get('redis').get('host', 'localhost') redis_port = config.get('redis').get('port', 6379) redis_db = config.get('redis').get('db', 14) +redis_password = config.get('redis').get('password', '') if strtobool(config.get('ipv6', 'False')): use_ipv6 = True else: @@ -234,7 +236,7 @@ else: bot = TelegramClient(session_string, api_key, api_hash, auto_reconnect=True, use_ipv6=use_ipv6) user_id = 0 user_bot = False -redis = StrictRedis(host=redis_host, port=redis_port, db=redis_db) +redis = StrictRedis(host=redis_host, port=redis_port, db=redis_db, password=redis_password) async def save_id(): @@ -283,8 +285,8 @@ def before_send(event, hint): AuthKeyUnregisteredError, UserBannedInChannelError, AuthKeyError, CancelError, AsyncTimeoutError)): return - elif exc_info and isinstance(exc_info[1], UserDeactivatedBanError): - # The user has been deleted/deactivated + elif exc_info and isinstance(exc_info[1], (UserDeactivatedBanError, SessionRevokedError)): + # The user has been deleted/deactivated or session revoked try: remove('pagermaid.session') except Exception as exc: diff --git a/pagermaid/assets/config.gen.yml b/pagermaid/assets/config.gen.yml index 7b3fe81..68c4d63 100644 --- a/pagermaid/assets/config.gen.yml +++ b/pagermaid/assets/config.gen.yml @@ -27,6 +27,7 @@ redis: host: "localhost" port: "6379" db: "14" + password: "" # Locale settings application_language: "zh-cn"