Ejemplo n.º 1
0
    async def weekly(self, ctx: commands.context):
        a, b = 500, 800
        gift_code = "7d"

        session_ = sessionmaker(bind=engine.get_engine())
        session = session_()

        gift_stat = session.query(Gift).filter_by(owner=ctx.author.id,
                                                  type=gift_code).first()
        if gift_stat is None:
            gift_stat = Gift()
            gift_stat.owner = ctx.author.id
            gift_stat.type = gift_code
            gift_stat.date = datetime.now() + timedelta(days=7)

            session.add(gift_stat)
            session.commit()
            await gift(session, ctx, a, b)
        else:
            if gift_stat.date <= datetime.now():
                gift_stat.date = datetime.now() + timedelta(days=7)
                session.commit()
                await gift(session, ctx, a, b)
            else:
                await ctx.reply("아직 선물 상자가 도착하지 않았습니다")
Ejemplo n.º 2
0
    async def worker(self):
        session_ = sessionmaker(bind=engine.get_engine())
        session = session_()
        date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

        import coins
        for coin in coins.__all__:
            coin = getattr(coins, coin)

            ctx = session.query(Coin).filter_by(
                name=coin.NAME
            ).first()

            symbol = choice(['-', '+', '-', '+', '-'])
            old_price = ctx.price
            new_price = randint(coin.MIN_RANGE, coin.MAX_RANGE)

            if symbol == "+":
                ctx.price += new_price
            else:
                ctx.price -= new_price

            if ctx.price < coin.MIN_PRICE:
                ctx.price = coin.MIN_PRICE

            if coin.MAX_PRICE is not None:
                if ctx.price > coin.MAX_PRICE:
                    ctx.price = coin.MAX_PRICE

            with open("coin_update.csv", mode="a", encoding="utf-8") as fp:
                fp.write(f"{date}, {ctx.name}, {symbol}{new_price}, {old_price}, {ctx.price}\n")

        session.commit()
Ejemplo n.º 3
0
    async def wallet(self, ctx: commands.context):
        embed = Embed(
            title="지갑",
            color=0xF7F7F7
        )

        session_ = sessionmaker(bind=engine.get_engine())
        session = session_()

        point = session.query(Point).filter_by(
            owner=str(ctx.author.id)
        ).first()

        point = point.point if point is not None else -1

        embed.description = f"{ctx.author.name}님의 포인트 : {point} P"

        import coins
        for cn in session.query(Wallet).filter_by(
            owner=str(ctx.author.id)
        ).all():
            embed.add_field(
                name="{name} 코인 ({code})".format(
                    name=getattr(getattr(coins, cn.name), "DISPLAY_NAME"),
                    code=getattr(getattr(coins, cn.name), "NAME")
                ),
                value=f"{cn.count} 개"
            )

        await ctx.send(
            embed=embed
        )
Ejemplo n.º 4
0
    async def buy(self, ctx: commands.context, code: str, count: int = 1):
        session_ = sessionmaker(bind=engine.get_engine())
        session = session_()

        if count <= 0:
            count = 1

        cn = session.query(Coin).filter_by(name=code).first()
        if cn is None:
            await ctx.reply("등록된 코인이 아닙니다.")
        else:
            wl = session.query(Wallet).filter_by(name=code,
                                                 owner=str(
                                                     ctx.author.id)).first()

            if wl is None:
                wl = Wallet()
                wl.name = code
                wl.owner = str(ctx.author.id)
                wl.count = 0

                session.add(wl)

            wl_point = session.query(Point).filter_by(
                owner=str(ctx.author.id)).first()
            if wl_point is None:
                return await ctx.reply("먼저 포인트 지갑을 만들어야 합니다")

            if wl_point.point - (cn.price * count) >= 0:
                wl.count += count
                wl_point.point -= cn.price * count
                session.commit()

                await ctx.reply("구매 성공\n"
                                "```\n"
                                "-----------------------------------\n"
                                f"- 거래한 코인: {count} 개\n"
                                f"- 코인 거래 가격: {cn.price} P\n"
                                f"- 거래 후 보유중인 코인: {wl.count} 개\n"
                                "-----------------------------------\n"
                                f"- 변동 포인트 : -{cn.price * count} P\n"
                                f"- 거래 후 남은 포인트: {wl_point.point} P\n"
                                "-----------------------------------\n"
                                "```")
            else:
                await ctx.reply("구매 실패"
                                "```\n"
                                "-----------------------------------\n"
                                f"- 거래한 코인: 0 개\n"
                                f"- 코인 거래 가격: {cn.price} P\n"
                                f"- 거래 후 보유중인 코인: {wl.count} 개\n"
                                "-----------------------------------\n"
                                f"- 변동 포인트 : -0 P\n"
                                f"- 거래 후 남은 포인트: {wl_point.point} P\n"
                                "-----------------------------------\n"
                                "```")
Ejemplo n.º 5
0
    async def leaderboard(self, ctx: commands.context):
        embed = Embed(title="리더보드", color=0xF7F7F7)

        session_ = sessionmaker(bind=engine.get_engine())
        session = session_()

        for i, x in enumerate(
                session.query(Point).order_by(
                    Point.point.desc()).limit(25).all()):
            embed.add_field(name=f"{i + 1} 위",
                            value=f"{x.point} P",
                            inline=False)

        await ctx.send(embed=embed)
Ejemplo n.º 6
0
    async def shop(self, ctx: commands.context):
        embed = Embed(title="코인상점", color=0xF7F7F7)
        embed.set_footer(text="- 괄호안에 텍스트는 거래코드 입니다. (거래코드는 구매&판매 할 때 사용됨)\n"
                         "- 모든 코인에는 가격 변동 범위와 최소 가격, 최대 가격이 정해져 있습니다.")

        session_ = sessionmaker(bind=engine.get_engine())
        session = session_()

        import coins
        for coin in coins.__all__:
            cn = session.query(Coin).filter_by(
                name=getattr(getattr(coins, coin), "NAME")).first()

            embed.add_field(name="{name} 코인 ({code}){star}".format(
                name=getattr(getattr(coins, coin), "DISPLAY_NAME"),
                code=getattr(getattr(coins, coin), "NAME"),
                star="*"
                if getattr(getattr(coins, coin), "MAX_PRICE") is None else ""),
                            value=f"{cn.price} P")

        await ctx.send(embed=embed)
Ejemplo n.º 7
0
    async def create(self, ctx: commands.context):
        session_ = sessionmaker(bind=engine.get_engine())
        session = session_()

        point = session.query(Point).filter_by(
                owner=str(ctx.author.id)
        ).first()
        if point is not None:
            await ctx.reply(
                "**경고** 당신은 이미 포인트 지갑을 가지고 있습니다."
            )
        else:
            point = Point()
            point.owner = str(ctx.author.id)
            point.point = 0

            session.add(point)
            session.commit()

            await ctx.reply(
                "포인트 지갑 생성 완료"
            )
Ejemplo n.º 8
0
from sqlalchemy.orm import sessionmaker

from database import engine
from models import Coin
import coins

Session = sessionmaker(engine.get_engine())
session = Session()

for coin in coins.__all__:
    coin = getattr(coins, coin)

    c = session.query(Coin).filter_by(name=coin.NAME).first()
    if c is not None:
        c.price = coin.MIN_PRICE
    else:
        c = Coin()
        c.name = coin.NAME
        c.price = coin.MIN_PRICE

        session.add(c)
        session.commit()