From d6de4be848c4e9653d3f25fbbe643bf137fde176 Mon Sep 17 00:00:00 2001 From: 007 Date: Sat, 17 Jun 2023 00:51:15 +0330 Subject: [PATCH] feat: add charge code stuff --- bchat/models/__init__.py | 7 +++++-- bchat/models/shop.py | 18 ++++++++++++++++++ bchat/modules/admin/__init__.py | 6 ++++++ bchat/modules/admin/charge.py | 16 ++++++++++++++++ bchat/modules/{admin.py => admin/misc.py} | 5 ++--- 5 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 bchat/modules/admin/__init__.py create mode 100644 bchat/modules/admin/charge.py rename bchat/modules/{admin.py => admin/misc.py} (99%) diff --git a/bchat/models/__init__.py b/bchat/models/__init__.py index 956f808..1d4ee25 100644 --- a/bchat/models/__init__.py +++ b/bchat/models/__init__.py @@ -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 @@ -9,5 +10,7 @@ 'GENDER_DISPLAY', 'Genders', 'gender_keys', 'gender_pattern', 'UserTable', 'UserModel', - 'ShopModel', 'ShopTable', 'ItemType' + 'ShopModel', 'ShopTable', 'ItemType', + + 'ChargeCodeTable', 'ChargeCodeModel', ] diff --git a/bchat/models/shop.py b/bchat/models/shop.py index 6e3bff4..a8c6258 100644 --- a/bchat/models/shop.py +++ b/bchat/models/shop.py @@ -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 diff --git a/bchat/modules/admin/__init__.py b/bchat/modules/admin/__init__.py new file mode 100644 index 0000000..2574aa5 --- /dev/null +++ b/bchat/modules/admin/__init__.py @@ -0,0 +1,6 @@ + +from .misc import H_MISC + +HANDLERS_ADMIN = [ + *H_MISC +] diff --git a/bchat/modules/admin/charge.py b/bchat/modules/admin/charge.py new file mode 100644 index 0000000..e2652be --- /dev/null +++ b/bchat/modules/admin/charge.py @@ -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), +] diff --git a/bchat/modules/admin.py b/bchat/modules/admin/misc.py similarity index 99% rename from bchat/modules/admin.py rename to bchat/modules/admin/misc.py index fe3033a..2634c4d 100644 --- a/bchat/modules/admin.py +++ b/bchat/modules/admin/misc.py @@ -1,5 +1,4 @@ - import logging import random import time @@ -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 @@ -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 ...\n' '/user_score -> get the user score\n' '/user_score set 12 -> set the user used score\n' '/user_score set 12 total -> set the user total score\n' @@ -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),