fix: change to static method

This commit is contained in:
Hehesheng 2024-06-07 01:08:32 +08:00
parent 6711e30ffc
commit 68478a0e45
2 changed files with 5 additions and 4 deletions

View File

@ -7,7 +7,7 @@ import os
import functools import functools
import traceback import traceback
import logging import logging
from typing import Union, Optional from typing import Union, Optional, Literal
from telethon import TelegramClient, types, hints, events from telethon import TelegramClient, types, hints, events
from telethon.custom import QRLogin from telethon.custom import QRLogin
@ -128,7 +128,7 @@ class TgFileSystemClient(object):
msg: types.Message = event.message msg: types.Message = event.message
self.db.insert_by_message(self.me, msg) self.db.insert_by_message(self.me, msg)
async def login(self, mode: Union["phone", "qrcode"] = "qrcode") -> str: async def login(self, mode: Literal["phone", "qrcode"] = "qrcode") -> str:
if self.is_valid(): if self.is_valid():
return "" return ""
if mode == "phone": if mode == "phone":
@ -184,7 +184,7 @@ class TgFileSystemClient(object):
async def _cache_whitelist_chat2(self): async def _cache_whitelist_chat2(self):
for chat_id in self.client_param.whitelist_chat: for chat_id in self.client_param.whitelist_chat:
async for msg in self.client.iter_messages(chat_id): async for msg in self.client.iter_messages(chat_id):
if len(self.db.get_msg_by_unique_id(self.db.generate_unique_id_by_msg(self.me, msg))) != 0: if len(self.db.get_msg_by_unique_id(UserManager.generate_unique_id_by_msg(self.me, msg))) != 0:
continue continue
self.db.insert_by_message(self.me, msg) self.db.insert_by_message(self.me, msg)
logger.info(f"{chat_id} quit cache task.") logger.info(f"{chat_id} quit cache task.")

View File

@ -50,7 +50,8 @@ class UserManager(object):
def update_message(self) -> None: def update_message(self) -> None:
raise NotImplementedError raise NotImplementedError
def generate_unique_id_by_msg(self, me: types.User, msg: types.Message) -> str: @staticmethod
def generate_unique_id_by_msg(me: types.User, msg: types.Message) -> str:
user_id = me.id user_id = me.id
chat_id = msg.chat_id chat_id = msg.chat_id
msg_id = msg.id msg_id = msg.id