Skip to content

Commit

Permalink
Merge branch 'main' of [email protected]:mikeybob/tgworker.git
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeybob committed Aug 7, 2024
2 parents ad16623 + ec7ef39 commit 93faa10
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 43 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/UpstreamSync.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: tgworker-sync

on: push

on:
push:
schedule:
- cron: "05 */3 * * *" # Every 3 hours at 0005, 0605, 1205, 1805
jobs:
tgworker-sync:
runs-on: ubuntu-latest # Use a suitable runner for your workflow
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,5 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
last_read_message_id.json
t.sh
*.sh
*.bat
Binary file modified 27437823session_name.session.enc
Binary file not shown.
Binary file modified 29614663session_name.session.enc
Binary file not shown.
3 changes: 0 additions & 3 deletions encoder.sh

This file was deleted.

43 changes: 6 additions & 37 deletions reset.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
from telethon import TelegramClient
import os
from vendor.class_bot import LYClass # 导入 LYClass




# 检查是否在本地开发环境中运行
if not os.getenv('GITHUB_ACTIONS'):
Expand All @@ -14,40 +10,13 @@
api_id = os.getenv('API_ID')
api_hash = os.getenv('API_HASH')
phone_number = os.getenv('PHONE_NUMBER')
pw2fa = os.getenv('PW2FA')
session_name = api_id + 'session_name' # 确保与上传的会话文件名匹配

session_file = session_name + '.session'
if os.path.exists(session_file):
os.remove(session_file)

# 创建客户端
client = TelegramClient(session_name, api_id, api_hash)


try:
config = {
'api_id': os.getenv('API_ID'),
'api_hash': os.getenv('API_HASH'),
'phone_number': os.getenv('PHONE_NUMBER'),
'session_name': os.getenv('API_ID') + 'session_name',
'work_bot_id': os.getenv('WORK_BOT_ID'),
'work_chat_id': int(os.getenv('WORK_CHAT_ID', 0)), # 默认值为0
'public_bot_id': os.getenv('PUBLIC_BOT_ID'),
'warehouse_chat_id': int(os.getenv('WAREHOUSE_CHAT_ID', 0)), # 默认值为0
'link_chat_id': int(os.getenv('LINK_CHAT_ID', 0))
}

# 创建 LYClass 实例
tgbot = LYClass(client,config)


except ValueError:
print("Environment variable WORK_CHAT_ID or WAREHOUSE_CHAT_ID is not a valid integer.")
exit(1)

#max_process_time 設為 1200 秒,即 20 分鐘
max_process_time = 1200 # 20分钟
max_media_count = 25 # 10个媒体文件
max_count_per_chat = 5 # 每个对话的最大消息数

async def main():
await client.start(phone_number)

with client:
client.loop.run_until_complete(main())
client.start(phone=phone_number, password=pw2fa)
66 changes: 66 additions & 0 deletions sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from telethon import TelegramClient
import os
from vendor.class_bot import LYClass # 导入 LYClass




# 检查是否在本地开发环境中运行
if not os.getenv('GITHUB_ACTIONS'):
from dotenv import load_dotenv
load_dotenv()

# 从环境变量中获取值
api_id = os.getenv('API_ID')
api_hash = os.getenv('API_HASH')
phone_number = os.getenv('PHONE_NUMBER')
session_name = api_id + 'session_name' # 确保与上传的会话文件名匹配

# 创建客户端
client = TelegramClient(session_name, api_id, api_hash)


try:
config = {
'api_id': os.getenv('API_ID'),
'api_hash': os.getenv('API_HASH'),
'phone_number': os.getenv('PHONE_NUMBER'),
'session_name': os.getenv('API_ID') + 'session_name',
'work_bot_id': os.getenv('WORK_BOT_ID'),
'work_chat_id': int(os.getenv('WORK_CHAT_ID', 0)), # 默认值为0
'public_bot_id': os.getenv('PUBLIC_BOT_ID'),
'warehouse_chat_id': int(os.getenv('WAREHOUSE_CHAT_ID', 0)), # 默认值为0
'link_chat_id': int(os.getenv('LINK_CHAT_ID', 0))
}

# 创建 LYClass 实例
tgbot = LYClass(client,config)


except ValueError:
print("Environment variable WORK_CHAT_ID or WAREHOUSE_CHAT_ID is not a valid integer.")
exit(1)

#max_process_time 設為 1200 秒,即 20 分鐘
max_process_time = 1200 # 20分钟
max_media_count = 25 # 10个媒体文件
max_count_per_chat = 5 # 每个对话的最大消息数

async def main():
await client.start(phone_number)

botlist = [7452636047,7075620315,6588695181,6373803154,6086006554]


for bot_id in botlist:
try:
await tgbot.client.send_message(bot_id, "/start")
await tgbot.client.send_message(bot_id, str(bot_id))
except Exception as e:
print(f"Error sending message to work_bot_id: {e}")
continue



with client:
client.loop.run_until_complete(main())
11 changes: 11 additions & 0 deletions tgworker.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"folders": [
{
"path": "."
},
{
"path": "../lybot"
}
],
"settings": {}
}

0 comments on commit 93faa10

Please sign in to comment.