├── .gitignore ├── InDMCategories.py ├── InDMDevDB.py ├── LICENSE ├── README.md ├── config.env ├── purchase.py ├── requirements.txt └── store_main.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | # PyCharm 156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 160 | #.idea/ 161 | -------------------------------------------------------------------------------- /InDMCategories.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | from datetime import * 4 | from flask_session import Session 5 | import telebot 6 | from flask import Flask, request 7 | from telebot import types 8 | import os 9 | import os.path 10 | from InDMDevDB import * 11 | from dotenv import load_dotenv 12 | load_dotenv('config.env') 13 | 14 | # Bot connection 15 | bot = telebot.TeleBot(f"{os.getenv('TELEGRAM_BOT_TOKEN')}", threaded=False) 16 | StoreCurrency = f"{os.getenv('STORE_CURRENCY')}" 17 | 18 | class CategoriesDatas: 19 | def get_category_products(message, input_cate): 20 | id = message.from_user.id 21 | keyboard = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 22 | keyboard.row_width = 2 23 | buyer_id = message.from_user.id 24 | buyer_username = message.from_user.username 25 | all_categories = GetDataFromDB.GetCategoryIDsInDB() 26 | categories = [] 27 | for catnum, catname in all_categories: 28 | catnames = catname.upper() 29 | categories.append(catnames) 30 | 31 | def checkint(): 32 | try: 33 | input_cat = int(input_cate) 34 | return input_cat 35 | except: 36 | return input_cate 37 | input_category = checkint() 38 | if isinstance(input_category, int) == True: 39 | product_cate = GetDataFromDB.Get_A_CategoryName(input_category) 40 | if f"{product_cate}" in f"{categories}": 41 | product_category = product_cate.upper() 42 | product_list = GetDataFromDB.GetProductInfoByCTGName(product_category) 43 | print(product_list) 44 | if product_list == []: 45 | keyboard = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 46 | keyboard.row_width = 2 47 | key1 = types.KeyboardButton(text="Shop Items 🛒") 48 | key2 = types.KeyboardButton(text="My Orders 🛍") 49 | key3 = types.KeyboardButton(text="Support 📞") 50 | keyboard.add(key1) 51 | keyboard.add(key2, key3) 52 | bot.send_message(id, f"No Product in the store", reply_markup=keyboard) 53 | else: 54 | bot.send_message(id, f"{product_cate} Gategory's Products") 55 | keyboard = types.InlineKeyboardMarkup() 56 | for productnumber, productname, productprice, productdescription, productimagelink, productdownloadlink, productquantity, productcategory in product_list: 57 | keyboard.add(types.InlineKeyboardButton(text="BUY NOW 💰", callback_data=f"getproduct_{productnumber}")) 58 | bot.send_photo(id, photo=f"{productimagelink}", caption=f"Product ID 🪪: /{productnumber}\n\nProduct Name 📦: {productname}\n\nProduct Price 💰: {productprice} {StoreCurrency}\n\nProducts In Stock 🛍: {productquantity}\n\nProduct Description 💬: {productdescription}", reply_markup=keyboard) 59 | 60 | #bot.send_message(id, "💡 Click on a Product ID to select the product purchase") 61 | else: 62 | print("Wrong commmand !!!") 63 | -------------------------------------------------------------------------------- /InDMDevDB.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | from datetime import * 3 | import threading 4 | 5 | InDMDevDBShopDBFile = 'InDMDevDBShop.db' 6 | DBConnection = sqlite3.connect(InDMDevDBShopDBFile, check_same_thread=False) 7 | 8 | connected = DBConnection.cursor() 9 | lock = threading.Lock() 10 | 11 | class CreateTables: 12 | def __init__(self) -> None: 13 | pass 14 | 15 | def createtable(): 16 | #Create ShopUserTable Table 17 | connected.execute("""CREATE TABLE IF NOT EXISTS ShopUserTable( 18 | id SERIAL PRIMARY KEY, 19 | user_id int, 20 | username text, 21 | wallet int 22 | )""") 23 | #Create ShopAdminTable Table 24 | connected.execute("""CREATE TABLE IF NOT EXISTS ShopAdminTable( 25 | id SERIAL PRIMARY KEY, 26 | admin_id int, 27 | username text, 28 | wallet int 29 | )""") 30 | 31 | #Create ShopProductTable Table 32 | connected.execute("""CREATE TABLE IF NOT EXISTS ShopProductTable( 33 | id SERIAL PRIMARY KEY, 34 | productnumber int, 35 | admin_id int, 36 | username text, 37 | productname text, 38 | productdescription text, 39 | productprice int, 40 | productimagelink text, 41 | productdownloadlink text, 42 | productkeysfile text, 43 | productquantity int, 44 | productcategory text 45 | )""") 46 | 47 | #Create ShopOrderTable Table 48 | connected.execute("""CREATE TABLE IF NOT EXISTS ShopOrderTable( 49 | id SERIAL PRIMARY KEY, 50 | buyerid int, 51 | buyerusername text, 52 | productname text, 53 | productprice text, 54 | orderdate int, 55 | paidmethod text, 56 | productdownloadlink text, 57 | productkeys text, 58 | buyercomment text, 59 | ordernumber int, 60 | productnumber int, 61 | payment_id int 62 | 63 | 64 | )""") 65 | connected.execute("""CREATE TABLE IF NOT EXISTS ShopCategoryTable( 66 | id SERIAL PRIMARY KEY, 67 | categorynumber int, 68 | categoryname text 69 | )""") 70 | #Create PaymentMethodTable Table 71 | connected.execute("""CREATE TABLE IF NOT EXISTS PaymentMethodTable( 72 | id SERIAL PRIMARY KEY, 73 | admin_id int, 74 | username text, 75 | method_name text, 76 | token_keys_clientid text, 77 | secret_keys text, 78 | activated text 79 | )""") 80 | 81 | CreateTables.createtable() 82 | 83 | class CreateDatas: 84 | def __init__(self) -> None: 85 | pass 86 | 87 | def AddAuser(id, username): 88 | try: 89 | AddData = f"Insert into ShopUserTable (user_id, username, wallet)values('{id}','{username}', '0')" 90 | connected.execute(AddData) 91 | DBConnection.commit() 92 | except Exception as e: 93 | print(e) 94 | 95 | def AddAdmin(id, username): 96 | try: 97 | AddData = f"Insert into ShopAdminTable (admin_id, username, wallet) values('{id}', '{username}', '0')" 98 | connected.execute(AddData) 99 | DBConnection.commit() 100 | except Exception as e: 101 | print(e) 102 | 103 | def AddProduct(productnumber, id, username): 104 | try: 105 | AddData = f"Insert into ShopProductTable (productnumber, admin_id, username, productname, productdescription, productprice, productimagelink, productdownloadlink, productkeysfile, productquantity, productcategory) values('{productnumber}', '{id}', '{username}', 'NIL', 'NIL', '0', 'NIL', 'https://nil.nil', 'NIL', '0', 'Default Category')" 106 | connected.execute(AddData) 107 | DBConnection.commit() 108 | except Exception as e: 109 | print(e) 110 | 111 | def AddOrder(id, username,productname, productprice, orderdate, paidmethod, productdownloadlink, productkeys, ordernumber, productnumber, payment_id): 112 | try: 113 | AddData = f"Insert into ShopOrderTable (buyerid, buyerusername, productname, productprice, orderdate, paidmethod, productdownloadlink, productkeys, buyercomment, ordernumber, productnumber, payment_id) values('{id}', '{username}', '{productname}', '{productprice}', '{orderdate}', '{paidmethod}', '{productdownloadlink}', '{productkeys}', 'NIL', '{ordernumber}', '{productnumber}', '{payment_id}')" 114 | connected.execute(AddData) 115 | DBConnection.commit() 116 | except Exception as e: 117 | print(e) 118 | 119 | def AddCategory(categorynumber, categoryname): 120 | try: 121 | AddData = f"Insert into ShopCategoryTable (categorynumber, categoryname) values('{categorynumber}', '{categoryname}')" 122 | connected.execute(AddData) 123 | DBConnection.commit() 124 | except Exception as e: 125 | print(e) 126 | 127 | def AddEmptyRow(): 128 | AddData = f"Insert into PaymentMethodTable (admin_id, username, method_name, activated) values('None', 'None', 'None', 'None')" 129 | connected.execute(AddData) 130 | DBConnection.commit() 131 | 132 | def AddCryptoPaymentMethod(id, username, token_keys_clientid, secret_keys, method_name): 133 | try: 134 | connected.execute(f"UPDATE PaymentMethodTable SET admin_id = ?, username = ?, token_keys_clientid = ?, secret_keys = ?, activated = 'NO' WHERE method_name = '{method_name}'", (id, username, token_keys_clientid, secret_keys)) 135 | DBConnection.commit() 136 | except Exception as e: 137 | print(e) 138 | 139 | def UpdateOrderConfirmed(paidmethod, ordernumber): 140 | try: 141 | connected.execute(f"UPDATE ShopOrderTable SET paidmethod = ? WHERE ordernumber = ?", (paidmethod, ordernumber)) 142 | DBConnection.commit() 143 | except Exception as e: 144 | print(e) 145 | 146 | def UpdatePaymentMethodToken(id, username, token_keys_clientid, method_name): 147 | try: 148 | connected.execute(f"UPDATE PaymentMethodTable SET admin_id = '{id}', username = '{username}', token_keys_clientid = '{token_keys_clientid}' WHERE method_name = '{method_name}'") 149 | DBConnection.commit() 150 | except Exception as e: 151 | print(e) 152 | 153 | def UpdatePaymentMethodSecret(id, username, secret_keys, method_name): 154 | try: 155 | connected.execute(f"UPDATE PaymentMethodTable SET admin_id = '{id}', username = '{username}', secret_keys = '{secret_keys}' WHERE method_name = '{method_name}'") 156 | DBConnection.commit() 157 | except Exception as e: 158 | print(e) 159 | 160 | def Update_A_Category(categoryname, categorynumber): 161 | try: 162 | connected.execute("UPDATE ShopCategoryTable SET categoryname = ? WHERE categorynumber = ?", (categoryname, categorynumber)) 163 | DBConnection.commit() 164 | except Exception as e: 165 | print(e) 166 | 167 | def UpdateOrderComment(buyercomment, ordernumber): 168 | try: 169 | connected.execute(f"UPDATE ShopOrderTable SET buyercomment = ? WHERE ordernumber = ?", (buyercomment, ordernumber)) 170 | DBConnection.commit() 171 | except Exception as e: 172 | print(e) 173 | 174 | def UpdateOrderPaymentMethod(paidmethod, ordernumber): 175 | try: 176 | connected.execute(f"UPDATE ShopOrderTable SET paidmethod = ? WHERE ordernumber = ?", (paidmethod, ordernumber)) 177 | DBConnection.commit() 178 | except Exception as e: 179 | print(e) 180 | 181 | def UpdateOrderPurchasedKeys(productkeys, ordernumber): 182 | try: 183 | connected.execute(f"UPDATE ShopOrderTable SET productkeys = ? WHERE ordernumber = ?", (productkeys, ordernumber)) 184 | DBConnection.commit() 185 | except Exception as e: 186 | print(e) 187 | 188 | 189 | def AddPaymentMethod(id, username, method_name): 190 | AddData = f"Insert into PaymentMethodTable (admin_id, username, method_name, activated) values('{id}', '{username}', '{method_name}', 'YES')" 191 | connected.execute(AddData) 192 | DBConnection.commit() 193 | 194 | def UpdateProductName(productname, productnumber): 195 | try: 196 | connected.execute(f"UPDATE ShopProductTable SET productname = ? WHERE productnumber = ?", (productname, productnumber)) 197 | DBConnection.commit() 198 | except Exception as e: 199 | print(e) 200 | 201 | def UpdateProductDescription(productdescription, productnumber): 202 | try: 203 | connected.execute(f"UPDATE ShopProductTable SET productdescription = ? WHERE productnumber = ?", (productdescription, productnumber)) 204 | DBConnection.commit() 205 | except Exception as e: 206 | print(e) 207 | 208 | def UpdateProductPrice(productprice, productnumber): 209 | try: 210 | connected.execute(f"UPDATE ShopProductTable SET productprice = ? WHERE productnumber = ?", (productprice, productnumber)) 211 | DBConnection.commit() 212 | except Exception as e: 213 | print(e) 214 | 215 | def UpdateProductproductimagelink(productimagelink, productnumber): 216 | try: 217 | connected.execute(f"UPDATE ShopProductTable SET productimagelink = ? WHERE productnumber = ?", (productimagelink, productnumber)) 218 | DBConnection.commit() 219 | except Exception as e: 220 | print(e) 221 | 222 | def UpdateProductproductdownloadlink(productdownloadlink, productnumber): 223 | try: 224 | connected.execute(f"UPDATE ShopProductTable SET productdownloadlink = ? WHERE productnumber = ?", (productdownloadlink, productnumber)) 225 | DBConnection.commit() 226 | except Exception as e: 227 | print(e) 228 | 229 | def UpdateProductKeysFile(productkeysfile, productnumber): 230 | try: 231 | connected.execute(f"UPDATE ShopProductTable SET productkeysfile = ? WHERE productnumber = ?", (productkeysfile, productnumber)) 232 | DBConnection.commit() 233 | except Exception as e: 234 | print(e) 235 | 236 | def UpdateProductQuantity(productquantity, productnumber): 237 | try: 238 | connected.execute(f"UPDATE ShopProductTable SET productquantity = ? WHERE productnumber = ?", (productquantity, productnumber)) 239 | DBConnection.commit() 240 | except Exception as e: 241 | print(e) 242 | 243 | def UpdateProductCategory(productcategory, productnumber): 244 | try: 245 | connected.execute(f"UPDATE ShopProductTable SET productcategory = ? WHERE productnumber = ?", (productcategory, productnumber)) 246 | DBConnection.commit() 247 | except Exception as e: 248 | print(e) 249 | 250 | def UpdateProductQuantity(productquantity, productnumber): 251 | try: 252 | connected.execute(f"UPDATE ShopProductTable SET productquantity = ? WHERE productnumber = ?", (productquantity, productnumber)) 253 | DBConnection.commit() 254 | except Exception as e: 255 | print(e) 256 | 257 | def Update_All_ProductCategory(new_category, productcategory): 258 | try: 259 | connected.execute(f"UPDATE ShopProductTable SET productcategory = ? WHERE productcategory = ?", (new_category, productcategory)) 260 | DBConnection.commit() 261 | except Exception as e: 262 | print(e) 263 | 264 | class GetDataFromDB: 265 | def __init__(self) -> None: 266 | pass 267 | 268 | def GetUserWalletInDB(userid): 269 | try: 270 | connected.execute(f"SELECT wallet FROM ShopUserTable WHERE user_id = '{userid}'") 271 | shopuser = connected.fetchone()[0] 272 | return shopuser 273 | except Exception as e: 274 | print(e) 275 | return "" 276 | 277 | def GetUserNameInDB(userid): 278 | try: 279 | connected.execute(f"SELECT username FROM ShopUserTable WHERE user_id = '{userid}'") 280 | shopuser = connected.fetchone()[0] 281 | return shopuser 282 | except Exception as e: 283 | print(e) 284 | return "" 285 | 286 | def GetAdminNameInDB(userid): 287 | try: 288 | connected.execute(f"SELECT username FROM ShopAdminTable WHERE admin_id = '{userid}'") 289 | shopuser = connected.fetchone()[0] 290 | return shopuser 291 | except Exception as e: 292 | print(e) 293 | return "" 294 | 295 | def GetUserIDsInDB(): 296 | try: 297 | connected.execute(f"SELECT user_id FROM ShopUserTable") 298 | shopuser = connected.fetchall() 299 | return shopuser 300 | except Exception as e: 301 | print(e) 302 | return None 303 | 304 | def GetProductName(productnumber): 305 | try: 306 | connected.execute(f"SELECT productname FROM ShopProductTable WHERE productnumber = '{productnumber}'") 307 | productname = connected.fetchone()[0] 308 | return productname 309 | except Exception as e: 310 | print(e) 311 | return None 312 | 313 | def GetProductDescription(productnumber): 314 | try: 315 | connected.execute(f"SELECT productdescription FROM ShopProductTable WHERE productnumber = '{productnumber}'") 316 | productdescription = connected.fetchone()[0] 317 | return productdescription 318 | except Exception as e: 319 | print(e) 320 | return None 321 | 322 | def GetProductPrice(productnumber): 323 | try: 324 | connected.execute(f"SELECT productprice FROM ShopProductTable WHERE productnumber = '{productnumber}'") 325 | productprice = connected.fetchone()[0] 326 | return productprice 327 | except Exception as e: 328 | print(e) 329 | return None 330 | 331 | def GetProductImageLink(productnumber): 332 | try: 333 | connected.execute(f"SELECT productimagelink FROM ShopProductTable WHERE productnumber = '{productnumber}'") 334 | productimagelink = connected.fetchone()[0] 335 | return productimagelink 336 | except Exception as e: 337 | print(e) 338 | return None 339 | 340 | def GetProductDownloadLink(productnumber): 341 | try: 342 | connected.execute(f"SELECT productdownloadlink FROM ShopProductTable WHERE productnumber = '{productnumber}'") 343 | productimagelink = connected.fetchone()[0] 344 | return productimagelink 345 | except Exception as e: 346 | print(e) 347 | return None 348 | 349 | def GetProductNumber(productnumber): 350 | try: 351 | connected.execute(f"SELECT productnumber FROM ShopProductTable WHERE productnumber = '{productnumber}'") 352 | productnumbers = connected.fetchone()[0] 353 | return productnumbers 354 | except Exception as e: 355 | print(e) 356 | return None 357 | 358 | def GetProductQuantity(productnumber): 359 | try: 360 | connected.execute(f"SELECT productquantity FROM ShopProductTable WHERE productnumber = '{productnumber}'") 361 | productprice = connected.fetchone()[0] 362 | return productprice 363 | except Exception as e: 364 | print(e) 365 | return None 366 | 367 | def GetProduct_A_Category(productnumber): 368 | try: 369 | connected.execute(f"SELECT productcategory FROM ShopProductTable WHERE productnumber = '{productnumber}'") 370 | productcategory = connected.fetchone()[0] 371 | return productcategory 372 | except Exception as e: 373 | print(e) 374 | return None 375 | 376 | def Get_A_CategoryName(categorynumber): 377 | try: 378 | connected.execute(f"SELECT DISTINCT categoryname FROM ShopCategoryTable WHERE categorynumber = '{categorynumber}'") 379 | productcategory = connected.fetchone()[0] 380 | if productcategory is not None: 381 | return productcategory 382 | else: 383 | return None 384 | except Exception as e: 385 | print(e) 386 | return None 387 | 388 | def GetCategoryIDsInDB(): 389 | try: 390 | connected.execute(f"SELECT categorynumber, categoryname FROM ShopCategoryTable") 391 | categories = connected.fetchall() 392 | if categories is not None: 393 | return categories 394 | else: 395 | return None 396 | except Exception as e: 397 | print(e) 398 | return None 399 | 400 | def GetCategoryNumProduct(productcategory): 401 | try: 402 | connected.execute(f"SELECT COUNT(*) FROM ShopProductTable WHERE productcategory = '{productcategory}'") 403 | categories = connected.fetchall() 404 | if categories is not None: 405 | return categories 406 | else: 407 | return None 408 | except Exception as e: 409 | print(e) 410 | return None 411 | 412 | def GetProduct_A_AdminID(productnumber): 413 | try: 414 | connected.execute(f"SELECT admin_id FROM ShopProductTable WHERE productnumber = '{productnumber}'") 415 | productcategory = connected.fetchone()[0] 416 | return productcategory 417 | except Exception as e: 418 | print(e) 419 | return None 420 | 421 | def GetAdminIDsInDB(): 422 | try: 423 | connected.execute(f"SELECT admin_id FROM ShopAdminTable") 424 | shopadmin = connected.fetchall() 425 | return shopadmin 426 | except Exception as e: 427 | print(e) 428 | return None 429 | 430 | def GetAdminUsernamesInDB(): 431 | try: 432 | shopadmin = [] 433 | connected.execute(f"SELECT username FROM ShopAdminTable") 434 | shopadmin = connected.fetchall() 435 | return shopadmin 436 | except Exception as e: 437 | print(e) 438 | return None 439 | 440 | def GetProductNumberName(): 441 | try: 442 | productnumbers_name = [] 443 | connected.execute(f"SELECT DISTINCT productnumber, productname FROM ShopProductTable") 444 | productnumbers_name = connected.fetchall() 445 | if productnumbers_name is not None: 446 | return productnumbers_name 447 | else: 448 | return None 449 | except Exception as e: 450 | print(e) 451 | return None 452 | 453 | def GetProductInfos(): 454 | try: 455 | productnumbers_name = [] 456 | connected.execute(f"SELECT DISTINCT productnumber, productname, productprice FROM ShopProductTable") 457 | productnumbers_name = connected.fetchall() 458 | if productnumbers_name is not None: 459 | return productnumbers_name 460 | else: 461 | return None 462 | except Exception as e: 463 | print(e) 464 | return None 465 | 466 | def GetProductInfo(): 467 | try: 468 | productnumbers_name = [] 469 | connected.execute(f"SELECT DISTINCT productnumber, productname, productprice, productdescription, productimagelink, productdownloadlink, productquantity, productcategory FROM ShopProductTable") 470 | productnumbers_name = connected.fetchall() 471 | if productnumbers_name is not None: 472 | return productnumbers_name 473 | else: 474 | return None 475 | except Exception as e: 476 | print(e) 477 | return None 478 | 479 | def GetProductInfoByCTGName(productcategory): 480 | try: 481 | productnumbers_name = [] 482 | connected.execute(f"SELECT DISTINCT productnumber, productname, productprice, productdescription, productimagelink, productdownloadlink, productquantity, productcategory FROM ShopProductTable WHERE productcategory = '{productcategory}'") 483 | productnumbers_name = connected.fetchall() 484 | if productnumbers_name is not None: 485 | return productnumbers_name 486 | else: 487 | return None 488 | except Exception as e: 489 | print(e) 490 | return None 491 | 492 | def GetProductInfoByPName(productnumber): 493 | try: 494 | productnumbers_name = [] 495 | connected.execute(f"SELECT DISTINCT productnumber, productname, productprice, productdescription, productimagelink, productdownloadlink, productquantity, productcategory FROM ShopProductTable WHERE productnumber = '{productnumber}'") 496 | productnumbers_name = connected.fetchall() 497 | if productnumbers_name is not None: 498 | return productnumbers_name 499 | else: 500 | return None 501 | except Exception as e: 502 | print(e) 503 | return None 504 | 505 | def GetUsersInfo(): 506 | try: 507 | user_infos = [] 508 | connected.execute(f"SELECT DISTINCT user_id, username, wallet FROM ShopUserTable") 509 | user_infos = connected.fetchall() 510 | if user_infos is not None: 511 | return user_infos 512 | else: 513 | return None 514 | except Exception as e: 515 | print(e) 516 | return None 517 | 518 | def AllUsers(): 519 | try: 520 | connected.execute(f"SELECT COUNT(user_id) FROM ShopUserTable") 521 | alluser = connected.fetchall() 522 | if alluser is not None: 523 | return alluser 524 | else: 525 | return 0 526 | except Exception as e: 527 | print(e) 528 | return 0 529 | 530 | def AllAdmins(): 531 | try: 532 | connected.execute(f"SELECT COUNT(admin_id) FROM ShopAdminTable") 533 | alladmin = connected.fetchall() 534 | if alladmin is not None: 535 | return alladmin 536 | else: 537 | return 0 538 | except Exception as e: 539 | print(e) 540 | return 0 541 | 542 | def AllProducts(): 543 | try: 544 | connected.execute(f"SELECT COUNT(productnumber) FROM ShopProductTable") 545 | allproduct = connected.fetchall() 546 | if allproduct is not None: 547 | return allproduct 548 | else: 549 | return 0 550 | except Exception as e: 551 | print(e) 552 | return 0 553 | 554 | def AllOrders(): 555 | try: 556 | connected.execute(f"SELECT COUNT(buyerid) FROM ShopOrderTable") 557 | allorder = connected.fetchall() 558 | if allorder is not None: 559 | return allorder 560 | else: 561 | return 0 562 | except Exception as e: 563 | print(e) 564 | return 0 565 | 566 | def GetAdminsInfo(): 567 | try: 568 | admin_infos = [] 569 | connected.execute(f"SELECT DISTINCT admin_id, username, wallet FROM ShopAdminTable") 570 | admin_infos = connected.fetchall() 571 | if admin_infos is not None: 572 | return admin_infos 573 | else: 574 | return None 575 | except Exception as e: 576 | print(e) 577 | return None 578 | 579 | def GetOrderInfo(): 580 | try: 581 | order_infos = [] 582 | connected.execute(f"SELECT DISTINCT ordernumber, productname, buyerusername FROM ShopOrderTable") 583 | order_infos = connected.fetchall() 584 | if order_infos is not None: 585 | return order_infos 586 | else: 587 | return None 588 | except Exception as e: 589 | print(e) 590 | return None 591 | 592 | def GetPaymentMethods(): 593 | try: 594 | payment_method = [] 595 | connected.execute(f"SELECT DISTINCT method_name, activated, username FROM PaymentMethodTable") 596 | payment_method = connected.fetchall() 597 | if payment_method is not None: 598 | return payment_method 599 | else: 600 | return None 601 | except Exception as e: 602 | print(e) 603 | return None 604 | 605 | def GetPaymentMethodsAll(method_name): 606 | try: 607 | payment_method = [] 608 | connected.execute(f"SELECT DISTINCT method_name, token_keys_clientid, secret_keys FROM PaymentMethodTable WHERE method_name = '{method_name}'") 609 | payment_method = connected.fetchall() 610 | if payment_method is not None: 611 | return payment_method 612 | else: 613 | return None 614 | except Exception as e: 615 | print(e) 616 | return None 617 | 618 | def GetPaymentMethodTokenKeysCleintID(method_name): 619 | try: 620 | connected.execute(f"SELECT DISTINCT token_keys_clientid FROM PaymentMethodTable WHERE method_name = '{method_name}'") 621 | payment_method = connected.fetchone()[0] 622 | if payment_method is not None: 623 | return payment_method 624 | else: 625 | return None 626 | except Exception as e: 627 | print(e) 628 | return None 629 | 630 | def GetPaymentMethodSecretKeys(method_name): 631 | try: 632 | connected.execute(f"SELECT DISTINCT secret_keys FROM PaymentMethodTable WHERE method_name = '{method_name}'") 633 | payment_method = connected.fetchone()[0] 634 | if payment_method is not None: 635 | return payment_method 636 | else: 637 | return None 638 | except Exception as e: 639 | print(e) 640 | return None 641 | 642 | def GetAllPaymentMethodsInDB(): 643 | try: 644 | payment_methods = [] 645 | connected.execute(f"SELECT DISTINCT method_name FROM PaymentMethodTable") 646 | payment_methods = connected.fetchall() 647 | if payment_methods is not None: 648 | return payment_methods 649 | else: 650 | return None 651 | except Exception as e: 652 | print(e) 653 | return None 654 | 655 | def GetProductCategories(): 656 | try: 657 | productcategory = [] 658 | connected.execute(f"SELECT DISTINCT productcategory FROM ShopProductTable") 659 | productcategory = connected.fetchall() 660 | return productcategory 661 | except Exception as e: 662 | print(e) 663 | return "Default Category" 664 | 665 | def GetProductIDs(): 666 | try: 667 | productnumbers = [] 668 | connected.execute(f"SELECT productnumber FROM ShopProductTable") 669 | productnumbers = connected.fetchall() 670 | return productnumbers 671 | except Exception as e: 672 | print(e) 673 | return None 674 | 675 | def GetOrderDetails(ordernumber): 676 | try: 677 | order_details = [] 678 | connected.execute(f"SELECT DISTINCT buyerid, buyerusername, productname, productprice, orderdate, paidmethod, productdownloadlink, productkeys, buyercomment, ordernumber, productnumber FROM ShopOrderTable WHERE ordernumber = '{ordernumber}' AND paidmethod != 'NO'") 679 | order_details = connected.fetchall() 680 | if order_details is not None: 681 | return order_details 682 | else: 683 | return None 684 | except Exception as e: 685 | print(e) 686 | return None 687 | 688 | def GetOrderIDs_Buyer(buyerid): 689 | try: 690 | productnumbers = [] 691 | connected.execute(f"SELECT ordernumber FROM ShopOrderTable WHERE buyerid = '{buyerid}' AND paidmethod != 'NO' ") 692 | productnumbers = connected.fetchall() 693 | return productnumbers 694 | except Exception as e: 695 | print(e) 696 | return None 697 | 698 | def GetOrderIDs(): 699 | try: 700 | productnumbers = [] 701 | connected.execute(f"SELECT ordernumber FROM ShopOrderTable") 702 | productnumbers = connected.fetchall() 703 | return productnumbers 704 | except Exception as e: 705 | print(e) 706 | return None 707 | 708 | def GetAllUnfirmedOrdersUser(buyerid): 709 | try: 710 | payment_method = [] 711 | connected.execute(f"SELECT DISTINCT ordernumber, productname, buyerusername, payment_id, productnumber FROM ShopOrderTable WHERE paidmethod = 'NO' AND buyerid = '{buyerid}' AND payment_id != ordernumber") 712 | payment_method = connected.fetchall() 713 | if payment_method is not None: 714 | return payment_method 715 | else: 716 | return None 717 | except Exception as e: 718 | print(e) 719 | return None 720 | 721 | 722 | class CleanData: 723 | def __init__(self) -> None: 724 | pass 725 | 726 | def CleanShopUserTable(): 727 | try: 728 | connected.execute("DELETE FROM ShopUserTable") 729 | DBConnection.commit() 730 | except Exception as e: 731 | print(e) 732 | 733 | def CleanShopProductTable(): 734 | try: 735 | connected.execute("DELETE FROM ShopProductTable") 736 | DBConnection.commit() 737 | except Exception as e: 738 | print(e) 739 | 740 | def delete_an_order(user_id, ordernumber): 741 | try: 742 | connected.execute(f"DELETE FROM ShopOrderTable WHERE user_id = '{user_id}' AND ordernumber = '{ordernumber}'") 743 | DBConnection.commit() 744 | except Exception as e: 745 | print(e) 746 | 747 | def delete_a_product(productnumber): 748 | try: 749 | connected.execute(f"DELETE FROM ShopProductTable WHERE productnumber = '{productnumber}'") 750 | DBConnection.commit() 751 | except Exception as e: 752 | print(e) 753 | 754 | def delete_an_order(ordernumber): 755 | try: 756 | connected.execute(f"DELETE FROM ShopOrderTable WHERE ordernumber = '{ordernumber}'") 757 | DBConnection.commit() 758 | except Exception as e: 759 | print(e) 760 | 761 | def delete_a_payment_method(method_name): 762 | try: 763 | connected.execute(f"DELETE FROM PaymentMethodTable WHERE method_name = '{method_name}'") 764 | DBConnection.commit() 765 | except Exception as e: 766 | print(e) 767 | 768 | def delete_a_category(categorynumber): 769 | try: 770 | connected.execute(f"DELETE FROM ShopCategoryTable WHERE categorynumber = '{categorynumber}'") 771 | DBConnection.commit() 772 | except Exception as e: 773 | print(e) 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 indmdev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Free-Telegram-Store-Bot 2 | I made this Bot Free 100%. 3 | 4 | The Telegram Store Bot you can use for selling and managing your products, services, and orders. 5 | 6 | ![image1](https://i.ibb.co/6tvrHzH/v5-1.png) 7 | 8 | 9 | # Message me at [@InDMDev](https://t.me/InDMDev) for your advanced Bots customizations. 10 | 11 | 12 | For more Bots like this, and to be the first to know when I publish free bots, join my channel: [@InDMDevBots](https://t.me/InDMDevBots) 13 | 14 | 15 | # Guide 16 | 1. Install Python 3.10 17 | 2. Install any git version 18 | 3. Open terminal 19 | 4. Run this command in your terminal "git clone https://github.com/indmdev/Free-Telegram-Store-Bot.git" 20 | 5. Run this command in your terminal "cd Free-Telegram-Store-Bot-main" 21 | 6. Run this command in your terminal: "pip install -r requirements.txt" 22 | 7. Set up a free NGROK account at https://ngrok.com 23 | 8. Open another terminal and run your Ngrok 24 | 9. Setup your new Bot at [@BotFather](https://t.me/Botfather) 25 | 10. Open the config.env file 26 | 11. Add your Bot Token (Provided to you by [@BotFather](https://t.me/Botfather)) 27 | 12. Add your Ngrok URL 28 | 13. Add your Store Currency 29 | 14. Save and close the file 30 | 16. Run the "python store_main.py" command in your terminal from the "Free-Telegram-Store-Bot-main" folder 31 | 17. Completed 32 | 33 | 34 | 35 | # Upgraded version of this FREE Bot 👉: [@InDMShopV5Bot](https://t.me/inDMShopV5Bot) 36 | 37 | # [Our Classic Bot Features:](https://i.ibb.co/6tvrHzH/v5-1.png) 38 | 39 | # Test and Subscribe To Classic Bot 👉 [@InDMShopBot](https://t.me/InDMShopBot) [Check Demo](https://t.me/InDMMarketbot) 40 | 41 | 42 | 43 | # Version 6 coming soon 👇: 44 | ![photo_2025-09-10 08 21 53](https://i.ibb.co/8mhDS9F/v5-2.png) 45 | 46 | # Languages in version 6 coming soon 👇: 47 | ![photo_2025-09-10 08 21 53](https://i.ibb.co/d54nQJ7/v5-3.png) 48 | 49 | 50 | 51 | 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 52 | # Note: Use this program only for legal purposes, InDMDev is not and will not be responsible for any illegal activity/activities you indulge in using this program. 53 | 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 54 | 55 | 56 | # MAKE THE WORLD A BETTER PLACE 🙏 57 | -------------------------------------------------------------------------------- /config.env: -------------------------------------------------------------------------------- 1 | NGROK_HTTPS_URL=https://sample.app 2 | TELEGRAM_BOT_TOKEN=00000000000:rtrtirtitrsample 3 | STORE_CURRENCY=USD 4 | -------------------------------------------------------------------------------- /purchase.py: -------------------------------------------------------------------------------- 1 | from datetime import * 2 | from flask_session import Session 3 | import telebot 4 | from flask import Flask, request 5 | from telebot import types 6 | import os 7 | import os.path 8 | from InDMDevDB import * 9 | from dotenv import load_dotenv 10 | load_dotenv('config.env') 11 | 12 | 13 | # M""M M"""""""`YM M""""""'YMM M"""""`'"""`YM M""""""'YMM MM""""""""`M M""MMMMM""M 14 | # M M M mmmm. M M mmmm. `M M mm. mm. M M mmmm. `M MM mmmmmmmM M MMMMM M 15 | # M M M MMMMM M M MMMMM M M MMM MMM M M MMMMM M M` MMMM M MMMMP M 16 | # M M M MMMMM M M MMMMM M M MMM MMM M M MMMMM M MM MMMMMMMM M MMMM' .M 17 | # M M M MMMMM M M MMMM' .M M MMM MMM M M MMMM' .M MM MMMMMMMM M MMP' .MM 18 | # M M M MMMMM M M .MM M MMM MMM M M .MM MM .M M .dMMM 19 | # MMMM MMMMMMMMMMM MMMMMMMMMMM MMMMMMMMMMMMMM MMMMMMMMMMM MMMMMMMMMMMM MMMMMMMMMMM 20 | 21 | # Bot connection 22 | bot = telebot.TeleBot(f"{os.getenv('TELEGRAM_BOT_TOKEN')}", threaded=False) 23 | StoreCurrency = f"{os.getenv('STORE_CURRENCY')}" 24 | 25 | class UserOperations: 26 | def shop_items(message): 27 | id = message.from_user.id 28 | usname = message.chat.username 29 | products_list = GetDataFromDB.GetProductInfo() 30 | id = message.from_user.id 31 | all_categories = GetDataFromDB.GetCategoryIDsInDB() 32 | keyboard = types.InlineKeyboardMarkup() 33 | if all_categories == []: 34 | bot.send_message(id, "⚠️ No Product available at the moment, kindly check back soon ") 35 | else: 36 | for catnum, catname in all_categories: 37 | c_catname = catname.upper() 38 | products_category = GetDataFromDB.GetCategoryNumProduct(c_catname) 39 | for ctg in products_category: 40 | products_in_category = ctg[0] 41 | text_but = f"🏷 {catname} ({products_in_category})" 42 | text_cal = f"getcats_{catnum}" 43 | keyboard.add(types.InlineKeyboardButton(text=text_but, callback_data=text_cal)) 44 | 45 | 46 | bot.send_message(id, f"CATEGORIES:", reply_markup=keyboard) 47 | bot.send_message(id, "List completed ✅", reply_markup=types.ReplyKeyboardRemove()) 48 | for productnumber, productname, productprice, productdescription, productimagelink, productdownloadlink, productquantity, productcategory in products_list: 49 | list_m = [productnumber, productname, productprice] 50 | 51 | #@bot.callback_query_handler(func=lambda call: True) 52 | def callback_query(call): 53 | if call.data == "check": 54 | check_command(call.message) 55 | else: 56 | print("Ok") 57 | 58 | def purchase_a_products(message, input_cate): 59 | id = message.from_user.id 60 | keyboard = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 61 | keyboard.row_width = 2 62 | def checkint(): 63 | try: 64 | input_cat = int(input_cate) 65 | return input_cat 66 | except: 67 | return input_cate 68 | 69 | input_product_id = checkint() 70 | if isinstance(input_product_id, int) == True: 71 | product_list = GetDataFromDB.GetProductInfoByPName(input_product_id) 72 | if f"{input_product_id}" in f"{product_list}": 73 | key1 = types.KeyboardButton(text="Bitcoin ฿") 74 | keyboard.add(key1) 75 | for productnumber, productname, productprice, productdescription, productimagelink, productdownloadlink, productquantity, productcategory in product_list: 76 | list_m = [productnumber, productname, productprice, productdescription, productimagelink, productdownloadlink, productquantity, productcategory] 77 | bot.send_message(id, "💡 Select a Payment method to pay for this product 👇", reply_markup=keyboard) 78 | global order_info 79 | order_info = list_m 80 | else: 81 | print("Wrong command !!!") 82 | def orderdata(): 83 | try: 84 | 1==1 85 | print(order_info) 86 | return order_info 87 | except: 88 | return None 89 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | telebot==0.0.5 2 | urllib3==2.2.3 3 | watchdog==6.0.0 4 | python-dotenv==1.0.1 5 | Flask==3.0.3 6 | Flask-Session==0.8.0 -------------------------------------------------------------------------------- /store_main.py: -------------------------------------------------------------------------------- 1 | import flask 2 | from datetime import * 3 | import requests 4 | import time 5 | from flask_session import Session 6 | import telebot 7 | from flask import Flask, request, jsonify 8 | from telebot import types 9 | import random 10 | import random 11 | import os 12 | import os.path 13 | import re 14 | from InDMDevDB import * 15 | from purchase import * 16 | from InDMCategories import * 17 | from telebot.types import LabeledPrice, PreCheckoutQuery, SuccessfulPayment, ShippingOption 18 | import json 19 | from dotenv import load_dotenv 20 | load_dotenv('config.env') 21 | 22 | # M""M M"""""""`YM M""""""'YMM M"""""`'"""`YM M""""""'YMM MM""""""""`M M""MMMMM""M 23 | # M M M mmmm. M M mmmm. `M M mm. mm. M M mmmm. `M MM mmmmmmmM M MMMMM M 24 | # M M M MMMMM M M MMMMM M M MMM MMM M M MMMMM M M` MMMM M MMMMP M 25 | # M M M MMMMM M M MMMMM M M MMM MMM M M MMMMM M MM MMMMMMMM M MMMM' .M 26 | # M M M MMMMM M M MMMM' .M M MMM MMM M M MMMM' .M MM MMMMMMMM M MMP' .MM 27 | # M M M MMMMM M M .MM M MMM MMM M M .MM MM .M M .dMMM 28 | # MMMM MMMMMMMMMMM MMMMMMMMMMM MMMMMMMMMMMMMM MMMMMMMMMMM MMMMMMMMMMMM MMMMMMMMMMM 29 | 30 | # Flask connection 31 | flaskconnection = Flask(__name__) 32 | appp = Flask(__name__) 33 | 34 | # Bot connection 35 | webhookkurl = f"{os.getenv('NGROK_HTTPS_URL')}" 36 | bot = telebot.TeleBot(f"{os.getenv('TELEGRAM_BOT_TOKEN')}", threaded=False) 37 | StoreCurrency = f"{os.getenv('STORE_CURRENCY')}" 38 | 39 | 40 | bot.remove_webhook() 41 | bot.set_webhook(url=webhookkurl) 42 | 43 | 44 | # Process webhook calls 45 | print("Shop Started !!!") 46 | @flaskconnection.route('/', methods=['GET', 'POST']) 47 | 48 | # webhook function 49 | def webhook(): 50 | if flask.request.headers.get('content-type') == 'application/json': 51 | json_string = flask.request.get_data().decode('utf-8') 52 | update = telebot.types.Update.de_json(json_string) 53 | bot.process_new_updates([update]) 54 | return '' 55 | else: 56 | print("error") 57 | flask.abort(403) 58 | 59 | # Your NOWPayments API key 60 | NOWPAYMENTS_API_KEY = GetDataFromDB.GetPaymentMethodTokenKeysCleintID("Bitcoin") 61 | print(NOWPAYMENTS_API_KEY) 62 | # Base currency (e.g., USD, EUR) 63 | BASE_CURRENCY = StoreCurrency 64 | 65 | 66 | keyboard = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 67 | keyboard.row_width = 2 68 | key1 = types.KeyboardButton(text="Shop Items 🛒") 69 | key2 = types.KeyboardButton(text="My Orders 🛍") 70 | key3 = types.KeyboardButton(text="Support 📞") 71 | keyboard.add(key1) 72 | keyboard.add(key2, key3) 73 | 74 | 75 | ##################WELCOME MESSAGE + BUTTONS START######################### 76 | #Function to list Products and Categories 77 | @bot.callback_query_handler(func=lambda call: True) 78 | def callback_query(call): 79 | if call.data.startswith("getcats_") == True: 80 | input_catees = call.data.replace('getcats_','') 81 | CategoriesDatas.get_category_products(call, input_catees) 82 | elif call.data.startswith("getproduct_") == True: 83 | input_cate = call.data.replace('getproduct_','') 84 | UserOperations.purchase_a_products(call, input_cate) 85 | elif call.data.startswith("managecats_") == True: 86 | input_cate = call.data.replace('managecats_','') 87 | manage_categoriesbutton(call, input_cate) 88 | 89 | 90 | #Function to list Products 91 | def productsp(message): 92 | category = r'/\d{8}$' 93 | category1 = re.match(category, message) 94 | if category1: 95 | return True 96 | else: 97 | return False 98 | @bot.message_handler(content_types=["text"], func=lambda message: productsp(message.text)==True) 99 | def products_get(message): 100 | try: 101 | UserOperations.purchase_a_products(message) 102 | except: 103 | 1==1 104 | #Start command handler and function 105 | @bot.message_handler(content_types=["text"], func=lambda message: message.text == "Home 🏘") 106 | @bot.message_handler(commands=['start']) 107 | def send_welcome(message): 108 | try: 109 | print(NOWPAYMENTS_API_KEY) 110 | 1==1 111 | try: 112 | id = message.from_user.id 113 | usname = message.chat.username 114 | admins = GetDataFromDB.GetAdminIDsInDB() 115 | user_s = GetDataFromDB.AllUsers() 116 | for a_user_s in user_s: 117 | all_user_s = a_user_s[0] 118 | admin_s = GetDataFromDB.AllAdmins() 119 | for a_admin_s in admin_s: 120 | all_admin_s = a_admin_s[0] 121 | product_s = GetDataFromDB.AllProducts() 122 | for a_product_s in product_s: 123 | all_product_s = a_product_s[0] 124 | orders_s = GetDataFromDB.AllOrders() 125 | for a_orders_s in orders_s: 126 | all_orders_s = a_orders_s[0] 127 | 128 | keyboardadmin = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 129 | keyboardadmin.row_width = 2 130 | 131 | if admins == []: 132 | users = GetDataFromDB.GetUserIDsInDB() 133 | if f"{id}" not in f"{users}": 134 | CreateDatas.AddAuser(id,usname) 135 | user_type = "Shop Admin" 136 | CreateDatas.AddAdmin(id,usname) 137 | key0 = types.KeyboardButton(text="Manage Products 💼") 138 | key1 = types.KeyboardButton(text="Manage Categories 💼") 139 | key2 = types.KeyboardButton(text="Manage Orders 🛍") 140 | key3 = types.KeyboardButton(text="Payment Methods 💳") 141 | key4 = types.KeyboardButton(text="News To Users 📣") 142 | key5 = types.KeyboardButton(text="Switch To User 🙍‍♂️") 143 | keyboardadmin.add(key0) 144 | keyboardadmin.add(key1, key2) 145 | keyboardadmin.add(key3, key4) 146 | keyboardadmin.add(key5) 147 | store_statistics = f"➖➖➖Store's Statistics 📊➖➖➖\n\n\nTotal Users 🙍‍♂️: {all_user_s}\n\nTotal Admins 🤴: {all_admin_s}\n\nTotal Products 🏷: {all_product_s}\n\nTotal Orders 🛍: {all_orders_s}\n\n\n➖➖➖➖➖➖➖➖➖➖➖➖➖" 148 | user_data = "0" 149 | bot.send_photo(chat_id=message.chat.id, photo="https://i.ibb.co/9vctwpJ/IMG-1235.jpg", caption=f"Dear {user_type},\n\nYour Wallet Balance: $ {user_data} 💰 \n\n{store_statistics}", reply_markup=keyboardadmin) 150 | elif f"{id}" in f"{admins}": 151 | keyboardadmin = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 152 | keyboardadmin.row_width = 2 153 | users = GetDataFromDB.GetUserIDsInDB() 154 | if f"{id}" not in f"{users}": 155 | CreateDatas.AddAuser(id,usname) 156 | user_type = "Shop Admin" 157 | key0 = types.KeyboardButton(text="Manage Products 💼") 158 | key1 = types.KeyboardButton(text="Manage Categories 💼") 159 | key2 = types.KeyboardButton(text="Manage Orders 🛍") 160 | key3 = types.KeyboardButton(text="Payment Methods 💳") 161 | key4 = types.KeyboardButton(text="News To Users 📣") 162 | key5 = types.KeyboardButton(text="Switch To User 🙍‍♂️") 163 | keyboardadmin.add(key0) 164 | keyboardadmin.add(key1, key2) 165 | keyboardadmin.add(key3, key4) 166 | keyboardadmin.add(key5) 167 | 168 | store_statistics = f"➖➖➖Store's Statistics 📊➖➖➖\n\n\nTotal Users 🙍‍♂️: {all_user_s}\n\nTotal Admins 🤴: {all_admin_s}\n\nTotal Products 🏷: {all_product_s}\n\nTotal Orders 🛍: {all_orders_s}\n\n\n➖➖➖➖➖➖➖➖➖➖➖➖➖" 169 | user_data = "0" 170 | bot.send_photo(chat_id=message.chat.id, photo="https://i.ibb.co/9vctwpJ/IMG-1235.jpg", caption=f"Dear {user_type},\n\nWelcome! 🤝\n\n{store_statistics}", reply_markup=keyboardadmin) 171 | 172 | else: 173 | users = GetDataFromDB.GetUserIDsInDB() 174 | if f"{id}" in f"{users}": 175 | user_type = "Customer" 176 | user_data = GetDataFromDB.GetUserWalletInDB(id) 177 | else: 178 | CreateDatas.AddAuser(id,usname) 179 | user_type = "Customer" 180 | user_data = GetDataFromDB.GetUserWalletInDB(id) 181 | bot.send_photo(chat_id=message.chat.id, photo="https://i.ibb.co/9vctwpJ/IMG-1235.jpg", caption=f"Dear {user_type},\n\nWelcome! 🤝\n\nBrowse our products, make purchases, and enjoy fast delivery! \nType /browse to start shopping. \n\n💬 Need help? \nContact our support team anytime.", reply_markup=keyboard) 182 | except Exception as e: 183 | print(e) 184 | admin_switch_user(message) 185 | except Exception as e: 186 | print(e) 187 | 188 | #Switch admin to user handler 189 | @bot.message_handler(content_types=["text"], func=lambda message: message.text == "Switch To User 🙍‍♂️") 190 | def admin_switch_user(message): 191 | id = message.from_user.id 192 | usname = message.chat.username 193 | keyboard = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 194 | keyboard.row_width = 2 195 | 196 | users = GetDataFromDB.GetUserIDsInDB() 197 | if f"{id}" in f"{users}": 198 | user_type = "Customer" 199 | key1 = types.KeyboardButton(text="Shop Items 🛒") 200 | key2 = types.KeyboardButton(text="My Orders 🛍") 201 | key3 = types.KeyboardButton(text="Support 📞") 202 | key4 = types.KeyboardButton(text="Home 🏘") 203 | keyboard.add(key1) 204 | keyboard.add(key2, key3) 205 | keyboard.add(key4) 206 | user_data = GetDataFromDB.GetUserWalletInDB(id) 207 | else: 208 | CreateDatas.AddAuser(id,usname) 209 | user_type = "Customer" 210 | key1 = types.KeyboardButton(text="Shop Items 🛒") 211 | key2 = types.KeyboardButton(text="My Orders 🛍") 212 | key3 = types.KeyboardButton(text="Support 📞") 213 | key4 = types.KeyboardButton(text="Home 🏘") 214 | keyboard.add(key1) 215 | keyboard.add(key2, key3) 216 | keyboard.add(key4) 217 | user_data = GetDataFromDB.GetUserWalletInDB(id) 218 | bot.send_photo(chat_id=message.chat.id, photo="https://i.ibb.co/9vctwpJ/IMG-1235.jpg", caption=f"Dear {user_type},\n\nYour Wallet Balance: $ {user_data} 💰 \n\nBrowse our products, make purchases, and enjoy fast delivery! \nType /browse to start shopping. \n\n💬 Need help? \nContact our support team anytime.", reply_markup=keyboard) 219 | bot.send_message(id, "You are on User Mode ✅\nSend /start command or press Home 🏘 button to switch back to Admin Mode", reply_markup=keyboard) 220 | 221 | #Command handler to manage products 222 | @bot.message_handler(content_types=["text"], func=lambda message: message.text == "Manage Products 💼") 223 | def ManageProducts(message): 224 | id = message.from_user.id 225 | name = message.from_user.first_name 226 | usname = message.chat.username 227 | admins = GetDataFromDB.GetAdminIDsInDB() 228 | 229 | 230 | if f"{id}" in f"{admins}": 231 | keyboardadmin = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 232 | keyboardadmin.row_width = 2 233 | key1 = types.KeyboardButton(text="Add New Product ➕") 234 | key2 = types.KeyboardButton(text="List Product 🏷") 235 | key3 = types.KeyboardButton(text="Delete Product 🗑️") 236 | key4 = types.KeyboardButton(text="Home 🏘") 237 | keyboardadmin.add(key1) 238 | keyboardadmin.add(key2, key3) 239 | keyboardadmin.add(key4) 240 | 241 | bot.send_message(id, "Choose an action to perform ✅", reply_markup=keyboardadmin) 242 | else: 243 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 244 | 245 | #Command handler to add product 246 | @bot.message_handler(content_types=["text"], func=lambda message: message.text == "Add New Product ➕") 247 | def AddProductsMNG(message): 248 | id = message.from_user.id 249 | name = message.from_user.first_name 250 | usname = message.chat.username 251 | admins = GetDataFromDB.GetAdminIDsInDB() 252 | 253 | 254 | if f"{id}" in f"{admins}": 255 | keyboard = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 256 | keyboard.row_width = 2 257 | msg = bot.send_message(id, "Reply With Your Product Name or Tittle: ✅") 258 | new_product_number = random.randint(10000000,99999999) 259 | productnumber = f"{new_product_number}" 260 | CreateDatas.AddProduct(productnumber, id, usname) 261 | global productnumbers 262 | productnumbers = productnumber 263 | bot.register_next_step_handler(msg, add_a_product_name) 264 | else: 265 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 266 | 267 | #Function to add product name 268 | def add_a_product_name(message): 269 | id = message.from_user.id 270 | admins = GetDataFromDB.GetAdminIDsInDB() 271 | 272 | 273 | if f"{id}" in f"{admins}": 274 | keyboard = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 275 | keyboard.row_width = 2 276 | try: 277 | id = message.from_user.id 278 | productname = message.text 279 | msg = bot.send_message(id, "Reply With Your Product Description: ✅") 280 | CreateDatas.UpdateProductName(productname, productnumbers) 281 | bot.register_next_step_handler(msg, add_a_product_decription) 282 | except Exception as e: 283 | print(e) 284 | msg = bot.send_message(id, "Error 404 🚫, try again with corrected input.") 285 | bot.register_next_step_handler(msg, add_a_product_name) 286 | else: 287 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 288 | 289 | #Function to add product describtion 290 | def add_a_product_decription(message): 291 | id = message.from_user.id 292 | admins = GetDataFromDB.GetAdminIDsInDB() 293 | 294 | 295 | if f"{id}" in f"{admins}": 296 | keyboard = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 297 | keyboard.row_width = 2 298 | try: 299 | id = message.from_user.id 300 | description = message.text 301 | msg = bot.send_message(id, "Reply With Your Product Price: ✅") 302 | CreateDatas.UpdateProductDescription(description, productnumbers) 303 | bot.register_next_step_handler(msg, add_a_product_price) 304 | except Exception as e: 305 | print(e) 306 | msg = bot.send_message(id, "Error 404 🚫, try again with corrected input.") 307 | bot.register_next_step_handler(msg, add_a_product_decription) 308 | else: 309 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 310 | 311 | #Function to add product price 312 | def add_a_product_price(message): 313 | id = message.from_user.id 314 | admins = GetDataFromDB.GetAdminIDsInDB() 315 | 316 | 317 | if f"{id}" in f"{admins}": 318 | keyboard = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 319 | keyboard.row_width = 2 320 | try: 321 | id = message.from_user.id 322 | price = message.text 323 | msg = bot.send_message(id, "Attach Your Product Photo: ✅") 324 | CreateDatas.UpdateProductPrice(price, productnumbers) 325 | bot.register_next_step_handler(msg, add_a_product_photo_link) 326 | except Exception as e: 327 | print(e) 328 | msg = bot.send_message(id, "Error 404 🚫, try again with corrected input.") 329 | bot.register_next_step_handler(msg, add_a_product_price) 330 | else: 331 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 332 | 333 | #Function to add product photo 334 | def add_a_product_photo_link(message): 335 | id = message.from_user.id 336 | admins = GetDataFromDB.GetAdminIDsInDB() 337 | 338 | 339 | if f"{id}" in f"{admins}": 340 | keyboard = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 341 | keyboard.row_width = 2 342 | try: 343 | id = message.from_user.id 344 | image_link = message.photo[0].file_id 345 | all_categories = GetDataFromDB.GetCategoryIDsInDB() 346 | if all_categories == []: 347 | msg = bot.send_message(id, "Please reply with a new category's name") 348 | CreateDatas.UpdateProductproductimagelink(image_link, productnumbers) 349 | bot.register_next_step_handler(msg, add_a_product_category) 350 | else: 351 | bot.send_message(id, f"CATEGORIES 👇") 352 | for catnum, catname in all_categories: 353 | bot.send_message(id, f"{catname} - ID: /{catnum} ✅") 354 | 355 | msg = bot.send_message(id, "Click on a Category ID to select Category for this Product: ✅\n\n⚠️Or Write A New Category", reply_markup=types.ReplyKeyboardRemove()) 356 | CreateDatas.UpdateProductproductimagelink(image_link, productnumbers) 357 | bot.register_next_step_handler(msg, add_a_product_category) 358 | except Exception as e: 359 | print(e) 360 | msg = bot.send_message(id, "Error 404 🚫, try again with corrected input.") 361 | bot.register_next_step_handler(msg, add_a_product_photo_link) 362 | else: 363 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 364 | 365 | #Function to add product category 366 | def add_a_product_category(message): 367 | id = message.from_user.id 368 | admins = GetDataFromDB.GetAdminIDsInDB() 369 | 370 | 371 | if f"{id}" in f"{admins}": 372 | keyboard = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 373 | keyboard.row_width = 2 374 | id = message.from_user.id 375 | input_cat = message.text 376 | all_categories = GetDataFromDB.GetCategoryIDsInDB() 377 | input_cate = input_cat[1:99] 378 | 379 | categories = [] 380 | for catnum, catname in all_categories: 381 | catnames = catname.upper() 382 | categories.append(catnames) 383 | 384 | def checkint(): 385 | try: 386 | input_cat = int(input_cate) 387 | return input_cat 388 | except: 389 | return input_cate 390 | 391 | input_category = checkint() 392 | if isinstance(input_category, int) == True: 393 | product_cate = GetDataFromDB.Get_A_CategoryName(input_category) 394 | product_category = product_cate.upper() 395 | if f"{product_category}" not in f"{categories}" or f"{product_category}" == "NONE": 396 | msg = bot.send_message(id, "Please reply with a new category's name", reply_markup=types.ReplyKeyboardRemove()) 397 | bot.register_next_step_handler(msg, add_a_product_category) 398 | elif f"{product_category}" in f"{categories}": 399 | msg = bot.send_message(id, "Attach Your Producy Keys In A Text File: ✅\n\n⚠️ Please Arrange Your Product Keys In the Text File, One Product Key Per Line In The File\n\n\n⚠️ Reply With Skip to skip this step if this Product has no Product Keys") 400 | CreateDatas.UpdateProductCategory(product_category, productnumbers) 401 | bot.register_next_step_handler(msg, add_a_product_keys_file) 402 | else: 403 | new_category_number = random.randint(1000,9999) 404 | input_cate = input_cat.upper() 405 | CreateDatas.AddCategory(new_category_number, input_cate) 406 | bot.send_message(id, f"New Category created successfully - {input_cat}") 407 | msg = bot.send_message(id, "Attach Your Producy Keys In A Text File: ✅\n\n⚠️ Please Arrange Your Product Keys In the Text File, One Product Key Per Line In The File\n\n\n⚠️ Reply With Skip to skip this step if this Product has no Product Keys") 408 | CreateDatas.UpdateProductCategory(input_cate, productnumbers) 409 | bot.register_next_step_handler(msg, add_a_product_keys_file) 410 | else: 411 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 412 | 413 | #Function to add product file for keys 414 | def add_a_product_keys_file(message): 415 | id = message.from_user.id 416 | admins = GetDataFromDB.GetAdminIDsInDB() 417 | 418 | 419 | if f"{id}" in f"{admins}": 420 | keyboard = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 421 | keyboard.row_width = 2 422 | try: 423 | id = message.from_user.id 424 | if message.text and message.text.upper() == "SKIP": 425 | msg = bot.send_message(id, "Reply With Download Link For This Product\n\nThis will be the Link customer will have access to after they have paid: ✅\n\n\n⚠️ Reply With Skip to skip this step if this Product has no Product Download Link") 426 | bot.register_next_step_handler(msg, add_a_product_download_link) 427 | elif message.document: 428 | keys_folder = "Keys" 429 | if not "Keys" in os.listdir(): 430 | try: 431 | os.mkdir("Keys") 432 | except Exception as e: 433 | print(e) 434 | else: 435 | pass 436 | KeysFiles = f"{keys_folder}/{productnumbers}.txt" 437 | file = message.document 438 | file_info = bot.get_file(file.file_id) 439 | file_path = file_info.file_path 440 | file_name = os.path.join(f"{KeysFiles}") 441 | downloaded_file = bot.download_file(file_path) 442 | with open(file_name, 'wb') as new_file: 443 | new_file.write(downloaded_file) 444 | bot.reply_to(message, f'File f"{productnumbers}.txt" saved successfully.') 445 | CreateDatas.UpdateProductKeysFile(KeysFiles, productnumbers) 446 | quantity = open(file_name, 'r').read().splitlines() 447 | with open(file_name, 'r') as all: 448 | all_quantity = all.read() 449 | all_quantities = len(all_quantity.split('\n')) 450 | CreateDatas.UpdateProductQuantity(all_quantities, productnumbers) 451 | msg = bot.send_message(id, "Reply With Download Link For This Product\n\nThis will be the Link customer will have access to after they have paid: ✅\n\n\n⚠️ Reply With Skip to skip this step if this Product has no Product Download Link") 452 | bot.register_next_step_handler(msg, add_a_product_download_link) 453 | else: 454 | msg = bot.send_message(id, "Error 404 🚫, try again with corrected input.") 455 | bot.register_next_step_handler(msg, add_a_product_keys_file) 456 | except Exception as e: 457 | print(e) 458 | msg = bot.send_message(id, "Error 404 🚫, try again with corrected input.") 459 | bot.register_next_step_handler(msg, add_a_product_keys_file) 460 | else: 461 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 462 | 463 | #Function to add product download link 464 | def add_a_product_download_link(message): 465 | try: 466 | id = message.from_user.id 467 | download_link = message.text 468 | if message.text and message.text.upper() == "SKIP": 469 | bot.send_message(id, "Download Link Skipped ✅") 470 | else: 471 | CreateDatas.UpdateProductproductdownloadlink(download_link, productnumbers) 472 | CreateDatas.UpdateProductQuantity(int(100), productnumbers) 473 | 474 | keyboardadmin = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 475 | keyboardadmin.row_width = 2 476 | key1 = types.KeyboardButton(text="Add New Product ➕") 477 | key2 = types.KeyboardButton(text="List Product 🏷") 478 | key3 = types.KeyboardButton(text="Delete Product 🗑️") 479 | key4 = types.KeyboardButton(text="Home 🏘") 480 | keyboardadmin.add(key1) 481 | keyboardadmin.add(key2, key3) 482 | keyboardadmin.add(key4) 483 | productimage = GetDataFromDB.GetProductImageLink(productnumbers) 484 | productname = GetDataFromDB.GetProductName(productnumbers) 485 | productnumber = GetDataFromDB.GetProductNumber(productnumbers) 486 | productdescription = GetDataFromDB.GetProductDescription(productnumbers) 487 | productprice = GetDataFromDB.GetProductPrice(productnumbers) 488 | productquantity = GetDataFromDB.GetProductQuantity(productnumbers) 489 | captions = f"\n\n\nProduct Tittle: {productname}\n\n\nProduct Number: `{productnumber}`\n\n\nProduct Price: {productprice} {StoreCurrency} 💰\n\n\nQuantity Avaialble: {productquantity} \n\n\nProduct Description: {productdescription}" 490 | bot.send_photo(chat_id=message.chat.id, photo=f"{productimage}", caption=f"{captions}", parse_mode='Markdown') 491 | bot.send_message(id, "Product Successfully Added ✅\n\nWhat will you like to do next ?", reply_markup=keyboardadmin) 492 | except Exception as e: 493 | print(e) 494 | msg = bot.send_message(id, "Error 404 🚫, try again with corrected input.") 495 | bot.register_next_step_handler(msg, add_a_product_download_link) 496 | 497 | #Command handler and functions to delete product 498 | @bot.message_handler(content_types=["text"], func=lambda message: message.text == "Delete Product 🗑️") 499 | def DeleteProductsMNG(message): 500 | try: 501 | id = message.from_user.id 502 | 503 | 504 | admins = GetDataFromDB.GetAdminIDsInDB() 505 | productnumber_name = GetDataFromDB.GetProductNumberName() 506 | if f"{id}" in f"{admins}": 507 | keyboard = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 508 | keyboard.row_width = 2 509 | if productnumber_name == []: 510 | msg = bot.send_message(id, "No product available, please send /start command to start creating products") 511 | bot.register_next_step_handler(msg, send_welcome) 512 | else: 513 | bot.send_message(id, f"👇Product ID --- Product Name👇") 514 | for pid, tittle in productnumber_name: 515 | bot.send_message(id, f"/{pid} - `{tittle}`", parse_mode="Markdown") 516 | msg = bot.send_message(id, "Click on a Product ID of the product you want to delete: ✅", parse_mode="Markdown") 517 | bot.register_next_step_handler(msg, delete_a_product) 518 | else: 519 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 520 | except Exception as e: 521 | print(e) 522 | msg = bot.send_message(id, "Error 404 🚫, try again with corrected input.") 523 | pass 524 | def delete_a_product(message): 525 | #try: 526 | id = message.from_user.id 527 | productnu = message.text 528 | productnumber = productnu[1:99] 529 | productnum = GetDataFromDB.GetProductIDs() 530 | productnums = [] 531 | for productn in productnum: 532 | productnums.append(productn[0]) 533 | print(productnums) 534 | if int(productnumber) in productnums: 535 | try: 536 | global productnumbers 537 | productnumbers = productnumber 538 | except Exception as e: 539 | print(e) 540 | 541 | 542 | admins = GetDataFromDB.GetAdminIDsInDB() 543 | if f"{id}" in f"{admins}": 544 | keyboardadmin = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 545 | keyboardadmin.row_width = 2 546 | key1 = types.KeyboardButton(text="Add New Product ➕") 547 | key2 = types.KeyboardButton(text="List Product 🏷") 548 | key3 = types.KeyboardButton(text="Delete Product 🗑️") 549 | key4 = types.KeyboardButton(text="Home 🏘") 550 | keyboardadmin.add(key1) 551 | keyboardadmin.add(key2, key3) 552 | keyboardadmin.add(key4) 553 | CleanData.delete_a_product(productnumber) 554 | msg = bot.send_message(id, "Deleted successfully 🗑️\n\n\nWhat will you like to do next ?\n\nSelect one of buttons 👇", reply_markup=keyboardadmin, parse_mode="Markdown") 555 | else: 556 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 557 | else: 558 | msg = bot.send_message(id, "Error 404 🚫, try again with corrected input.") 559 | bot.register_next_step_handler(msg, delete_a_product) 560 | pass 561 | #except Exception as e: 562 | #print(e) 563 | #msg = bot.send_message(id, "Error 404 🚫, try again with corrected input.") 564 | #bot.register_next_step_handler(msg, delete_a_product) 565 | #pass 566 | 567 | #Command handler and fucntion to shop Items 568 | @bot.message_handler(commands=['browse']) 569 | @bot.message_handler(content_types=["text"], func=lambda message: message.text == "Shop Items 🛒") 570 | def shop_items(message): 571 | UserOperations.shop_items(message) 572 | 573 | 574 | # Dictionary to store Bitcoint payment data 575 | bitcoin_payment_data = {} 576 | 577 | # Function to get BTC amount for the given fiat amount 578 | def get_btc_amount(fiat_amount, currency): 579 | url = f'https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies={currency.lower()}' 580 | response = requests.get(url) 581 | if response.status_code == 200: 582 | price = response.json()['bitcoin'][currency.lower()] 583 | btc_amount = int(fiat_amount) / int(price) 584 | return btc_amount 585 | else: 586 | print(f"Error fetching BTC price: {response.status_code} - {response.text}") 587 | return None 588 | 589 | # Function to create a new payment 590 | def create_payment_address(btc_amount): 591 | url = 'https://api.nowpayments.io/v1/payment' 592 | headers = { 593 | 'x-api-key': NOWPAYMENTS_API_KEY, 594 | 'Content-Type': 'application/json' 595 | } 596 | data = { 597 | 'price_amount': btc_amount, 598 | 'price_currency': 'btc', 599 | 'pay_currency': 'btc', 600 | 'ipn_callback_url': 'https://api.nowpayments.io/ipn', 601 | 'order_id': '5555555555', 602 | 'order_description': 'Payment for Order' 603 | } 604 | response = requests.post(url, json=data, headers=headers) 605 | if response.status_code == 201: 606 | return response.json()['pay_address'], response.json()['payment_id'] 607 | else: 608 | print(f"Error creating payment address: {response.status_code} - {response.text}") 609 | return None, None 610 | 611 | # Function to check the payment status 612 | def check_payment_status(payment_id): 613 | url = f'https://api.nowpayments.io/v1/payment/{payment_id}' 614 | headers = { 615 | 'x-api-key': NOWPAYMENTS_API_KEY 616 | } 617 | response = requests.get(url, headers=headers) 618 | if response.status_code == 200: 619 | return response.json()['payment_status'] 620 | else: 621 | print(f"Error checking payment status: {response.status_code} - {response.text}") 622 | return None 623 | 624 | 625 | # Command handler to pay with Bitcoin 626 | @bot.message_handler(content_types=["text"], func=lambda message: message.text == "Bitcoin ฿") 627 | def bitcoin_pay_command(message): 628 | id = message.from_user.id 629 | username = message.from_user.username 630 | 631 | 632 | order_info = UserOperations.orderdata() 633 | new_order = order_info 634 | new_orders = order_info 635 | if f"{order_info}" == "None": 636 | bot.send_message(id, "No order found !", reply_markup=keyboard, parse_mode="Markdown") 637 | else: 638 | if int(f"{order_info[6]}") < int(1): 639 | bot.send_message(id, "This Item is soldout !!!", reply_markup=keyboard, parse_mode="Markdown") 640 | else: 641 | try: 642 | fiat_amount = new_order[2] 643 | btc_amount = get_btc_amount(fiat_amount, StoreCurrency) 644 | if btc_amount: 645 | payment_address, payment_id = create_payment_address(btc_amount) 646 | if payment_address and payment_id: 647 | bitcoin_payment_data[message.from_user.id] = { 648 | 'payment_id': payment_id, 649 | 'address': payment_address, 650 | 'status': 'waiting', 651 | 'fiat_amount': fiat_amount, 652 | 'btc_amount': btc_amount 653 | } 654 | try: 655 | now = datetime.now() 656 | orderdate = now.strftime("%Y-%m-%d %H:%M:%S") 657 | ordernumber = random.randint(10000,99999) 658 | paidmethod = "NO" 659 | add_key = "NIL" 660 | productdownloadlink = GetDataFromDB.GetProductDownloadLink(new_orders[0]) 661 | 662 | CreateDatas.AddOrder(id, username,new_orders[1], new_orders[2], orderdate, paidmethod, productdownloadlink, add_key, ordernumber, new_orders[0], payment_id) 663 | except Exception as e: 664 | print(e) 665 | pass 666 | keyboard2 = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 667 | keyboard2.row_width = 2 668 | key1 = types.KeyboardButton(text="Check Payment Status ⌛") 669 | keyboard2.add(key1) 670 | bot.send_message(id, f"Please send extact {btc_amount:.8f} BTC (approximately {fiat_amount} {StoreCurrency}) to the following Bitcoin", reply_markup=types.ReplyKeyboardRemove()) 671 | bot.send_message(message.chat.id, f"Address: `{payment_address}`", reply_markup=keyboard2, parse_mode='Markdown') 672 | bot.send_message(message.chat.id, f"Please stay on this page and click on Check Payment Status ⌛ button until payment is confirmed", reply_markup=keyboard2, parse_mode='Markdown') 673 | 674 | else: 675 | bot.send_message(message.chat.id, "Error creating payment address. Please try again later.\n\nOR Amount value is too small") 676 | else: 677 | bot.send_message(message.chat.id, "Error converting amount to BTC. Please try again later.") 678 | except (IndexError, ValueError): 679 | bot.send_message(message.chat.id, f"Invalid command.") 680 | 681 | # Command handler and function to Check bitcoin payment status 682 | @bot.message_handler(content_types=["text"], func=lambda message: message.text == "Check Payment Status ⌛") 683 | def bitcoin_check_command(message): 684 | id = message.from_user.id 685 | orders = GetDataFromDB.GetAllUnfirmedOrdersUser(id) 686 | if orders == [] or orders == "None": 687 | bot.send_message(message.chat.id, "No order found !") 688 | else: 689 | for ordernumber, productname, buyerusername, payment_id, productnumber in orders: 690 | status = check_payment_status(payment_id) 691 | if status: 692 | if status == 'finished': 693 | try: 694 | keys_folder = 'Keys' 695 | keys_location = f"{keys_folder}/{productnumber}.txt" 696 | all_key = open(f"{keys_location}", 'r').read().splitlines() 697 | def keeys(): 698 | if all_key == []: 699 | return "NIL" 700 | else: 701 | return all_key 702 | all_keys = keeys() 703 | for a_key in all_keys: 704 | 1==1 705 | productkeys = a_key 706 | 707 | name_file = keys_location 708 | with open(f'{name_file}', 'r') as file: 709 | lines = file.readlines() 710 | with open(f'{name_file}', 'w') as file: 711 | for line in lines: 712 | if f"{productkeys}" not in line: 713 | file.write(line) 714 | file.truncate() 715 | except: 716 | pass 717 | 718 | def check_if_keys(): 719 | try: 720 | return productkeys 721 | except: 722 | return "NIL" 723 | 724 | add_key = check_if_keys() 725 | 726 | bot.send_message(message.chat.id, "Payment received and confirmed!") 727 | CreateDatas.UpdateOrderPurchasedKeys(add_key, ordernumber) 728 | CreateDatas.UpdateOrderPaymentMethod("Bitcoin", ordernumber) 729 | product_list = GetDataFromDB.GetProductInfoByPName(productnumber) 730 | for productnumber, productname, productprice, productdescription, productimagelink, productdownloadlink, productquantity, productcategory in product_list: 731 | list_m = [productnumber, productname, productprice, productdescription, productimagelink, productdownloadlink, productquantity, productcategory] 732 | new_quantity = int(f"{productquantity}") - int(1) 733 | CreateDatas.UpdateProductQuantity(int(new_quantity), productnumber) 734 | msg = bot.send_message(message.chat.id, "Payment successful ✅") 735 | msg = bot.send_message(message.chat.id, "Would you like to write a note to the Seller ?") 736 | msg = bot.send_message(message.chat.id, "Reply with your note or reply with NIL to proceed") 737 | global order_number 738 | order_number = ordernumber 739 | bot.register_next_step_handler(msg, complete_order) 740 | else: 741 | keyboard = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 742 | keyboard.row_width = 2 743 | key1 = types.KeyboardButton(text="Check Payment Status ⌛") 744 | key2 = types.KeyboardButton(text="Home 🏘") 745 | keyboard.add(key1) 746 | keyboard.add(key2) 747 | bot.send_message(message.chat.id, f"Your payment is {status} for Order ID: {ordernumber}", reply_markup=keyboard) 748 | 749 | else: 750 | bot.send_message(message.chat.id, f"No order found with pending payment confirmation !") 751 | bot.send_message(message.chat.id, "Done ✅") 752 | 753 | def complete_order(message): 754 | id = message.from_user.id 755 | input_commend = message.text 756 | CreateDatas.UpdateOrderComment(input_commend, order_number) 757 | order_details = GetDataFromDB.GetOrderDetails(order_number) 758 | for buyerid, buyerusername, productname, productprice, orderdate, paidmethod, productdownloadlink, productkeys, buyercomment, ordernumber, productnumber in order_details: 759 | print(f"{order_details}") 760 | bot.send_message(message.chat.id, "Thank for your order 🤝") 761 | msg = f"YOUR NEW ORDER ✅\n\n\nOrder 🆔: {ordernumber}\nOrder Date 🗓: {orderdate}\nProduct Name 📦: {productname}\nProduct 🆔:{productnumber}\nProduct Price 💰: {productprice} {StoreCurrency}\nPayment Method 💳: {paidmethod}\nProduct Keys 🔑: {productkeys}\nDownload ⤵️: {productdownloadlink}" 762 | bot.send_message(id, text=f"{msg}", reply_markup=keyboard) 763 | admin_id = GetDataFromDB.GetProduct_A_AdminID(productnumber) 764 | bot.send_message(admin_id, text=f"{msg}", reply_markup=keyboard) 765 | 766 | #Command handler and function to List My Orders 🛍 767 | @bot.message_handler(content_types=["text"], func=lambda message: message.text == "My Orders 🛍") 768 | def MyOrdersList(message): 769 | id = message.from_user.id 770 | 771 | 772 | my_orders = GetDataFromDB.GetOrderIDs_Buyer(id) 773 | if my_orders == [] or my_orders == "None": 774 | bot.send_message(id, "You have not completed any order yet, please purchase an Item now", reply_markup=keyboard) 775 | else: 776 | for my_order in my_orders: 777 | order_details = GetDataFromDB.GetOrderDetails(my_order[0]) 778 | for buyerid, buyerusername, productname, productprice, orderdate, paidmethod, productdownloadlink, productkeys, buyercomment, ordernumber, productnumber in order_details: 779 | msg = f"{productname} ORDERED ON {orderdate} ✅\n\n\nOrder 🆔: {ordernumber}\nOrder Date 🗓: {orderdate}\nProduct Name 📦: {productname}\nProduct 🆔:{productnumber}\nProduct Price 💰: {productprice} {StoreCurrency}\nPayment Method 💳: {paidmethod}\nProduct Keys 🔑: {productkeys}\nDownload ⤵️: {productdownloadlink}" 780 | bot.send_message(id, text=f"{msg}") 781 | bot.send_message(id, "List completed ✅", reply_markup=keyboard) 782 | 783 | #Command handler and function to list Store Supports 📞 784 | @bot.message_handler(content_types=["text"], func=lambda message: message.text == "Support 📞") 785 | def ContactSupport(message): 786 | id = message.from_user.id 787 | admin_usernames = GetDataFromDB.GetAdminUsernamesInDB() 788 | for usernames in admin_usernames: 789 | bot.send_message(id, f"Contact us @{usernames[0]}", reply_markup=keyboard) 790 | 791 | #Command handler and function to add New Category 792 | @bot.message_handler(content_types=["text"], func=lambda message: message.text == "Add New Category ➕") 793 | def AddNewCategoryMNG(message): 794 | try: 795 | id = message.from_user.id 796 | admins = GetDataFromDB.GetAdminIDsInDB() 797 | if f"{id}" in f"{admins}": 798 | keyboard = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 799 | keyboard.row_width = 2 800 | msg = bot.send_message(id, "Reply with name you want to name your new category", reply_markup=keyboard) 801 | bot.register_next_step_handler(msg, manage_categories) 802 | else: 803 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 804 | except Exception as e: 805 | print(e) 806 | msg = bot.send_message(id, "Error 404 🚫, try again with corrected input.") 807 | bot.register_next_step_handler(msg, AddNewCategoryMNG) 808 | 809 | #Command handler and function to List Category 810 | @bot.message_handler(content_types=["text"], func=lambda message: message.text == "List Categories 🏷") 811 | def ListCategoryMNG(message): 812 | id = message.from_user.id 813 | admins = GetDataFromDB.GetAdminIDsInDB() 814 | 815 | 816 | if f"{id}" in f"{admins}": 817 | keyboardadmin = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 818 | keyboardadmin.row_width = 2 819 | try: 820 | id = message.from_user.id 821 | all_categories = GetDataFromDB.GetCategoryIDsInDB() 822 | key1 = types.KeyboardButton(text="Add New Category ➕") 823 | key2 = types.KeyboardButton(text="List Categories 🏷") 824 | key3 = types.KeyboardButton(text="Edit Category Name ✏️") 825 | key4 = types.KeyboardButton(text="Delete Category 🗑️") 826 | key5 = types.KeyboardButton(text="Home 🏘") 827 | keyboardadmin.add(key1, key2) 828 | keyboardadmin.add(key3, key4) 829 | keyboardadmin.add(key5) 830 | if all_categories == []: 831 | msg = bot.send_message(id, "No Category in your Store !!!", reply_markup=keyboardadmin) 832 | else: 833 | keyboardadmin = types.InlineKeyboardMarkup() 834 | for catnum, catname in all_categories: 835 | text_but = f"🏷 {catname}" 836 | text_cal = f"listcats_{catnum}" 837 | keyboardadmin.add(types.InlineKeyboardButton(text=text_but, callback_data=text_cal)) 838 | bot.send_message(id, f"CATEGORIES:", reply_markup=keyboardadmin) 839 | bot.send_message(id, "List completed ✅") 840 | except Exception as e: 841 | print(e) 842 | msg = bot.send_message(id, "Error 404 🚫, try again with corrected input.") 843 | bot.register_next_step_handler(msg, ManageCategoryMNG) 844 | else: 845 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 846 | 847 | #Command handler and function to Delete Category 848 | @bot.message_handler(content_types=["text"], func=lambda message: message.text == "Delete Category 🗑️") 849 | def AddNewCategoryMNG(message): 850 | try: 851 | id = message.from_user.id 852 | 853 | 854 | admins = GetDataFromDB.GetAdminIDsInDB() 855 | if f"{id}" in f"{admins}": 856 | keyboardadmin = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 857 | keyboardadmin.row_width = 2 858 | key1 = types.KeyboardButton(text="Home 🏘") 859 | keyboardadmin.add(key1) 860 | try: 861 | nen_category_name = "Deleted" 862 | try: 863 | CreateDatas.Update_All_ProductCategory(nen_category_name, product_cate) 864 | except Exception as e: 865 | print(e) 866 | product_cate = GetDataFromDB.Get_A_CategoryName(category_number) 867 | msg = bot.send_message(id, f"{product_cate} successfully deleted 🗑️", reply_markup=keyboardadmin) 868 | CleanData.delete_a_category(category_number) 869 | bot.register_next_step_handler(msg, send_welcome) 870 | 871 | except: 872 | msg = bot.send_message(id, "Category not found !!!", reply_markup=keyboardadmin) 873 | bot.register_next_step_handler(msg, send_welcome) 874 | 875 | else: 876 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 877 | except Exception as e: 878 | print(e) 879 | msg = bot.send_message(id, "Error 404 🚫, try again with corrected input.") 880 | bot.register_next_step_handler(msg, AddNewCategoryMNG) 881 | 882 | #Command handler and functions to Edit Category Name 883 | @bot.message_handler(content_types=["text"], func=lambda message: message.text == "Edit Category Name ✏️") 884 | def EditCategoryNameMNG(message): 885 | try: 886 | id = message.from_user.id 887 | 888 | 889 | admins = GetDataFromDB.GetAdminIDsInDB() 890 | if f"{id}" in f"{admins}": 891 | keyboardadmin = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 892 | keyboardadmin.row_width = 2 893 | key1 = types.KeyboardButton(text="Add New Category ➕") 894 | key2 = types.KeyboardButton(text="List Categories 🏷") 895 | key3 = types.KeyboardButton(text="Edit Category Name ✏️") 896 | key4 = types.KeyboardButton(text="Delete Category 🗑️") 897 | key5 = types.KeyboardButton(text="Home 🏘") 898 | keyboardadmin.add(key1, key2) 899 | keyboardadmin.add(key3, key4) 900 | keyboardadmin.add(key5) 901 | try: 902 | product_cate = GetDataFromDB.Get_A_CategoryName(category_number) 903 | msg = bot.send_message(id, f"Current Category's Name: {product_cate} \n\n\nReply with your new Category's name") 904 | bot.register_next_step_handler(msg, edit_a_category_name) 905 | except: 906 | msg = bot.send_message(id, "Category to edit not found !!!", reply_markup=keyboardadmin) 907 | else: 908 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 909 | except Exception as e: 910 | print(e) 911 | msg = bot.send_message(id, "Error 404 🚫, try again with corrected input.") 912 | bot.register_next_step_handler(msg, EditCategoryNameMNG) 913 | def edit_a_category_name(message): 914 | try: 915 | id = message.from_user.id 916 | 917 | 918 | admins = GetDataFromDB.GetAdminIDsInDB() 919 | if f"{id}" in f"{admins}": 920 | keyboardadmin = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 921 | keyboardadmin.row_width = 2 922 | key1 = types.KeyboardButton(text="Home 🏘") 923 | keyboardadmin.add(key1) 924 | try: 925 | nen_category_n = message.text 926 | nen_category_name = nen_category_n.upper() 927 | product_cate = GetDataFromDB.Get_A_CategoryName(category_number) 928 | try: 929 | CreateDatas.Update_All_ProductCategory(nen_category_name, product_cate) 930 | except Exception as e: 931 | print(e) 932 | CreateDatas.Update_A_Category(nen_category_name, category_number) 933 | msg = bot.send_message(id, "Category's name successfully updated: ✅", reply_markup=keyboardadmin) 934 | bot.register_next_step_handler(msg, send_welcome) 935 | 936 | except: 937 | msg = bot.send_message(id, "Category not found !!!", reply_markup=keyboardadmin) 938 | bot.register_next_step_handler(msg, send_welcome) 939 | else: 940 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 941 | except Exception as e: 942 | print(e) 943 | msg = bot.send_message(id, "Error 404 🚫, try again with corrected input.") 944 | bot.register_next_step_handler(msg, AddNewCategoryMNG) 945 | 946 | #Command handler and function to Manage Category 947 | @bot.message_handler(content_types=["text"], func=lambda message: message.text == "Manage Categories 💼") 948 | def ManageCategoryMNG(message): 949 | id = message.from_user.id 950 | admins = GetDataFromDB.GetAdminIDsInDB() 951 | 952 | 953 | if f"{id}" in f"{admins}": 954 | keyboardadmin = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 955 | keyboardadmin.row_width = 2 956 | try: 957 | id = message.from_user.id 958 | all_categories = GetDataFromDB.GetCategoryIDsInDB() 959 | if all_categories == []: 960 | msg = bot.send_message(id, "No Category in your Store !!!\n\n\nPlease reply with a new category's name to create Category") 961 | bot.register_next_step_handler(msg, manage_categories) 962 | else: 963 | keyboardadmin = types.InlineKeyboardMarkup() 964 | for catnum, catname in all_categories: 965 | text_but = f"🏷 {catname}" 966 | text_cal = f"managecats_{catnum}" 967 | keyboardadmin.add(types.InlineKeyboardButton(text=text_but, callback_data=text_cal)) 968 | bot.send_message(id, f"CATEGORIES:", reply_markup=keyboardadmin) 969 | 970 | keyboard1 = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 971 | keyboard1.row_width = 2 972 | key1 = types.KeyboardButton(text="Add New Category ➕") 973 | key2 = types.KeyboardButton(text="Home 🏘") 974 | keyboard1.add(key1) 975 | keyboard1.add(key2) 976 | msg = bot.send_message(id, "Select Category you want to manage: ✅\n\nOr Create new Category", reply_markup=keyboard1) 977 | except Exception as e: 978 | print(e) 979 | msg = bot.send_message(id, "Error 404 🚫, try again with corrected input.") 980 | bot.register_next_step_handler(msg, ManageCategoryMNG) 981 | else: 982 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 983 | 984 | def manage_categories(message): 985 | id = message.from_user.id 986 | admins = GetDataFromDB.GetAdminIDsInDB() 987 | 988 | 989 | if f"{id}" in f"{admins}": 990 | keyboardadmin = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 991 | keyboardadmin.row_width = 2 992 | input_cat = message.text 993 | all_categories = GetDataFromDB.GetCategoryIDsInDB() 994 | input_cate = input_cat 995 | categories = [] 996 | for catnum, catname in all_categories: 997 | catnames = catname.upper() 998 | categories.append(catnames) 999 | 1000 | def checkint(): 1001 | try: 1002 | input_cat = int(input_cate) 1003 | return input_cat 1004 | except: 1005 | return input_cate 1006 | 1007 | input_category = checkint() 1008 | if isinstance(input_category, int) == True: 1009 | product_cate = GetDataFromDB.Get_A_CategoryName(input_category) 1010 | product_category = product_cate.upper() 1011 | if f"{product_category}" not in f"{categories}" or f"{product_category}" == "NONE": 1012 | msg = bot.send_message(id, "Category not found !!!\n\n\nPlease reply with a new category's name to create category") 1013 | bot.register_next_step_handler(msg, manage_categories) 1014 | elif f"{product_category}" in f"{categories}": 1015 | category_num = input_cate 1016 | key1 = types.KeyboardButton(text="Add New Category ➕") 1017 | key2 = types.KeyboardButton(text="List Categories 🏷") 1018 | key3 = types.KeyboardButton(text="Edit Category Name ✏️") 1019 | key4 = types.KeyboardButton(text="Delete Category 🗑️") 1020 | key5 = types.KeyboardButton(text="Home 🏘") 1021 | keyboardadmin.add(key1, key2) 1022 | keyboardadmin.add(key3, key4) 1023 | keyboardadmin.add(key5) 1024 | bot.send_message(id, f"What will you like to do next ?", reply_markup=keyboardadmin) 1025 | else: 1026 | new_category_number = random.randint(1000,9999) 1027 | input_cate = input_cat.upper() 1028 | CreateDatas.AddCategory(new_category_number, input_cate) 1029 | key1 = types.KeyboardButton(text="Add New Category ➕") 1030 | key2 = types.KeyboardButton(text="Manage Categories 💼") 1031 | key3 = types.KeyboardButton(text="Home 🏘") 1032 | keyboardadmin.add(key1) 1033 | keyboardadmin.add(key2) 1034 | keyboardadmin.add(key3) 1035 | bot.send_message(id, f"New Category {input_cat} created successfully\n\n\nWhat will you like to do next ?", reply_markup=keyboardadmin) 1036 | category_num = new_category_number 1037 | global category_number 1038 | category_number = category_num 1039 | 1040 | else: 1041 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 1042 | 1043 | def manage_categoriesbutton(message, input_c): 1044 | id = message.from_user.id 1045 | admins = GetDataFromDB.GetAdminIDsInDB() 1046 | 1047 | 1048 | if f"{id}" in f"{admins}": 1049 | keyboardadmin = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 1050 | keyboardadmin.row_width = 2 1051 | id = message.from_user.id 1052 | all_categories = GetDataFromDB.GetCategoryIDsInDB() 1053 | input_cate = input_c 1054 | categories = [] 1055 | for catnum, catname in all_categories: 1056 | catnames = catname.upper() 1057 | categories.append(catnames) 1058 | input_category = input_cate 1059 | product_cate = GetDataFromDB.Get_A_CategoryName(input_category) 1060 | product_category = product_cate.upper() 1061 | if f"{product_category}" not in f"{categories}" or f"{product_category}" == "NONE": 1062 | msg = bot.send_message(id, "Category not found !!!\n\n\nPlease reply with a new category's name to create category") 1063 | bot.register_next_step_handler(msg, manage_categoriesbutton) 1064 | elif f"{product_category}" in f"{categories}": 1065 | category_num = input_cate 1066 | key1 = types.KeyboardButton(text="Add New Category ➕") 1067 | key2 = types.KeyboardButton(text="List Categories 🏷") 1068 | key3 = types.KeyboardButton(text="Edit Category Name ✏️") 1069 | key4 = types.KeyboardButton(text="Delete Category 🗑️") 1070 | key5 = types.KeyboardButton(text="Home 🏘") 1071 | keyboardadmin.add(key1, key2) 1072 | keyboardadmin.add(key3, key4) 1073 | keyboardadmin.add(key5) 1074 | bot.send_message(id, f"What will you like to do next ?", reply_markup=keyboardadmin) 1075 | 1076 | global category_number 1077 | category_number = category_num 1078 | print(category_number) 1079 | else: 1080 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 1081 | 1082 | #Command handler and function to List Product 1083 | @bot.message_handler(content_types=["text"], func=lambda message: message.text == "List Product 🏷") 1084 | def LISTProductsMNG(message): 1085 | id = message.from_user.id 1086 | keyboarda = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 1087 | keyboarda.row_width = 2 1088 | admins = GetDataFromDB.GetAdminIDsInDB() 1089 | productinfos = GetDataFromDB.GetProductInfos() 1090 | if f"{id}" in f"{admins}": 1091 | keyboard = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 1092 | keyboard.row_width = 2 1093 | if productinfos == []: 1094 | msg = bot.send_message(id, "No product available, please send /start command to start creating products") 1095 | bot.register_next_step_handler(msg, send_welcome) 1096 | else: 1097 | keyboard = types.InlineKeyboardMarkup() 1098 | for pid, tittle, price in productinfos: 1099 | text_but = f"💼 {tittle} - {price} {StoreCurrency}" 1100 | text_cal = f"getproductig_{pid}" 1101 | keyboard.add(types.InlineKeyboardButton(text=text_but, callback_data=text_cal)) 1102 | bot.send_message(id, f"PRODUCTS:", reply_markup=keyboard) 1103 | key1 = types.KeyboardButton(text="Add New Product ➕") 1104 | key2 = types.KeyboardButton(text="List Product 🏷") 1105 | key3 = types.KeyboardButton(text="Delete Product 🗑️") 1106 | key4 = types.KeyboardButton(text="Home 🏘") 1107 | keyboarda.add(key1) 1108 | keyboarda.add(key2, key3) 1109 | keyboarda.add(key4) 1110 | msg = bot.send_message(id, "List Finished: ✅", reply_markup=keyboarda, parse_mode="Markdown") 1111 | 1112 | else: 1113 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 1114 | 1115 | #Command handler and functions to Message All Store Users 1116 | @bot.message_handler(content_types=["text"], func=lambda message: message.text == "News To Users 📣") 1117 | def MessageAllUsers(message): 1118 | id = message.from_user.id 1119 | admins = GetDataFromDB.GetAdminIDsInDB() 1120 | 1121 | 1122 | if f"{id}" in f"{admins}": 1123 | keyboardadmin = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 1124 | keyboardadmin.row_width = 2 1125 | msg = bot.send_message(id, f"This Bot is about to Broadcast mesage to all Shop Users\n\n\nReply with the message you want to Broadcast: ✅") 1126 | bot.register_next_step_handler(msg, message_all_users) 1127 | else: 1128 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 1129 | def message_all_users(message): 1130 | id = message.from_user.id 1131 | admins = GetDataFromDB.GetAdminIDsInDB() 1132 | 1133 | 1134 | if f"{id}" in f"{admins}": 1135 | keyboardadmin = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 1136 | keyboardadmin.row_width = 2 1137 | try: 1138 | key1 = types.KeyboardButton(text="Manage Products 💼") 1139 | key2 = types.KeyboardButton(text="Manage Orders 🛍") 1140 | key3 = types.KeyboardButton(text="Payment Methods 💳") 1141 | key4 = types.KeyboardButton(text="News To Users 📣") 1142 | key5 = types.KeyboardButton(text="Switch To User 🙍‍♂️") 1143 | keyboardadmin.add(key1, key2) 1144 | keyboardadmin.add(key3, key4) 1145 | keyboardadmin.add(key5) 1146 | input_message = message.text 1147 | all_users = GetDataFromDB.GetUsersInfo() 1148 | if all_users == []: 1149 | msg = bot.send_message(id, "No user available in your store, /start", reply_markup=keyboardadmin) 1150 | else: 1151 | bot.send_message(id, "Now Broadcasting Message To All Users: ✅") 1152 | for uid, uname, uwallet in all_users: 1153 | try: 1154 | bot.send_message(uid, f"{input_message}") 1155 | bot.send_message(id, f"Message successfully sent ✅ To: @`{uname}`") 1156 | time.sleep(0.5) 1157 | except: 1158 | bot.send_message(id, f"User @{uid} has blocked the bot - {uname} ") 1159 | bot.send_message(id, f"Broadcast Completed ✅", reply_markup=keyboardadmin) 1160 | except Exception as e: 1161 | print(e) 1162 | bot.send_message(id, "Error 404 🚫, try again with corrected input.") 1163 | else: 1164 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 1165 | 1166 | 1167 | #Command handler and function to Manage Orders 1168 | @bot.message_handler(content_types=["text"], func=lambda message: message.text == "Manage Orders 🛍") 1169 | def ManageOrders(message): 1170 | id = message.from_user.id 1171 | admins = GetDataFromDB.GetAdminIDsInDB() 1172 | 1173 | 1174 | if f"{id}" in f"{admins}": # ✏️ 1175 | keyboardadmin = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 1176 | keyboardadmin.row_width = 2 1177 | key1 = types.KeyboardButton(text="List Orders 🛍") 1178 | key2 = types.KeyboardButton(text="Delete Order 🗑️") 1179 | key3 = types.KeyboardButton(text="Home 🏘") 1180 | keyboardadmin.add(key1) 1181 | keyboardadmin.add(key2, key3) 1182 | bot.send_message(id, "Choose an action to perform ✅", reply_markup=keyboardadmin) 1183 | else: 1184 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 1185 | 1186 | #Command handler and function to List All Orders 1187 | @bot.message_handler(content_types=["text"], func=lambda message: message.text == "List Orders 🛍") 1188 | def ListOrders(message): 1189 | try: 1190 | id = message.from_user.id 1191 | 1192 | 1193 | admins = GetDataFromDB.GetAdminIDsInDB() 1194 | all_orders = GetDataFromDB.GetOrderInfo() 1195 | if f"{id}" in f"{admins}": 1196 | keyboardadmin = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 1197 | keyboardadmin.row_width = 2 1198 | if all_orders == []: 1199 | bot.send_message(id, "No Order available in your store, /start") 1200 | else: 1201 | bot.send_message(id, "Your Oders List: ✅") 1202 | bot.send_message(id, f"👇 OrderID - ProductName - BuyerUserName👇") 1203 | for ordernumber, productname, buyerusername in all_orders: 1204 | import time 1205 | time.sleep(0.5) 1206 | bot.send_message(id, f"`{ordernumber}` - `{productname}` - @{buyerusername}") 1207 | key1 = types.KeyboardButton(text="List Orders 🛍") 1208 | key2 = types.KeyboardButton(text="Delete Order 🗑️") 1209 | key3 = types.KeyboardButton(text="Home 🏘") 1210 | keyboardadmin.add(key1) 1211 | keyboardadmin.add(key2, key3) 1212 | bot.send_message(id, f"List Completed ✅", reply_markup=keyboardadmin) 1213 | else: 1214 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 1215 | except Exception as e: 1216 | print(e) 1217 | bot.send_message(id, "Error 404 🚫, try again with corrected input.") 1218 | 1219 | 1220 | #Command handler and functions to Delete Order 1221 | @bot.message_handler(content_types=["text"], func=lambda message: message.text == "Delete Order 🗑️") 1222 | def DeleteOrderMNG(message): 1223 | try: 1224 | id = message.from_user.id 1225 | 1226 | 1227 | admins = GetDataFromDB.GetAdminIDsInDB() 1228 | all_orders = GetDataFromDB.GetOrderInfo() 1229 | if f"{id}" in f"{admins}": 1230 | keyboardadmin = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 1231 | keyboardadmin.row_width = 2 1232 | if all_orders == []: 1233 | key1 = types.KeyboardButton(text="List Orders 🛍") 1234 | key2 = types.KeyboardButton(text="Home 🏘") 1235 | keyboardadmin.add(key1) 1236 | keyboardadmin.add(key2) 1237 | bot.send_message(id, "No Order available in your store, /start", reply_markup=keyboardadmin) 1238 | else: 1239 | bot.send_message(id, f"👇 OrderID - ProductName - BuyerUserName 👇") 1240 | for ordernumber, productname, buyerusername in all_orders: 1241 | bot.send_message(id, f"/{ordernumber} - `{productname}` - @{buyerusername}", parse_mode="Markdown") 1242 | msg = bot.send_message(id, "Click on an Order ID of the order you want to delete: ✅", parse_mode="Markdown") 1243 | bot.register_next_step_handler(msg, delete_an_order) 1244 | else: 1245 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 1246 | except Exception as e: 1247 | print(e) 1248 | msg = bot.send_message(id, "Error 404 🚫, try again with corrected input.") 1249 | bot.register_next_step_handler(msg, DeleteOrderMNG) 1250 | def delete_an_order(message): 1251 | try: 1252 | id = message.from_user.id 1253 | ordernu = message.text 1254 | ordernumber = ordernu[1:99] 1255 | ordernum = GetDataFromDB.GetOrderIDs() 1256 | ordernumbers = [] 1257 | for ordern in ordernum: 1258 | ordernumbers.append(ordern[0]) 1259 | if f"{ordernumber}" in f"{ordernumbers}": 1260 | try: 1261 | global ordernums 1262 | ordernums = ordernumber 1263 | except Exception as e: 1264 | print(e) 1265 | 1266 | 1267 | admins = GetDataFromDB.GetAdminIDsInDB() 1268 | if f"{id}" in f"{admins}": 1269 | keyboardadmin = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 1270 | keyboardadmin.row_width = 2 1271 | key1 = types.KeyboardButton(text="List Orders 🛍") 1272 | key2 = types.KeyboardButton(text="Home 🏘") 1273 | keyboardadmin.add(key1) 1274 | keyboardadmin.add(key2) 1275 | CleanData.delete_an_order(ordernumber) 1276 | msg = bot.send_message(id, "Deleted successfully 🗑️\n\n\nWhat will you like to do next ?\n\nSelect one of buttons 👇", reply_markup=keyboardadmin, parse_mode="Markdown") 1277 | else: 1278 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 1279 | else: 1280 | msg = bot.send_message(id, "Error 404 🚫, try again with corrected input.") 1281 | bot.register_next_step_handler(msg, delete_an_order) 1282 | except Exception as e: 1283 | print(e) 1284 | msg = bot.send_message(id, "Error 404 🚫, try again with corrected input.") 1285 | bot.register_next_step_handler(msg, delete_an_order) 1286 | 1287 | #Command handler and function to Manage Payment Methods 1288 | @bot.message_handler(content_types=["text"], func=lambda message: message.text == "Payment Methods 💳") 1289 | def PaymentMethodMNG(message): 1290 | id = message.from_user.id 1291 | admins = GetDataFromDB.GetAdminIDsInDB() 1292 | 1293 | 1294 | if f"{id}" in f"{admins}": 1295 | keyboardadmin = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 1296 | keyboardadmin.row_width = 2 1297 | key1 = types.KeyboardButton(text="Add Bitcoin Method ➕") 1298 | key2 = types.KeyboardButton(text="Home 🏘") 1299 | keyboardadmin.add(key1) 1300 | keyboardadmin.add(key2) 1301 | bot.send_message(id, "Choose an action to perform ✅", reply_markup=keyboardadmin) 1302 | else: 1303 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 1304 | 1305 | 1306 | #Command handler and function to Add API Keys for Bitcoin Payment Method 1307 | @bot.message_handler(content_types=["text"], func=lambda message: message.text == "Add Bitcoin Method ➕") 1308 | def AddBitcoinAPIKey(message): 1309 | id = message.from_user.id 1310 | username = message.from_user.username 1311 | admins = GetDataFromDB.GetAdminIDsInDB() 1312 | keyboardadmin = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 1313 | keyboardadmin.row_width = 2 1314 | edit_methods = "Bitcoin" 1315 | global edit_method 1316 | edit_method = edit_methods 1317 | all_pay_methods = GetDataFromDB.GetPaymentMethodsAll(edit_method) 1318 | if f"{id}" in f"{admins}": 1319 | 1320 | if f"{edit_method}" in f"{all_pay_methods}": 1321 | bot.send_message(id, f"{edit_method} Payment method is already added ✅", reply_markup=keyboardadmin) 1322 | else: 1323 | CreateDatas.AddPaymentMethod(id, username, edit_method) 1324 | 1325 | try: 1326 | for method_name, token_clientid_keys, sectret_keys in all_pay_methods: 1327 | all = method_name, token_clientid_keys, sectret_keys 1328 | msg = bot.send_message(id, f"Reply With Your {edit_method} API Key for your NowPayments Account (https://account.nowpayments.io/create-account?link_id=3539852335): ✅") 1329 | bot.register_next_step_handler(msg, add_bitcoin_api_key) 1330 | except Exception as e: 1331 | print(e) 1332 | msg = bot.send_message(id, "Error 404 🚫, try again with corrected input.") 1333 | bot.register_next_step_handler(msg, AddBitcoinAPIKey) 1334 | else: 1335 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 1336 | def add_bitcoin_api_key(message): 1337 | id = message.from_user.id 1338 | admins = GetDataFromDB.GetAdminIDsInDB() 1339 | keyboardadmin = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 1340 | keyboardadmin.row_width = 2 1341 | if f"{id}" in f"{admins}": 1342 | try: 1343 | key1 = types.KeyboardButton(text="Home 🏘") 1344 | keyboardadmin.add(key1) 1345 | id = message.from_user.id 1346 | api_key = message.text 1347 | username = message.from_user.username 1348 | CreateDatas.UpdatePaymentMethodToken(id, username, api_key, edit_method) 1349 | bot.send_message(id, "Bitcoin Added successfully ✅", reply_markup=keyboardadmin) 1350 | except Exception as e: 1351 | print(e) 1352 | msg = bot.send_message(id, "Error 404 🚫, try again with corrected input.") 1353 | bot.register_next_step_handler(msg, AddBitcoinAPIKey) 1354 | else: 1355 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 1356 | 1357 | #Command handler and function to Add API Secret Key for Bitcoin Payment Method 1358 | @bot.message_handler(content_types=["text"], func=lambda message: message.text == "Add Bitcoin Secret ➕") 1359 | def AddBitcoinSecretKey(message): 1360 | id = message.from_user.id 1361 | admins = GetDataFromDB.GetAdminIDsInDB() 1362 | keyboardadmin = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 1363 | keyboardadmin.row_width = 2 1364 | all_pay_methods = GetDataFromDB.GetPaymentMethodsAll(edit_method) 1365 | if f"{id}" in f"{admins}": 1366 | try: 1367 | for method_name, token_clientid_keys, sectret_keys in all_pay_methods: 1368 | all = method_name, token_clientid_keys, sectret_keys 1369 | msg = bot.send_message(id, f"Reply With Your {edit_method} API Key for your NowPayments Account (https://account.nowpayments.io/create-account?link_id=3539852335): ✅") 1370 | bot.register_next_step_handler(msg, add_bitcoin_secret_key) 1371 | except Exception as e: 1372 | print(e) 1373 | msg = bot.send_message(id, "Error 404 🚫, try again with corrected input.") 1374 | bot.register_next_step_handler(msg, AddBitcoinSecretKey) 1375 | else: 1376 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboardadmin) 1377 | def add_bitcoin_secret_key(message): 1378 | id = message.from_user.id 1379 | admins = GetDataFromDB.GetAdminIDsInDB() 1380 | keyboardadmin = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) 1381 | keyboardadmin.row_width = 2 1382 | if f"{id}" in f"{admins}": 1383 | try: 1384 | key1 = types.KeyboardButton(text="Home 🏘") 1385 | keyboardadmin.add(key1) 1386 | id = message.from_user.id 1387 | api_key = message.text 1388 | username = message.from_user.username 1389 | CreateDatas.UpdatePaymentMethodSecret(id, username, api_key, edit_method) 1390 | bot.send_message(id, "Added successfully ✅", reply_markup=keyboardadmin) 1391 | except Exception as e: 1392 | print(e) 1393 | msg = bot.send_message(id, "Error 404 🚫, try again with corrected input.") 1394 | bot.register_next_step_handler(msg, AddBitcoinSecretKey) 1395 | else: 1396 | bot.send_message(id, "⚠️ Only Admin can use this command !!!", reply_markup=keyboard) 1397 | 1398 | if __name__ == '__main__': 1399 | flaskconnection.run(debug=False) 1400 | appp.run(debug=True) 1401 | --------------------------------------------------------------------------------