Skip to content

Commit

Permalink
feat: add charge code stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
i007c committed Jun 16, 2023
1 parent d70dad0 commit d6de4be
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
7 changes: 5 additions & 2 deletions bchat/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .direct import DirectModel, DirectTable
from .shop import ItemType, ShopModel, ShopTable
from .shop import ChargeCodeModel, ChargeCodeTable, ItemType, ShopModel
from .shop import ShopTable
from .user import GENDER_DISPLAY, Genders, UserModel, UserTable, gender_keys
from .user import gender_pattern

Expand All @@ -9,5 +10,7 @@
'GENDER_DISPLAY', 'Genders', 'gender_keys', 'gender_pattern',
'UserTable', 'UserModel',

'ShopModel', 'ShopTable', 'ItemType'
'ShopModel', 'ShopTable', 'ItemType',

'ChargeCodeTable', 'ChargeCodeModel',
]
18 changes: 18 additions & 0 deletions bchat/models/shop.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ class ShopTable(BaseTable):
done = Column(Boolean, server_default=text('0'))


class ChargeCodeTable(BaseTable):
__tablename__ = 'charge_code'

cc_id = Column(Integer, primary_key=True, autoincrement=True)
amount = Column(Integer, nullable=False)
user_id = Column(Integer)
code = Column(String, nullable=False)
used = Column(Boolean, server_default=text('0'))


class ChargeCodeModel(BaseModel):
cc_id: int
amount: int
user_id: int = None
code: str
used: bool = False


class ItemType(int, Enum):
phone_charge = 0
channel_member = 1
Expand Down
6 changes: 6 additions & 0 deletions bchat/modules/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

from .misc import H_MISC

HANDLERS_ADMIN = [
*H_MISC
]
16 changes: 16 additions & 0 deletions bchat/modules/admin/charge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@


from deps import require_admin
from telegram import Update
from telegram.ext import CommandHandler, ContextTypes

Ctx = ContextTypes.DEFAULT_TYPE


@require_admin
async def add_charge_codes(update: Update, ctx: Ctx):
await update.effective_message.reply_text(' - '.join(ctx.args))

H_CHARGE = [
CommandHandler(['charge'], add_charge_codes),
]
5 changes: 2 additions & 3 deletions bchat/modules/admin.py → bchat/modules/admin/misc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


import logging
import random
import time
Expand All @@ -15,7 +14,6 @@
from telegram.error import Forbidden, NetworkError, RetryAfter, TelegramError
from telegram.error import TimedOut
from telegram.ext import CommandHandler, ContextTypes
from utils import config

Ctx = ContextTypes.DEFAULT_TYPE

Expand Down Expand Up @@ -106,6 +104,7 @@ async def help_cmd(update: Update, ctx: Ctx):
'/stats -> user count\n'
'/update_db -> only for developer\n'
'/seen_all -> seen all of your directs\n'
'/charge <Toman> <code> <code> ...\n'
'/user_score <code> -> get the user score\n'
'/user_score <code> set 12 -> set the user used score\n'
'/user_score <code> set 12 total -> set the user total score\n'
Expand Down Expand Up @@ -330,7 +329,7 @@ async def update_db(update: Update, ctx: Ctx):
await update.effective_message.reply_text('nothing to do.')


HANDLERS_ADMIN = [
H_MISC = [
CommandHandler(['stats'], stats),
CommandHandler(['update_db'], update_db, block=False),
CommandHandler(['seen_all'], seen_all),
Expand Down

0 comments on commit d6de4be

Please sign in to comment.