klaim reward BP harian (claim service V32-V34) + kill-switch DISTRIBUTE_ENABLED (V35) + Telegram dua kanal komunitas/internal (V30/V36) + placement web/scan/dist/claim != server2U
This commit is contained in:
1 parent
d3a0e768a0
commit
b1e6e93796
14 files changed
+878
-72
No files matched your search
+50
-14
@@ -1,21 +1,29 @@
|
||||
"""Kirim notifikasi status distribusi via Telegram Bot API (best-effort).
|
||||
"""Kirim notifikasi status distribusi + klaim via Telegram Bot API (best-effort).
|
||||
|
||||
Token + daftar chat id dari env (`TELEGRAM_BOT_TOKEN`, `TELEGRAM_CHAT_IDS`
|
||||
CSV) via `config.py`. Tanpa token/daftar → no-op senyap (⊥ ganggu run lokal).
|
||||
Gagal kirim hanya dicatat — ⊥ pernah crash distribusi.
|
||||
Dua kanal (V30/V36): KOMUNITAS (`TELEGRAM_COMMUNITY_CHAT_IDS`) hanya brief
|
||||
mulai/selesai distribusi; INTERNAL (`TELEGRAM_INTERNAL_CHAT_IDS`) detail
|
||||
distribusi + semua kegagalan + klaim reward (⊥ komunitas). Token tunggal
|
||||
`TELEGRAM_BOT_TOKEN`. Tanpa token/daftar → kanal itu no-op senyap (⊥ ganggu
|
||||
run). Gagal kirim hanya dicatat — ⊥ pernah crash distribusi/klaim.
|
||||
"""
|
||||
|
||||
import requests
|
||||
|
||||
from config import TELEGRAM_BOT_TOKEN, TELEGRAM_CHAT_IDS
|
||||
from config import (TELEGRAM_BOT_TOKEN, TELEGRAM_COMMUNITY_CHAT_IDS,
|
||||
TELEGRAM_INTERNAL_CHAT_IDS)
|
||||
|
||||
|
||||
def send_text(text):
|
||||
"""Kirim `text` ke semua chat id tujuan. Best-effort: gagal → log saja."""
|
||||
if not TELEGRAM_BOT_TOKEN or not TELEGRAM_CHAT_IDS:
|
||||
def send_text(text, chat_ids=None):
|
||||
"""Kirim `text` ke daftar chat id. `chat_ids=None` → kanal komunitas.
|
||||
|
||||
Best-effort: tanpa token/daftar → no-op; gagal → log saja.
|
||||
"""
|
||||
if chat_ids is None:
|
||||
chat_ids = TELEGRAM_COMMUNITY_CHAT_IDS
|
||||
if not TELEGRAM_BOT_TOKEN or not chat_ids:
|
||||
return
|
||||
url = f'https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage'
|
||||
for chat_id in TELEGRAM_CHAT_IDS:
|
||||
for chat_id in chat_ids:
|
||||
try:
|
||||
resp = requests.post(url, json={'chat_id': chat_id, 'text': text},
|
||||
timeout=10)
|
||||
@@ -25,9 +33,15 @@ def send_text(text):
|
||||
flush=True)
|
||||
|
||||
|
||||
def send_internal(text):
|
||||
"""Kirim ke kanal internal (detail + kegagalan + klaim)."""
|
||||
send_text(text, TELEGRAM_INTERNAL_CHAT_IDS)
|
||||
|
||||
|
||||
def notify_start(run_date, n_voters, total_share, balance):
|
||||
"""Notifikasi run nyata dimulai (setelah guard no-op + key siap)."""
|
||||
send_text(
|
||||
"""Run nyata dimulai: komunitas brief + internal detail."""
|
||||
send_text(f'DISTRIBUSI MULAI\nTanggal: {run_date}')
|
||||
send_internal(
|
||||
f'DISTRIBUSI MULAI\n'
|
||||
f'Tanggal: {run_date}\n'
|
||||
f'Pemilih: {n_voters}\n'
|
||||
@@ -37,8 +51,13 @@ def notify_start(run_date, n_voters, total_share, balance):
|
||||
|
||||
|
||||
def notify_finish(status, sent, total, total_share, failed, run_date):
|
||||
"""Notifikasi run selesai dengan ringkasan (ok | partial)."""
|
||||
"""Run selesai: komunitas brief + internal detail (ok | partial)."""
|
||||
send_text(
|
||||
f'DISTRIBUSI SELESAI\n'
|
||||
f'Tanggal: {run_date}\n'
|
||||
f'Status: {status}'
|
||||
)
|
||||
send_internal(
|
||||
f'DISTRIBUSI SELESAI\n'
|
||||
f'Tanggal: {run_date}\n'
|
||||
f'Status: {status}\n'
|
||||
@@ -49,8 +68,25 @@ def notify_finish(status, sent, total, total_share, failed, run_date):
|
||||
|
||||
|
||||
def notify_failure(exc):
|
||||
"""Notifikasi run gagal total (exception di main)."""
|
||||
send_text(
|
||||
"""Run gagal total — kanal internal saja (ops detail)."""
|
||||
send_internal(
|
||||
f'DISTRIBUSI GAGAL\n'
|
||||
f'Error: {exc}'
|
||||
)
|
||||
|
||||
|
||||
def notify_claim(reward, fee, wallet):
|
||||
"""Klaim reward BP sukses — kanal internal saja, ⊥ komunitas (V36)."""
|
||||
send_internal(
|
||||
f'KLAIM REWARD SUKSES\n'
|
||||
f'Reward: {reward} VEX\n'
|
||||
f'Fee BP: {fee} VEX → {wallet}'
|
||||
)
|
||||
|
||||
|
||||
def notify_claim_failure(exc):
|
||||
"""Kegagalan siklus klaim — kanal internal saja (V36)."""
|
||||
send_internal(
|
||||
f'KLAIM GAGAL\n'
|
||||
f'Error: {exc}'
|
||||
)
|
||||
Reference in new issue
Block a user