EARNING BOT -- SETUP GUIDE
==========================

Everything except the database connection is configured from the admin
panel after you upload these files. You do not need to edit any PHP file
other than config.php.

Requirements: PHP 8+ with the GD and curl extensions, a MySQL/MariaDB
database, and HTTPS on the domain you'll use (Telegram requires HTTPS for
both the bot webhook and the Mini App -- plain http:// will not work).


STEP 1 -- Upload the files
---------------------------
Upload everything in this zip to a folder on your site, e.g.
https://yourdomain.com/bot/  ->  the "earningbot" folder's contents go there.

Two folders need to be writable by PHP (your host may call this 755 or
777 depending on the server):
  - uploads/broadcasts/   (broadcast images you send from the admin panel)
That's the only one; nothing else writes to disk.


STEP 2 -- Create a database
-----------------------------
In your hosting control panel (cPanel, Plesk, etc.), create a new MySQL
database and a database user with full privileges on it. Write down:
  - the database host       (almost always "localhost")
  - the database name
  - the database username
  - the database password


STEP 3 -- Import schema.sql
------------------------------
Using phpMyAdmin (or your host's database tool), open the database you
just created and import the included schema.sql file. This creates all
the tables. It intentionally contains NO users, tasks, or channels --
those you add yourself once the bot is running -- but it DOES create:

  - one admin login:
        username: admin
        password: yHw79AwnnFQc99zY
    (change this the moment you log in -- see Step 6 below)

  - a default 7-day streak (Admin > Daily Streak), since that screen edits
    existing days rather than creating new ones. Edit the amounts, or turn
    days off, once you're in.


STEP 4 -- Edit config.php
----------------------------
Open config.php and fill in the database details from Step 2:

    define('DB_HOST', 'localhost');
    define('DB_NAME', 'your_database_name');
    define('DB_USER', 'your_database_user');
    define('DB_PASS', 'your_database_password');

Optionally set your timezone on the date_default_timezone_set(...) line.
That's the only file you need to touch.


STEP 5 -- Log in to the admin panel
--------------------------------------
Visit https://yourdomain.com/bot/admin/  and log in with the admin login
from Step 3. You'll land on the SETUP tab automatically the first time.


STEP 6 -- Connect your bot (Admin > Setup)
----------------------------------------------
1. If you haven't already, create a bot with @BotFather on Telegram and
   copy the token it gives you (looks like 123456789:AA...).
2. On the Setup tab, paste that token into "Bot Token".
3. Fill in "Site Domain" -- this folder's own address, no trailing slash,
   e.g. if this file loads at https://yourdomain.com/bot/tap.php, enter
   https://yourdomain.com/bot
4. Click "Save & Connect". It should say "Connected as @yourbotname".
5. Click "Register Webhook". This tells Telegram to send messages to your
   bot here. The panel shows the current webhook status so you can
   confirm it took.
6. Immediately below, change your admin password (Step 3 above used a
   generated one -- don't leave it as-is).


STEP 7 -- A few things only you can do inside Telegram
------------------------------------------------------------
These aren't things a script can do for you:

  - Required channels: add them in the Channels tab, then in Telegram
    itself, add THIS BOT as an ADMINISTRATOR of each channel. Without
    that, the bot cannot check who has joined, and verification will
    always fail.
  - Payout channel (optional): if you set Settings > Payout Channel ID,
    add the bot as admin there too.
  - FaucetPay / OxaPay: add your API key(s) under the Settings tab if
    you're paying out withdrawals. Nothing else needs configuring for
    these -- the payout callback URL is generated automatically from
    your Site Domain.


STEP 8 -- Cron jobs
----------------------
Three background jobs keep things running smoothly. Add these in your
host's cron manager (cPanel: Cron Jobs), replacing /full/path/to/bot with
this folder's real path on the server -- NOT the https:// URL. Your host
can tell you this path, or you can find it by creating a temporary PHP
file containing <?php echo __DIR__; and opening it in a browser once.

    # Marks OxaPay withdrawals as paid as soon as they're confirmed
    */5 * * * * php /full/path/to/bot/cron/sync_withdrawals.php

    # Sends queued broadcasts (only needed if a broadcast is still
    # sending when the admin page closes -- safe to run every minute)
    * * * * * php /full/path/to/bot/cron/broadcast_worker.php

    # Pays out the referral-contest leaderboard on its configured date
    0 * * * * php /full/path/to/bot/cron/distribute_ranks.php


STEP 9 -- Try it
-------------------
Send /start to your bot on Telegram. If nothing happens, go back to
Admin > Setup and check the webhook status box for an error.


THAT'S IT
---------
Everything else -- coin name/symbol, theme colors and font, energy
settings, tasks, the spin wheel, rank rewards, daily streak amounts,
required channels, withdrawal settings -- is configured from the other
tabs in the admin panel. None of it needs a file edit.
