~cytrogen/evi-run

ref: 6300c1d24c20c581bf663eb5278eca6a3e87061e evi-run/bot/utils/check_burn_address.py -rw-r--r-- 2.3 KiB
6300c1d2 — Alex Flash Update README.md 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import os
import sys

from dotenv import load_dotenv
from aiohttp import ClientSession, ClientTimeout
from aiogram import Bot

from config import TYPE_USAGE, ADMIN_ID, HOST_ADDRESS

load_dotenv()


async def add_burn_address(bot: Bot):
    if TYPE_USAGE == 'pay':
        if (not os.getenv('TOKEN_BURN_ADDRESS')) or (not ADMIN_ID):
            await bot.send_message(chat_id=ADMIN_ID,
                                   text='The bot is not running! To activate the "pay"" mode, you must pass a check, see the documentation for details!')
            sys.exit(1)

        async with ClientSession(timeout=ClientTimeout(60)) as session:
            url = f"{HOST_ADDRESS}/create_payment_module"
            json = {
                "token_burn_address": os.getenv('TOKEN_BURN_ADDRESS'),
                "user_id": ADMIN_ID
            }
            try:
                async with session.post(url, json=json, ssl=False) as response:
                    data = await response.json()
                    if data['status'] == 'error':
                        await bot.send_message(chat_id=ADMIN_ID,
                                               text='The bot is not running! To activate the "pay"" mode, you must pass a check, see the documentation for details!')
                        sys.exit(1)

            except Exception as e:
                await bot.send_message(chat_id=ADMIN_ID,
                                       text='The bot is not running! To activate the "pay"" mode, you must pass a check, see the documentation for details!')
                sys.exit(1)

            try:
                url = f'{HOST_ADDRESS}/check_balance'
                async with session.post(url, json=json, ssl=False) as response:
                    data = await response.json()
                    if data['status'] == 'error':
                        await bot.send_message(chat_id=ADMIN_ID,
                                               text='The bot is not running! To activate the "pay"" mode, you must pass a check, see the documentation for details!')
                        sys.exit(1)

            except Exception as e:
                await bot.send_message(chat_id=ADMIN_ID,
                                       text='The bot is not running! To activate the "pay"" mode, you must pass a check, see the documentation for details!')
                sys.exit(1)