Skip to content

Commit eb767a9

Browse files
committed
initial commit
0 parents  commit eb767a9

3 files changed

Lines changed: 154 additions & 0 deletions

File tree

.github/workflows/main.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Telegram Auto Sign
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *'
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
run-checkin:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: 检出代码
17+
uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 0
20+
21+
- name: 配置 Python 环境
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: '3.10'
25+
26+
- name: 安装依赖
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install telethon
30+
31+
- name: 运行签到脚本
32+
env:
33+
API_ID: ${{ secrets.API_ID }}
34+
API_HASH: ${{ secrets.API_HASH }}
35+
SESSION_STRING: ${{ secrets.SESSION_STRING }}
36+
BOT_USERNAME: ${{ secrets.BOT_USERNAME }}
37+
run: python main.py
38+
39+
- name: 提交日志到 logs 分支
40+
run: |
41+
# 配置 Git 身份
42+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
43+
git config --local user.name "github-actions[bot]"
44+
45+
# 临时保存生成的日志文件内容
46+
LOG_CONTENT=$(cat checkin.log)
47+
48+
# 切换到 logs 分支
49+
git checkout logs || git checkout -b logs
50+
51+
# 将刚才运行生成的日志写回文件
52+
echo "$LOG_CONTENT" > checkin.log
53+
54+
# 提交并推送
55+
git add checkin.log
56+
git commit -m "Auto check-in log update: $(date +'%Y-%m-%d %H:%M:%S')" || echo "No changes to commit"
57+
git push origin logs

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# 🤖 Telegram Auto Sign
2+
3+
An automated daily sign-in script for Telegram bots, powered by GitHub Actions and Python (Telethon). It uses your personal account (Userbot) to send sign-in commands (like `/qd`) to specified Telegram bots daily, completely freeing your hands.
4+
5+
## ✨ Core Features
6+
* **☁️ Zero-Cost Deployment**: Runs entirely on GitHub Actions. No need for a local server or VPS.
7+
* **👥 Multi-Bot Support**: Capable of sending sign-in commands to multiple bots sequentially.
8+
* **🎲 Smart Anti-Ban System**: Built-in 1~20 minutes randomized startup delay and random pauses between messages to prevent triggering Telegram's spam filters.
9+
* **📝 Auto-Log Keepalive**: Automatically writes sign-in results to `checkin.log` and pushes it to the repository after each run. This perfectly bypasses GitHub Actions' 60-day inactivity suspension rule.
10+
11+
## 🚀 Deployment Guide
12+
13+
### Step 1: Get API Credentials
14+
1. Log in to the [Telegram API Development Tools](https://my.telegram.org/).
15+
2. Create a new application.
16+
3. Note down your `App api_id` and `App api_hash`.
17+
18+
### Step 2: Get Session String
19+
Install the dependency (`pip install telethon`) on your local machine and run a script to generate your session string.
20+
> ⚠️ **WARNING**: Treat your Session String like a password. NEVER share it publicly!
21+
22+
### Step 3: Configure GitHub Repository Secrets
23+
1. Create a **Private** repository (Highly recommended for security).
24+
2. Go to `Settings` -> `Secrets and variables` -> `Actions`, and add the following 4 **Repository secrets**:
25+
* `API_ID`: Your API ID (Numbers only).
26+
* `API_HASH`: Your API Hash string.
27+
* `SESSION_STRING`: The extremely long session string generated in Step 2.
28+
* `BOT_USERNAME`: The target bot usernames, separated by commas (e.g., `@bot1, @bot2`).
29+
30+
### Step 4: Grant Action Permissions
31+
To allow the script to push the log file back to the repository:
32+
1. Go to `Settings` -> `Actions` -> `General`.
33+
2. Scroll down to **Workflow permissions**.
34+
3. Select **Read and write permissions** and click `Save`.
35+
36+
### Step 5: First Run & Test
37+
Go to the **Actions** tab, select the `Telegram Auto Sign` workflow on the left, and click `Run workflow` to test it manually. If successful, your account will send the commands, and a log file will appear in your repository!
38+
39+
---
40+
41+
## ⏱️ Schedule Modification
42+
The default trigger time is **00:00 UTC daily**.
43+
To modify this, edit the cron expression in the `.github/workflows/checkin.yml` file.
44+
45+
## ⚠️ Disclaimer
46+
This script is for educational and automated testing purposes only. Do not use it for high-frequency spamming or violating Telegram's Terms of Service. The user bears all responsibility for any account restrictions or bans caused by API abuse.

main.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import os
2+
import asyncio
3+
import random
4+
from datetime import datetime, timezone, timedelta
5+
from telethon import TelegramClient
6+
from telethon.sessions import StringSession
7+
8+
# 读取环境变量
9+
API_ID = int(os.environ['API_ID'])
10+
API_HASH = os.environ['API_HASH']
11+
SESSION_STRING = os.environ['SESSION_STRING']
12+
BOT_USERNAMES = os.environ['BOT_USERNAME']
13+
14+
async def main():
15+
delay_seconds = random.randint(10, 1200)
16+
await asyncio.sleep(delay_seconds)
17+
18+
print("🔄 正在连接 Telegram 服务器...")
19+
client = TelegramClient(StringSession(SESSION_STRING), API_ID, API_HASH)
20+
await client.start()
21+
print("✅ 登录成功!\n")
22+
23+
bot_list = [bot.strip() for bot in BOT_USERNAMES.split(',')]
24+
success_bots = []
25+
26+
for bot in bot_list:
27+
if bot:
28+
print(f"👉 正在向 {bot} 发送签到指令 /qd ...")
29+
await client.send_message(bot, '/qd')
30+
success_bots.append(bot)
31+
32+
sleep_time = random.randint(2, 5)
33+
await asyncio.sleep(sleep_time)
34+
35+
print("\n🎉 所有签到指令发送完毕!")
36+
await client.disconnect()
37+
38+
# 获取东八区时间 (北京时间)
39+
tz = timezone(timedelta(hours=8))
40+
current_time = datetime.now(tz).strftime('%Y-%m-%d %H:%M:%S')
41+
42+
# 拼接日志内容
43+
log_msg = f"[{current_time}] 成功向 {', '.join(success_bots)} 发送签到指令 (随机延迟了 {delay_seconds} 秒)。\n"
44+
45+
# 追加写入到 checkin.log 文件中
46+
with open('checkin.log', 'a', encoding='utf-8') as f:
47+
f.write(log_msg)
48+
print("📝 运行日志已成功写入 checkin.log")
49+
50+
if __name__ == '__main__':
51+
asyncio.run(main())

0 commit comments

Comments
 (0)