-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.py
36 lines (31 loc) · 1.15 KB
/
bot.py
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
from discord.ext import commands
from os import environ
from lib import db
from models import CryptoModel, Crypto
from sqlalchemy.engine.url import URL
import asyncio
class Cryptrans(commands.Bot):
def __init__(self) -> None:
super().__init__(command_prefix=commands.when_mentioned_or("vc."))
self.loop.create_task(self.init_db())
self.loop.create_task(self.give_hold_batch())
async def init_db(self):
await db.set_bind(
URL(
drivername="postgresql",
username=environ.get("POSTGRES_USER"),
password=environ.get("POSTGRES_PASSWORD"),
host="virtualcrypto_postgres",
port="5430",
database=environ.get("POSTGRES_DB")
)
)
await db.gino.create_all()
async def give_hold_batch(self):
await self.wait_until_ready()
while not self.is_closed():
await asyncio.sleep(60 * 10)
await asyncio.gather(
*[crypto.update(hold=Crypto.hold + crypto.per_amount).apply() for crypto in await CryptoModel().all()],
loop=self.loop
)