Created
September 24, 2021 16:31
-
-
Save Denver-sn/737355d70a4bb1d8bff64d32a06291e6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import telebot | |
import sqlite3 | |
import time | |
# DATABASE CONFIGURATION | |
conn = sqlite3.connect('sacs_db.db', check_same_thread=False) | |
cursor = conn.cursor() | |
def db_wallet(user_id: int, wallet_a: str): | |
cursor.execute('INSERT INTO user_db (user_id, wallet) VALUES (?, ?)', | |
(user_id, wallet_a)) | |
conn.commit() | |
#---------------------------# | |
TOKEN = "YOUR_TOKEN" | |
bot = telebot.TeleBot(TOKEN) | |
@bot.message_handler(commands=['start']) | |
def start(message): | |
user = message.chat.id | |
name = message.chat.first_name | |
try: | |
cursor.execute(f"SELECT * from user_db WHERE user_id = {user}") | |
records = cursor.fetchone() | |
data_id = records[0] | |
wallet_in_db = records[2] | |
bot.send_message(message.chat.id, f"Hello {name}, welcome back!") | |
except Exception as e: | |
print(e) | |
try: | |
db_wallet(user_id=user, wallet_a=None) | |
bot.send_message(message.chat.id, f"Hello {name}, welcome New user!") | |
except Exception as e: | |
print(e) | |
@bot.message_handler(commands=['wallet']) | |
def start(message): | |
user = message.chat.id | |
name = message.chat.first_name | |
if message.chat.type == 'private': | |
try: | |
cursor.execute(f"SELECT * from user_db WHERE user_id = {user}") | |
records = cursor.fetchone() | |
data_id = records[0] | |
wallet_in_db = records[2] | |
if wallet_in_db == None: | |
bot.send_message(message.chat.id, f"Sorry! you didn't set any wallet :/") | |
else: | |
bot.send_message(message.chat.id, f"Your Wallet is : {wallet_in_db}") | |
except: | |
bot.send_message(message.chat.id, f"Error! seems you're not in our database") | |
@bot.message_handler(commands=['set_wallet']) | |
def start(message): | |
sent = bot.reply_to(message, f"Please send your Wallet Adress: ") | |
bot.register_next_step_handler(sent, receive) | |
def receive(message): | |
wallet = message.text | |
user = message.chat.id | |
name = message.chat.first_name | |
try: | |
cursor.execute(f"SELECT * from user_db WHERE user_id = {user}") | |
records = cursor.fetchone() | |
data_id = records[0] | |
wallet_in_db = records[2] | |
print(wallet_in_db) | |
db_wallet(user_id=user, wallet_a=wallet) | |
bot.send_message(message.chat.id, f"Wallet Updated !") | |
except Exception as e: | |
print(e) | |
db_wallet(user_id=user, wallet_a=wallet) | |
bot.send_message(message.chat.id, f"New Wallet Adress added") | |
while True: | |
try: | |
bot.polling(none_stop=True) | |
except Exception: | |
time.sleep(60) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE user_db ( | |
id PRIMARY KEY | |
UNIQUE, | |
user_id INTEGER UNIQUE ON CONFLICT REPLACE, | |
wallet INTEGER UNIQUE | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment