修改了消息发送对象读取的逻辑,现在是从数据库里读取了
This commit is contained in:
parent
093e8cbb5e
commit
f6f77f7c00
@ -7,7 +7,6 @@ import requests
|
||||
from aiohttp import ClientError
|
||||
|
||||
from src import logger
|
||||
from src.core.constant import BOT_TOKEN, GROUP_ID
|
||||
from src.core.login import login
|
||||
from src.core.message_client import send_message
|
||||
from src.entity.account import Account
|
||||
@ -59,14 +58,16 @@ def account_post(url: str, account: Account, params: dict) -> ApiResponse[Any]:
|
||||
except ClientError as e:
|
||||
logger.error(f"Client error occurred: {e}")
|
||||
except TimeoutError as e:
|
||||
logger.error(f"")
|
||||
send_message(BOT_TOKEN, GROUP_ID, f'{account.url}:加载超时,请检查是否后台更换了链接')
|
||||
logger.error(e)
|
||||
send_message(account.user.bot_token, account.user.group_id,
|
||||
f'{account.url}:加载超时,请检查是否后台更换了链接')
|
||||
except Exception as e:
|
||||
logger.error(f"Unknown error: {e}")
|
||||
|
||||
time.sleep(10)
|
||||
|
||||
send_message(BOT_TOKEN, GROUP_ID, f'{account.url}: Retry limit exceeded, please check the code')
|
||||
send_message(account.user.bot_token, account.user.group_id,
|
||||
f'{account.url}: Retry limit exceeded, please check the code')
|
||||
logger.error(f"{account.url}: Retry limit exceeded, please check the code")
|
||||
|
||||
|
||||
@ -88,5 +89,5 @@ async def async_account_post(url: str, account: Account, params: dict) -> ApiRes
|
||||
# Add a delay before retrying
|
||||
await asyncio.sleep(10)
|
||||
|
||||
send_message(BOT_TOKEN, GROUP_ID, f'{account.url}: Retry limit exceeded, please check the code')
|
||||
send_message(account.user.bot_token, account.user.group_id, f'{account.url}: Retry limit exceeded, please check the code')
|
||||
logger.error("Retry limit exceeded, please check the code")
|
||||
|
@ -10,12 +10,4 @@ PAY_RECORD_URL = '/agent/api/v1/payRecords/list'
|
||||
|
||||
PAY_RECORD_LIST_URL = '/agent/api/v1/member/payRecordList'
|
||||
|
||||
FINANCE_URL = '/agent/api/v1/finance/excel/total'
|
||||
|
||||
BOT_TOKEN = '6013830443:AAGzq1Tgtr_ZejU7bv0mab14xOwi0_64d0w'
|
||||
# 工作号id
|
||||
CHAT_ID = '6054562838'
|
||||
# 冲!群组id
|
||||
GROUP_ID = '-1002122455730'
|
||||
# 报数群组id
|
||||
COUNT_GROUP_ID = '-4062683798'
|
||||
FINANCE_URL = '/agent/api/v1/finance/excel/total'
|
@ -2,7 +2,6 @@ import time
|
||||
import schedule
|
||||
from loguru import logger
|
||||
|
||||
from src.core.constant import BOT_TOKEN, COUNT_GROUP_ID
|
||||
from src.core.message_client import send_message
|
||||
from src.core.util import get_curr_day
|
||||
from src.entity.finance import get_net_win_by_user
|
||||
@ -15,7 +14,7 @@ def job_count(username, password):
|
||||
try:
|
||||
logger.info(f'Running job_count for username: {username}')
|
||||
user = get_user_by_username_and_password(username, password)
|
||||
send_message(BOT_TOKEN, COUNT_GROUP_ID, text_count_by_user(user, get_curr_day()))
|
||||
send_message(user.bot_token, user.group_id, text_count_by_user(user, get_curr_day()))
|
||||
logger.info(f'Finished job_count for username: {username}')
|
||||
except Exception as e:
|
||||
logger.error(f'Error running job_count for username: {username}, Error: {e}')
|
||||
@ -25,7 +24,7 @@ def query_failed_deposit(username, password):
|
||||
try:
|
||||
logger.info(f'Running query_failed_deposit for username: {username}')
|
||||
user = get_user_by_username_and_password(username, password)
|
||||
send_message(BOT_TOKEN, COUNT_GROUP_ID, get_pay_failed_by_user(user, get_curr_day()))
|
||||
send_message(user.bot_token, user.count_group_id, get_pay_failed_by_user(user, get_curr_day()))
|
||||
logger.info(f'Finished query_failed_deposit for username: {username}')
|
||||
except Exception as e:
|
||||
logger.error(f'Error running query_failed_deposit for username: {username}, Error: {e}')
|
||||
@ -35,7 +34,7 @@ def query_net_win(username, password):
|
||||
try:
|
||||
logger.info(f'Running query_net_win for username: {username}')
|
||||
user = get_user_by_username_and_password(username, password)
|
||||
send_message(BOT_TOKEN, COUNT_GROUP_ID, get_net_win_by_user(user, date=get_curr_day()))
|
||||
send_message(user.bot_token, user.count_group_id, get_net_win_by_user(user, date=get_curr_day()))
|
||||
logger.info(f'Finished query_net_win for username: {username}')
|
||||
except Exception as e:
|
||||
logger.error(f'Error running query_net_win for username: {username}, Error: {e}')
|
||||
@ -43,7 +42,7 @@ def query_net_win(username, password):
|
||||
|
||||
if __name__ == '__main__':
|
||||
logger.info('Starting scheduled tasks')
|
||||
times = ['10:50', '14:40', '17:40', '20:40', '21:40', '23:59']
|
||||
times = ['20:11', '14:40', '17:40', '20:40', '21:40', '23:59']
|
||||
for time_str in times:
|
||||
schedule.every().day.at(time_str).do(job_count, 'zayac', '123456')
|
||||
schedule.every().day.at(time_str).do(query_net_win, 'zayac', '123456')
|
||||
|
@ -6,7 +6,7 @@ from typing import List
|
||||
from loguru import logger
|
||||
|
||||
from src.core.api_request import account_post
|
||||
from src.core.constant import BANNER_URL, BOT_TOKEN, GROUP_ID
|
||||
from src.core.constant import BANNER_URL
|
||||
from src.core.message_client import send_message
|
||||
from src.core.util import get_curr_day
|
||||
from src.entity.account import Account
|
||||
@ -60,7 +60,7 @@ def query_banner_info(account: Account):
|
||||
else:
|
||||
names = 'unknown'
|
||||
msg = f'👏 {account.name} 注册:{register_count} 用户: {names} 总数: {banner_info.registerMembers}'
|
||||
send_message(BOT_TOKEN, GROUP_ID, msg)
|
||||
send_message(account.user.bot_token, account.user.group_id, msg)
|
||||
logger.info(f'发送的消息: {msg}')
|
||||
|
||||
last_banner_info = banner_info
|
||||
@ -71,14 +71,14 @@ def query_banner_info(account: Account):
|
||||
msg = '\n'.join(
|
||||
[f"用户: `{member_detail.name}`, 首存金额: *{member_detail.deposit}*" for member_detail in
|
||||
member_details_list])
|
||||
send_message(BOT_TOKEN, GROUP_ID,
|
||||
send_message(account.user.bot_token, account.user.group_id,
|
||||
f'🎉 {account.name} 首存:{count} {msg} 总数:*{banner_info.firstDepositNum}*')
|
||||
logger.info(f'发送的消息: {msg}')
|
||||
|
||||
last_banner_info = banner_info
|
||||
time.sleep(60)
|
||||
except Exception as e:
|
||||
send_message(BOT_TOKEN, GROUP_ID, str(e))
|
||||
send_message(account.user.bot_token, account.user.group_id, str(e))
|
||||
logger.exception(f'发生未知错误:{e} ')
|
||||
time.sleep(10)
|
||||
return query_banner_info(account)
|
||||
|
@ -22,6 +22,7 @@ class User(db.Base):
|
||||
email: Mapped[str] = mapped_column(String(32), nullable=False, comment="邮箱")
|
||||
bot_token: Mapped[str] = mapped_column(String(64), nullable=True, comment="飞机机器人id")
|
||||
group_id: Mapped[str] = mapped_column(String(32), nullable=True, comment="消息群组id")
|
||||
count_group_id: Mapped[str] = mapped_column(String(32), nullable=True, comment="报数消息群组id")
|
||||
chat_id: Mapped[str] = mapped_column(String(32), nullable=True, comment="消息个人id")
|
||||
telegram_ids: Mapped[str] = mapped_column(String(128), nullable=True, comment="telegram_ids")
|
||||
status: Mapped[int] = mapped_column(TINYINT, nullable=False, comment='账号状态,0禁用,1启用', default=0)
|
||||
@ -47,7 +48,7 @@ def get_all_users():
|
||||
def get_user_by_telegram_id(telegram_id: int) -> User:
|
||||
with db.Session() as session:
|
||||
user = session.query(User).filter(
|
||||
and_(User.status == 1,func.find_in_set(telegram_id, User.telegram_ids) > 0)).one()
|
||||
and_(User.status == 1, func.find_in_set(telegram_id, User.telegram_ids) > 0)).one()
|
||||
# 过滤出所有状态为可用的账户,并将它们存储在 User 对象中
|
||||
user.accounts = [account for account in user.accounts if account.status == 1]
|
||||
user.accounts.sort(key=lambda account: account.type.value)
|
||||
|
Loading…
Reference in New Issue
Block a user