feat: initial bot orchestrator with AI integration
This commit is contained in:
93
main.py
Normal file
93
main.py
Normal file
@@ -0,0 +1,93 @@
|
||||
import os
|
||||
import time
|
||||
import random
|
||||
import requests
|
||||
import schedule
|
||||
from dotenv import load_dotenv
|
||||
from ai_generator import generate_bot_data
|
||||
|
||||
load_dotenv()
|
||||
|
||||
BACKEND_URL = os.getenv("BACKEND_URL", "http://localhost:3001/api")
|
||||
BOT_SECRET = os.getenv("BOT_API_SECRET", "")
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"x-bot-api-key": BOT_SECRET
|
||||
}
|
||||
|
||||
def log(msg):
|
||||
print(f"[BOT] {time.strftime('%Y-%m-%d %H:%M:%S')} - {msg}")
|
||||
|
||||
def run_daily_simulation():
|
||||
log("=== Memulai Simulasi Transaksi Harian ===")
|
||||
|
||||
# 1. Generate Data AI
|
||||
log("Generating data using AI...")
|
||||
ai_data = generate_bot_data()
|
||||
|
||||
# 2. Setup Accounts (Akun 1 & Akun 2)
|
||||
log("Step 1: Setup Accounts")
|
||||
# TODO: Panggil API Backend
|
||||
req1 = requests.post(f"{BACKEND_URL}/bot/setup-account", json={"data": ai_data}, headers=headers)
|
||||
if req1.status_code != 200:
|
||||
log(f"Failed to setup accounts: {req1.text}")
|
||||
return
|
||||
res_data1 = req1.json()
|
||||
provider_id = res_data1['data']['user1']['providerProfile']['id']
|
||||
buyer_id = res_data1['data']['user2']['id']
|
||||
log(f"Accounts created! ProviderID: {provider_id}, BuyerID: {buyer_id}")
|
||||
|
||||
# Delay acak agar terlihat natural (misal: 10 - 30 menit)
|
||||
delay_minutes = random.randint(10, 30)
|
||||
log(f"Menunggu {delay_minutes} menit sebelum membuat layanan...")
|
||||
# time.sleep(delay_minutes * 60) # Uncomment in production
|
||||
|
||||
# 3. Create Service
|
||||
log("Step 2: Create Service")
|
||||
# TODO: Panggil API Backend
|
||||
req2 = requests.post(f"{BACKEND_URL}/bot/create-service", json={
|
||||
"providerId": provider_id,
|
||||
"data": ai_data
|
||||
}, headers=headers)
|
||||
if req2.status_code != 200:
|
||||
log(f"Failed to create service: {req2.text}")
|
||||
return
|
||||
res_data2 = req2.json()
|
||||
service_id = res_data2['data']['id']
|
||||
log(f"Service created! ServiceID: {service_id}")
|
||||
|
||||
# Delay tunggu pesanan (misal: 1 - 3 jam)
|
||||
delay_hours = random.randint(1, 3)
|
||||
log(f"Menunggu {delay_hours} jam sebelum simulasi order...")
|
||||
# time.sleep(delay_hours * 3600) # Uncomment in production
|
||||
|
||||
# 4. Simulate Transaction & Payment
|
||||
log("Step 3: Place Order & Skip Payment")
|
||||
# TODO: Panggil API Backend
|
||||
req3 = requests.post(f"{BACKEND_URL}/bot/simulate-transaction", json={
|
||||
"buyerId": buyer_id,
|
||||
"providerId": provider_id,
|
||||
"serviceId": service_id,
|
||||
"data": ai_data
|
||||
}, headers=headers)
|
||||
if req3.status_code != 200:
|
||||
log(f"Failed to simulate transaction: {req3.text}")
|
||||
return
|
||||
res_data3 = req3.json()
|
||||
log(f"Transaction Simulated Successfully! OrderID: {res_data3['data']['orderId']}")
|
||||
|
||||
log("=== Simulasi Selesai ===")
|
||||
|
||||
if __name__ == "__main__":
|
||||
log("Bot Juaskill Started!")
|
||||
|
||||
# Jadwalkan bot untuk jalan 1 kali setiap hari di jam random antara 08:00 - 10:00 pagi
|
||||
# Untuk testing, kita jalankan langsung 1x
|
||||
run_daily_simulation()
|
||||
|
||||
# Uncomment untuk menjalankan scheduler
|
||||
# schedule.every().day.at("09:00").do(run_daily_simulation)
|
||||
# while True:
|
||||
# schedule.run_pending()
|
||||
# time.sleep(60)
|
||||
Reference in New Issue
Block a user