Add files via upload
This commit is contained in:
parent
2bb06b0d91
commit
9264058093
1 changed files with 129 additions and 17 deletions
146
misc_beta_bot.py
146
misc_beta_bot.py
|
@ -8,6 +8,57 @@ from aiogram.utils import executor
|
|||
|
||||
from config import TOKEN
|
||||
|
||||
from const import REG_OK
|
||||
|
||||
import os
|
||||
import re
|
||||
import random
|
||||
import time
|
||||
|
||||
#import pymysql
|
||||
#import pymysql.cursors
|
||||
|
||||
import sqlite3
|
||||
|
||||
#print('Bot started')
|
||||
|
||||
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,
|
||||
rng_kd INTEGER NOT NULL DEFAULT 0,
|
||||
lng_code VARCHAR NOT NULL DEFAULT ''
|
||||
)''');
|
||||
|
||||
async def reg_user(message: types.Message):
|
||||
print(message)
|
||||
user_id = int(message.from_user.id)
|
||||
user_fn = message.from_user.first_name or ''
|
||||
lng_code = message.from_user.language_code or ''
|
||||
when_int = int(datetime.timestamp(message.date))
|
||||
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()
|
||||
except Exception as Err:
|
||||
print(Err)
|
||||
try:
|
||||
cur.execute("SELECT reg_int FROM users WHERE user_id = %d" % int(user_id));
|
||||
rd = cur.fetchone();
|
||||
if rd is None:
|
||||
return 0
|
||||
else:
|
||||
rd=rd[0]
|
||||
if rd==when_int:
|
||||
print(REG_OK.get(lng_code, REG_OK['default']).format(user_fn=user_fn))
|
||||
return rd
|
||||
except Exception as Err:
|
||||
print(Err)
|
||||
return 0
|
||||
|
||||
bot = Bot(token=TOKEN)
|
||||
dp = Dispatcher(bot)
|
||||
|
||||
|
@ -16,36 +67,97 @@ print('Bot started')
|
|||
@dp.message_handler(commands=['start'])
|
||||
async def process_start_command(message: types.Message):
|
||||
#print(message)
|
||||
await message.answer("🖖")
|
||||
snd_msg = "🖖"
|
||||
user_id = int(message.from_user.id)
|
||||
user_fn = message.from_user.first_name or ''
|
||||
lng_code = message.from_user.language_code or ''
|
||||
when_int = int(datetime.timestamp(message.date))
|
||||
rd=int(await reg_user(message))#create or date
|
||||
if rd == when_int:
|
||||
snd_msg = REG_OK.get(lng_code, REG_OK['default']).format(user_fn=user_fn)
|
||||
await message.answer(snd_msg)
|
||||
|
||||
@dp.message_handler(commands=['reg'])
|
||||
async def cmd_reg(message: types.Message):
|
||||
#print(message)
|
||||
snd_msg = "🤷"
|
||||
user_id = int(message.from_user.id)
|
||||
user_fn = message.from_user.first_name or ''
|
||||
lng_code = message.from_user.language_code or ''
|
||||
when_int = int(datetime.timestamp(message.date))
|
||||
rd=int(await reg_user(message))#create or date
|
||||
if rd == when_int:
|
||||
snd_msg = REG_OK.get(lng_code, REG_OK['default']).format(user_fn=user_fn)
|
||||
elif rd > 0:
|
||||
snd_msg = time.strftime('%d.%m.%Y', time.localtime(rd))
|
||||
await message.answer(snd_msg)
|
||||
|
||||
@dp.message_handler(commands=['farm','ферма','random','rand','rnd'])
|
||||
async def cmd_farm (message: types.Message):
|
||||
user_id = int(message.from_user.id)
|
||||
when_int = int(datetime.timestamp(message.date))
|
||||
await reg_user(message)#register_user
|
||||
bal = 0
|
||||
rkd = 0
|
||||
try:
|
||||
cur.execute("SELECT mcoins,rng_kd FROM users WHERE user_id = %d" % int(user_id));
|
||||
rd = cur.fetchone();
|
||||
if rd is None:
|
||||
msg = "ERROR"
|
||||
else:
|
||||
#print(rd)
|
||||
bal = rd[0]
|
||||
rkd = rd[1]
|
||||
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
|
||||
try:
|
||||
cur.execute("UPDATE users SET mcoins = :bal, rng_kd = :rkd WHERE user_id = :uid;",
|
||||
{"rkd":int(rkd),"bal":int(bal),"uid":int(user_id)}); con.commit()
|
||||
except Exception as Err:
|
||||
msg = Err
|
||||
print(Err)
|
||||
else:
|
||||
rkd = rkd-when_int
|
||||
msg=f"\n⌚️ кд: {rkd} сек.\n🤑 бл: {bal}"
|
||||
except Exception as Err:
|
||||
msg = Err
|
||||
print(Err)
|
||||
await message.answer(msg)
|
||||
|
||||
@dp.message_handler(commands=['help'])
|
||||
async def process_help_command(message: types.Message):
|
||||
#print(message)
|
||||
await message.answer(emoji="🤷")
|
||||
#await message.answer(emoji="🤷")
|
||||
await message.answer('''
|
||||
• 💬 /chats
|
||||
• 🎲 /dice
|
||||
• 🤑 /rnd
|
||||
''')
|
||||
|
||||
@dp.message_handler(commands=['ping'])
|
||||
async def process_ping_command(message: types.Message):
|
||||
#print(message)
|
||||
await message.reply("PONG!")
|
||||
|
||||
@dp.message_handler(commands=['кубик'])
|
||||
@dp.message_handler(commands=['dice','кубик'])
|
||||
async def cmd_dice(message: types.Message):
|
||||
#print(message)
|
||||
await message.answer_dice(emoji="🎲")
|
||||
|
||||
@dp.message_handler(commands=['coffee','кава','кофе','кофи','кофі'])
|
||||
async def cmd_coffee(message: types.Message):
|
||||
#print(message)
|
||||
await message.answer("☕")
|
||||
|
||||
@dp.message_handler(commands=['tea','чай','чяй'])
|
||||
async def cmd_tea(message: types.Message):
|
||||
#print(message)
|
||||
await message.answer("🍵")
|
||||
|
||||
@dp.message_handler(commands=['chats','чати','чаты','чаті'])
|
||||
async def cmd_chats(message: types.Message):
|
||||
#print(message)
|
||||
await message.answer('''
|
||||
• ☕ @misc_chat
|
||||
• 🦠 @misc_flood
|
||||
|
|
Loading…
Reference in a new issue