commit
0272bd466a
5 changed files with 192 additions and 0 deletions
@ -0,0 +1,6 @@ |
|||||
|
FROM python:3.10 |
||||
|
RUN python -m pip install glQiwiApi aiohttp |
||||
|
ENV PYTHONUNBUFFERED 1 |
||||
|
WORKDIR /app |
||||
|
COPY ./ ./ |
||||
|
ENTRYPOINT ["python", "paybot.facti13.py"] |
@ -0,0 +1,56 @@ |
|||||
|
import aiohttp, os, sys |
||||
|
from colors import * |
||||
|
import traceback |
||||
|
|
||||
|
class BackendClient: |
||||
|
up = False |
||||
|
warn = False |
||||
|
|
||||
|
def __init__(self): |
||||
|
if not os.getenv("BACKEND_URL", ""): |
||||
|
error("BACKEND_URL not setted in env") |
||||
|
sys.exit(10) |
||||
|
if not os.getenv("SECRET_KEY", ""): |
||||
|
error("SECRET_KEY not setted in env") |
||||
|
sys.exit(11) |
||||
|
self.secret_key = os.getenv("SECRET_KEY") |
||||
|
self.pulse_url = f"{os.getenv('BACKEND_URL')}/api/pulse" |
||||
|
self.vip_url = f"{os.getenv('BACKEND_URL')}/api/external/vip" |
||||
|
|
||||
|
async def pulse(self): |
||||
|
async with aiohttp.ClientSession(cookies={ |
||||
|
"secretkey":self.secret_key}) as session: |
||||
|
async with session.get(self.pulse_url, ssl=False) as response: |
||||
|
try: |
||||
|
await response.text() |
||||
|
self.up = True |
||||
|
if not self.warn: |
||||
|
info("Backend connected!") |
||||
|
self.warn = True |
||||
|
except: |
||||
|
error("Backend not respond") |
||||
|
traceback.print_exc() |
||||
|
self.up = False |
||||
|
self.warn = False |
||||
|
return self.up |
||||
|
|
||||
|
async def vip(self, steamid, amount: int, extra: str): |
||||
|
async with aiohttp.ClientSession(cookies={ |
||||
|
"secretkey":self.secret_key}) as session: |
||||
|
async with session.post(self.vip_url + f"?steam={steamid}&amount={int(amount)}&service=steam&extra={extra}", ssl=False) as response: |
||||
|
try: |
||||
|
result = int(await response.text()) |
||||
|
if result == 0: |
||||
|
warning(f"[S64:{steamid}] VIP as not be added, maybe permition already exists") |
||||
|
return 99 |
||||
|
elif result > 0: |
||||
|
info(f"[S64:{steamid}] VIP has be added!") |
||||
|
return 100 |
||||
|
elif result < 0: |
||||
|
info(f"[S64:{steamid}] VIP has be extends!") |
||||
|
return 101 |
||||
|
except: |
||||
|
error(f"[S64:{steamid}] Backend returned error") |
||||
|
traceback.print_exc() |
||||
|
return False |
||||
|
return False |
@ -0,0 +1,29 @@ |
|||||
|
from time import strftime |
||||
|
|
||||
|
class colors: |
||||
|
HEADER = u'\033[95m' |
||||
|
OKBLUE = u'\033[94m' |
||||
|
OKGREEN = u'\033[92m' |
||||
|
WARNING = u'\033[93m' |
||||
|
FAIL = u'\033[91m' |
||||
|
ENDC = u'\033[0m' |
||||
|
BOLD = u'\033[1m' |
||||
|
UNDERLINE = u'\033[4m' |
||||
|
|
||||
|
HEADER = u"[{:^7}] ({:^17}) {}" |
||||
|
|
||||
|
def ok(text): |
||||
|
HEAD = colors.OKGREEN + u"OK" + colors.ENDC |
||||
|
return print(HEADER.format(HEAD, strftime(u"%H:%M:%S %d.%m.%y"), text)) |
||||
|
|
||||
|
def error(text): |
||||
|
HEAD = colors.FAIL + u"FAIL" + colors.ENDC |
||||
|
return print(HEADER.format(HEAD, strftime(u"%H:%M:%S %d.%m.%y"), text)) |
||||
|
|
||||
|
def warning(text): |
||||
|
HEAD = colors.WARNING + u"WARNING" + colors.ENDC |
||||
|
return print(HEADER.format(HEAD, strftime(u"%H:%M:%S %d.%m.%y"), text)) |
||||
|
|
||||
|
def info(text): |
||||
|
HEAD = colors.HEADER + u"INFO" + colors.ENDC |
||||
|
return print(HEADER.format(HEAD, strftime(u"%H:%M:%S %d.%m.%y"), text)) |
@ -0,0 +1,14 @@ |
|||||
|
FROM python:3.10 |
||||
|
RUN python -m pip install glQiwiApi aiohttp |
||||
|
WORKDIR /app |
||||
|
|
||||
|
ENV TZ=Europe/Moscow |
||||
|
ENV PYTHONUNBUFFERED 1 |
||||
|
RUN mkdir /home/service && \ |
||||
|
cp /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \ |
||||
|
dpkg-reconfigure -f noninteractive tzdata |
||||
|
|
||||
|
ARG BUILDDATE |
||||
|
ENV BUILDDATE $BUILDDATE |
||||
|
RUN echo $BUILDDATE && cd /tmp && git clone https://git.pblr-nyk.pro/gsd/Facti13.QiwiBot.v2 && cp -a Facti13.QiwiBot.v2/. /app && rm -r Facti13.QiwiBot.v2 |
||||
|
ENTRYPOINT ["python", "bot.py"] |
@ -0,0 +1,87 @@ |
|||||
|
from locale import currency |
||||
|
from glQiwiApi import QiwiWallet |
||||
|
from glQiwiApi.core.event_fetching import executor |
||||
|
from glQiwiApi.core.event_fetching.dispatcher import QiwiDispatcher |
||||
|
from glQiwiApi.core.event_fetching.executor import Context |
||||
|
from glQiwiApi.core.event_fetching.filters import ExceptionFilter |
||||
|
from glQiwiApi.qiwi.clients.wallet.types import Transaction, TransactionType, TransactionStatus |
||||
|
from glQiwiApi.qiwi.exceptions import QiwiAPIError |
||||
|
|
||||
|
from backend_integration import BackendClient |
||||
|
from colors import * |
||||
|
import os, sys |
||||
|
|
||||
|
prices = { |
||||
|
20.0: 1*24*60*60, |
||||
|
75.0: 7*24*60*60, |
||||
|
150.0: 30*24*60*60 |
||||
|
} |
||||
|
|
||||
|
def price_checker(amount): |
||||
|
seconds2give = 0 |
||||
|
for rub, sec in prices.items(): |
||||
|
if amount >= rub: |
||||
|
seconds2give = sec |
||||
|
return seconds2give |
||||
|
|
||||
|
class Client: |
||||
|
wallet: QiwiWallet |
||||
|
qiwi_dp: QiwiDispatcher |
||||
|
backend: BackendClient |
||||
|
|
||||
|
def __init__(self): |
||||
|
if not os.getenv("BACKEND_URL", "") or not os.getenv("SECRET_KEY", ""): |
||||
|
error("BACKEND_URL or SECRET_KEY is not setted!") |
||||
|
sys.exit(1) |
||||
|
if not os.getenv("QIWI_APIKEY", "") or not os.getenv("QIWI_PHONENUMBER", ""): |
||||
|
error("QIWI_APIKEY or QIWI_PHONENUMBER in not setted!") |
||||
|
sys.exit(2) |
||||
|
|
||||
|
self.backend = BackendClient() |
||||
|
self.qiwi_dp = QiwiDispatcher() |
||||
|
self.wallet = QiwiWallet(api_access_token=os.getenv("QIWI_APIKEY"), phone_number=os.getenv("QIWI_PHONENUMBER")) |
||||
|
|
||||
|
def run(self): |
||||
|
executor.start_polling(self.wallet, self.qiwi_dp, on_startup=self.on_startup) |
||||
|
|
||||
|
async def on_startup(self, ctx: Context): |
||||
|
print(await self.wallet.get_balance()) |
||||
|
await self.backend.pulse() |
||||
|
|
||||
|
def build_handler(self): |
||||
|
@self.qiwi_dp.transaction_handler() |
||||
|
async def handle_transaction(t: Transaction, ctx: Context): |
||||
|
if t.type != Transaction.type == TransactionType.IN: |
||||
|
return |
||||
|
if t.status != TransactionStatus.SUCCESS: |
||||
|
return |
||||
|
######################################## |
||||
|
currency = t.sum.currency |
||||
|
if str(currency) != "643":#643-rub code |
||||
|
warning(f"[{t.id}] currency not be rub, drop") |
||||
|
return |
||||
|
######################################## |
||||
|
money = t.sum.amount |
||||
|
seconds = price_checker(money) |
||||
|
if seconds == 0: |
||||
|
warning(f"[{t.id}] so smol donate {money} RUB") |
||||
|
return |
||||
|
######################################## |
||||
|
splitted = t.comment.split() |
||||
|
steam2 = None |
||||
|
for maybe_steam in splitted: |
||||
|
if "STEAM_" in maybe_steam.upper(): |
||||
|
steam2 = maybe_steam.upper() |
||||
|
break |
||||
|
if steam2 is None: |
||||
|
warning(f"[{t.id}] comment not contain steam {t.comment} RUB") |
||||
|
return |
||||
|
######################################## |
||||
|
# add vip |
||||
|
info(f"Add vip {steam2}, amount {seconds}") |
||||
|
#await self.backend.vip(steam2, seconds, f"rub={int(money)}") |
||||
|
|
||||
|
if __name__ == "__main__": |
||||
|
print("Build date: "+os.getenv("BUILDDATE", "not setted")) |
||||
|
client = Client() |
||||
|
client.run() |
Loading…
Reference in new issue