Add files via upload
This commit is contained in:
parent
f4d8a849d5
commit
8e39c8bdee
1 changed files with 159 additions and 66 deletions
225
misc_beta_bot.py
225
misc_beta_bot.py
|
@ -15,25 +15,35 @@ import re
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
|
|
||||||
#import pymysql
|
import pymysql
|
||||||
#import pymysql.cursors
|
import pymysql.cursors
|
||||||
|
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
#print('Bot started')
|
db_pymysql = True#set True or False
|
||||||
|
db_sqlite3 = True#set True or False
|
||||||
|
|
||||||
con = sqlite3.connect("db4tg.sqlite")
|
if db_sqlite3:
|
||||||
|
con=sqlite3.connect("db4tg.sqlite")
|
||||||
|
cur=con.cursor()
|
||||||
|
cur.execute('''CREATE TABLE IF NOT EXISTS users (
|
||||||
|
user_id INTEGER NOT NULL DEFAULT 0 UNIQUE,
|
||||||
|
reg_int INTEGER NOT NULL DEFAULT 0,
|
||||||
|
f_name VARCHAR NOT NULL DEFAULT 'хз',
|
||||||
|
mcoins INTEGER NOT NULL DEFAULT 1024,
|
||||||
|
rnd_kd INTEGER NOT NULL DEFAULT 0,
|
||||||
|
lng_code VARCHAR NOT NULL DEFAULT ''
|
||||||
|
)''');
|
||||||
|
|
||||||
cur = con.cursor()
|
if db_pymysql:
|
||||||
|
ldb=pymysql.connect(
|
||||||
cur.execute('''CREATE TABLE IF NOT EXISTS users (
|
host='localhost',
|
||||||
user_id INTEGER NOT NULL DEFAULT 0 UNIQUE,
|
user='root',
|
||||||
reg_int INTEGER NOT NULL DEFAULT 0,
|
password='V3rY$tR0Ng',
|
||||||
f_name VARCHAR NOT NULL DEFAULT 'хз',
|
db='db',
|
||||||
mcoins INTEGER NOT NULL DEFAULT 1024,
|
charset='utf8mb4',
|
||||||
rnd_kd INTEGER NOT NULL DEFAULT 0,
|
cursorclass=pymysql.cursors.DictCursor)
|
||||||
lng_code VARCHAR NOT NULL DEFAULT ''
|
dbc = ldb.cursor()
|
||||||
)''');
|
|
||||||
|
|
||||||
async def reg_user(message: types.Message):
|
async def reg_user(message: types.Message):
|
||||||
print(message)
|
print(message)
|
||||||
|
@ -41,23 +51,79 @@ async def reg_user(message: types.Message):
|
||||||
user_fn = message.from_user.first_name or ''
|
user_fn = message.from_user.first_name or ''
|
||||||
lng_code = message.from_user.language_code or ''
|
lng_code = message.from_user.language_code or ''
|
||||||
when_int = int(datetime.timestamp(message.date))
|
when_int = int(datetime.timestamp(message.date))
|
||||||
try:
|
reg_date = 0
|
||||||
cur.execute("INSERT OR IGNORE INTO users(user_id,reg_int,f_name,lng_code) VALUES (?,?,?,?)", (int(user_id),int(when_int),str(user_fn),str(lng_code))); con.commit()
|
mcoins_c = 0
|
||||||
except Exception as Err:
|
if db_sqlite3:
|
||||||
print(Err)
|
try:
|
||||||
try:
|
cur.execute("INSERT OR IGNORE INTO users(user_id,reg_int,f_name,lng_code) VALUES (?,?,?,?)", (int(user_id),int(when_int),str(user_fn),str(lng_code))); con.commit()
|
||||||
cur.execute("SELECT reg_int FROM users WHERE user_id = %d" % int(user_id));
|
except Exception as Err:
|
||||||
rd = cur.fetchone();
|
print(f"sqlite INSERT:{Err}")
|
||||||
if rd is None:
|
|
||||||
return 0
|
sqlite_rd=when_int#for min (rd,rd)
|
||||||
else:
|
sqlite_co=1024
|
||||||
rd=rd[0]
|
try:
|
||||||
if rd==when_int:
|
cur.execute("SELECT reg_int,mcoins FROM users WHERE user_id = %d" % int(user_id));
|
||||||
print(REG_OK.get(lng_code, REG_OK['default']).format(user_fn=user_fn))
|
rd = cur.fetchone();
|
||||||
return rd
|
if rd is None:
|
||||||
except Exception as Err:
|
print('не знайшли юзера у базі sqlite')
|
||||||
print(Err)
|
else:
|
||||||
return 0
|
sqlite_rd=int(rd[0])
|
||||||
|
sqlite_co=int(rd[1])
|
||||||
|
if sqlite_rd > 0:
|
||||||
|
reg_date=sqlite_rd
|
||||||
|
else:
|
||||||
|
reg_date=when_int
|
||||||
|
if sqlite_co > 0:
|
||||||
|
mcoins_c=sqlite_co
|
||||||
|
except Exception as Err:
|
||||||
|
print(f"sqlite SELECT:{Err}")
|
||||||
|
|
||||||
|
if db_pymysql:
|
||||||
|
try:
|
||||||
|
dbc.execute("INSERT INTO `tg_bot_users` (user_id,reg_int,f_name,lng_code) VALUES (%s,%s,%s,%s) ON DUPLICATE KEY UPDATE f_name=VALUES(f_name);",(int(user_id),int(when_int),str(user_fn),str(lng_code))); ldb.commit();
|
||||||
|
except Exception as Err:
|
||||||
|
print(f"localhost INSERT:{Err}")
|
||||||
|
pymysql_rd=when_int#for min (rd,rd)
|
||||||
|
pymysql_co=1024
|
||||||
|
try:
|
||||||
|
dbc.execute("SELECT reg_int,mcoins FROM `tg_bot_users` WHERE user_id = %d" % int(user_id));
|
||||||
|
rd = dbc.fetchone();
|
||||||
|
if rd is None:
|
||||||
|
print('не знайшли юзера у базі localhost')
|
||||||
|
else:
|
||||||
|
pymysql_rd=int(rd['reg_int'])
|
||||||
|
pymysql_co=int(rd['mcoins'])
|
||||||
|
if pymysql_rd > 0:
|
||||||
|
reg_date=pymysql_rd
|
||||||
|
else:
|
||||||
|
reg_date=when_int
|
||||||
|
if pymysql_co > 0:
|
||||||
|
mcoins_c=pymysql_co
|
||||||
|
except Exception as Err:
|
||||||
|
print(f"localhost SELECT:{Err}")
|
||||||
|
|
||||||
|
if db_sqlite3 and db_pymysql:
|
||||||
|
#якщо юзаємо обидві бази,то
|
||||||
|
reg_date=int(min(sqlite_rd,pymysql_rd))
|
||||||
|
mcoins_c=int(max(sqlite_co,pymysql_co))
|
||||||
|
|
||||||
|
if sqlite_rd < pymysql_rd or sqlite_co > pymysql_co:
|
||||||
|
#UPDATE `tg_bot_users` SET `reg_int`=?,`mcoins`=? WHERE `user_id`=?;
|
||||||
|
try:
|
||||||
|
dbc.execute(f"UPDATE `tg_bot_users` SET `reg_int` ='{reg_date}',`mcoins` ='{mcoins_c}' WHERE user_id = %d" % int(user_id)); ldb.commit()#як я хотів воно нехотіло, тому буде пока так.
|
||||||
|
except Exception as Err:
|
||||||
|
print(f"localhost UPDATE:{Err}")
|
||||||
|
|
||||||
|
if sqlite_rd > pymysql_rd or sqlite_co < pymysql_co:
|
||||||
|
try:
|
||||||
|
cur.execute("UPDATE users SET reg_int =?,mcoins=? WHERE user_id=?", (int(reg_date),int(mcoins_c),int(user_id))); con.commit()
|
||||||
|
except Exception as Err:
|
||||||
|
print(f"sqlite UPDATE:{Err}")
|
||||||
|
|
||||||
|
if reg_date==when_int:
|
||||||
|
print(REG_OK.get(lng_code, REG_OK['default']).format(user_fn=user_fn))
|
||||||
|
|
||||||
|
return reg_date
|
||||||
|
|
||||||
bot = Bot(token=TOKEN)
|
bot = Bot(token=TOKEN)
|
||||||
dp = Dispatcher(bot)
|
dp = Dispatcher(bot)
|
||||||
|
@ -96,47 +162,74 @@ async def cmd_reg(message: types.Message):
|
||||||
async def cmd_farm (message: types.Message):
|
async def cmd_farm (message: types.Message):
|
||||||
user_id = int(message.from_user.id)
|
user_id = int(message.from_user.id)
|
||||||
when_int = int(datetime.timestamp(message.date))
|
when_int = int(datetime.timestamp(message.date))
|
||||||
await reg_user(message)#register_user
|
rd=await reg_user(message)#register_user#+sync
|
||||||
bal = 0
|
bal = int(42)#min bal
|
||||||
rkd = 0
|
rkd = int(rd)#reg int
|
||||||
try:
|
if db_sqlite3:
|
||||||
cur.execute("SELECT mcoins,rnd_kd FROM users WHERE user_id = %d" % int(user_id));
|
try:
|
||||||
rd = cur.fetchone();
|
cur.execute("SELECT mcoins,rnd_kd FROM users WHERE user_id = %d" % int(user_id));
|
||||||
if rd is None:
|
rd = cur.fetchone();
|
||||||
msg = "ERROR"
|
if rd is None:
|
||||||
else:
|
msg = "ERROR: user not registred in sqlite"
|
||||||
#print(rd)
|
print(msg)
|
||||||
bal = rd[0]
|
else:
|
||||||
rkd = rd[1]
|
bal = int(max(int(rd[0]),bal))
|
||||||
if when_int > rkd:
|
rkd = int(max(int(rd[1]),rkd))
|
||||||
rnd = random.randint(-32,64)
|
except Exception as Err:
|
||||||
if rnd > 0:
|
msg = Err
|
||||||
msg = f"✅ ok! +{rnd}"
|
print(Err)
|
||||||
rkd = rnd * 60
|
if db_pymysql:
|
||||||
if rnd < 0:
|
try:
|
||||||
msg = f"❎ ой! {rnd}"
|
dbc.execute("SELECT mcoins,rnd_kd FROM `tg_bot_users` WHERE user_id = %d" % int(user_id));
|
||||||
rkd = (64-rnd) *32
|
rd = dbc.fetchone();
|
||||||
if rnd == 0:
|
if rd is None:
|
||||||
rnd = 100
|
print('не знайшли юзера у базі localhost')
|
||||||
rkd = rnd * 64
|
print(msg)
|
||||||
msg = f"✅ оу! +{rnd}"
|
else:
|
||||||
bal+=rnd
|
bal = int(max(int(rd['mcoins']),bal))
|
||||||
if bal<10:
|
rkd = int(max(int(rd['rnd_kd']),rkd))
|
||||||
bal =10 #я сьодня добрьій.
|
except Exception as Err:
|
||||||
msg=f"{msg}\n🤑 бл: {bal} \n⌚️ кд: {rkd} сек"
|
msg = Err
|
||||||
rkd+=when_int
|
print(Err)
|
||||||
|
|
||||||
|
if db_sqlite3 or db_pymysql:
|
||||||
|
# якщо вобще юзаєм базу
|
||||||
|
if when_int > rkd:
|
||||||
|
rnd = random.randint(-32,64)
|
||||||
|
if rnd > 0:
|
||||||
|
msg = f"✅ ok! +{rnd}"
|
||||||
|
rkd = rnd * 60
|
||||||
|
if rnd < 0:
|
||||||
|
msg = f"❎ ой! {rnd}"
|
||||||
|
rkd = (64-rnd) *32
|
||||||
|
if rnd == 0:
|
||||||
|
rnd = 100
|
||||||
|
rkd = rnd * 64
|
||||||
|
msg = f"✅ оу! +{rnd}"
|
||||||
|
bal+=rnd
|
||||||
|
if bal<10:
|
||||||
|
bal =10 #я сьодня добрьій.
|
||||||
|
msg=f"{msg}\n🤑 бл: {bal} \n⏱ кд: {rkd} сек"
|
||||||
|
rkd+=when_int
|
||||||
|
if db_sqlite3:
|
||||||
try:
|
try:
|
||||||
cur.execute("UPDATE users SET mcoins = :bal, rnd_kd = :rkd WHERE user_id = :uid;",
|
cur.execute("UPDATE users SET mcoins = :bal, rnd_kd = :rkd WHERE user_id = :uid;",
|
||||||
{"rkd":int(rkd),"bal":int(bal),"uid":int(user_id)}); con.commit()
|
{"rkd":int(rkd),"bal":int(bal),"uid":int(user_id)}); con.commit()
|
||||||
except Exception as Err:
|
except Exception as Err:
|
||||||
msg = Err
|
msg = Err
|
||||||
print(Err)
|
print(Err)
|
||||||
else:
|
if db_pymysql:
|
||||||
rkd = rkd-when_int
|
try:
|
||||||
msg=f"\n⌚️ кд: {rkd} сек.\n🤑 бл: {bal}"
|
dbc.execute(f"UPDATE `tg_bot_users` SET `rnd_kd` ='{rkd}',`mcoins` ='{bal}' WHERE user_id = %d" % int(user_id)); ldb.commit()#як я хотів воно нехотіло, тому буде пока так.
|
||||||
except Exception as Err:
|
except Exception as Err:
|
||||||
msg = Err
|
msg = Err
|
||||||
print(Err)
|
print(Err)
|
||||||
|
else:
|
||||||
|
rkd = rkd-when_int
|
||||||
|
msg=f"\n ⏱ кд: {rkd} сек.\n🤑 бл: {bal}"
|
||||||
|
else:
|
||||||
|
rnd = random.randint(-32,100)
|
||||||
|
msg = rnd
|
||||||
await message.answer(msg)
|
await message.answer(msg)
|
||||||
|
|
||||||
@dp.message_handler(commands=['help'])
|
@dp.message_handler(commands=['help'])
|
||||||
|
|
Loading…
Reference in a new issue