forked from Pavel_Durov/python_bot
меньше кода - лучше!
This commit is contained in:
parent
eb59091615
commit
505d90aea8
0
db_logic/__init__.py
Normal file
0
db_logic/__init__.py
Normal file
18
db_logic/collections.py
Normal file
18
db_logic/collections.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
from global_conf import CONFIG
|
||||||
|
|
||||||
|
#### https://docs.python-arango.com/en/main/
|
||||||
|
from arango import ArangoClient
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def get_dicks_collection():
|
||||||
|
arango_client = ArangoClient(hosts=CONFIG['databaso']['host'] )
|
||||||
|
pipisa_db = arango_client.db(
|
||||||
|
CONFIG['databaso']['base'],
|
||||||
|
username=CONFIG['databaso']['user'],
|
||||||
|
password=CONFIG['databaso']['pass']
|
||||||
|
)
|
||||||
|
dicks_collection = pipisa_db.collection(CONFIG['databaso']['collection'])
|
||||||
|
|
||||||
|
return dicks_collection
|
33
db_logic/tops.py
Normal file
33
db_logic/tops.py
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
from global_conf import CONFIG
|
||||||
|
from db_logic import collections
|
||||||
|
|
||||||
|
|
||||||
|
def get_tops(top_ = False, glob_ = False, chat_id = None):
|
||||||
|
|
||||||
|
if top_:
|
||||||
|
try:
|
||||||
|
dicks = [d for d in collections.get_dicks_collection().find({'chat_id': chat_id}, skip=0, limit=1100)]
|
||||||
|
except Exception as e:
|
||||||
|
print('ошибка DB в /topdick')
|
||||||
|
print(e)
|
||||||
|
elif glob_:
|
||||||
|
try:
|
||||||
|
dicks = [d for d in collections.get_dicks_collection().all( ) if d['user_id'] != d['chat_id']]
|
||||||
|
except Exception as e:
|
||||||
|
print('ошибка DB в /globaldick')
|
||||||
|
print(e)
|
||||||
|
else:
|
||||||
|
print('вызывают хз что!')
|
||||||
|
|
||||||
|
top_dicks = sorted(dicks, key=lambda dick: dick['dick_size'], reverse=True)
|
||||||
|
top_dicks = top_dicks[:( min(len(top_dicks), 10) )]
|
||||||
|
|
||||||
|
dickos = ''
|
||||||
|
emo = ['🏆','🚀','🍆','🍌','🐍','🐎','🌭','🌶','👌','💩']
|
||||||
|
|
||||||
|
if len(top_dicks) > 0:
|
||||||
|
for i in range(len(top_dicks)):
|
||||||
|
dickos += f' {emo[i]} {i+1}. {top_dicks[i]["user_fullname"]}: {top_dicks[i]["dick_size"]}см\n'
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
return dickos
|
@ -8,30 +8,20 @@ from pipisa_functions import pipisa_time
|
|||||||
|
|
||||||
from global_conf import CONFIG
|
from global_conf import CONFIG
|
||||||
|
|
||||||
#### https://docs.python-arango.com/en/main/
|
from db_logic import tops
|
||||||
from arango import ArangoClient
|
from db_logic import collections
|
||||||
|
|
||||||
|
|
||||||
admins = CONFIG['telegram_admins_ids']
|
admins = CONFIG['telegram_admins_ids']
|
||||||
|
|
||||||
|
|
||||||
def get_dicks_collection():
|
|
||||||
arango_client = ArangoClient(hosts=CONFIG['databaso']['host'] )
|
|
||||||
pipisa_db = arango_client.db(
|
|
||||||
CONFIG['databaso']['base'],
|
|
||||||
username=CONFIG['databaso']['user'],
|
|
||||||
password=CONFIG['databaso']['pass']
|
|
||||||
)
|
|
||||||
dicks_collection = pipisa_db.collection(CONFIG['databaso']['collection'])
|
|
||||||
|
|
||||||
return dicks_collection
|
|
||||||
|
|
||||||
|
|
||||||
@dp.message_handler(commands=["dick"])
|
@dp.message_handler(commands=["dick"])
|
||||||
async def up_dick(message: types.Message):
|
async def up_dick(message: types.Message):
|
||||||
|
|
||||||
if message.from_user.id in admins or message.chat.type != 'private':
|
if message.from_user.id in admins or message.chat.type != 'private':
|
||||||
|
|
||||||
dicks_collection = get_dicks_collection()
|
dicks_collection = collections.get_dicks_collection()
|
||||||
|
|
||||||
#### TODO уплатить нолог с 100 см для самого нищего
|
#### TODO уплатить нолог с 100 см для самого нищего
|
||||||
|
|
||||||
@ -150,42 +140,19 @@ async def up_dick(message: types.Message):
|
|||||||
async def send_topchat(message: types.Message):
|
async def send_topchat(message: types.Message):
|
||||||
if message.from_user.id in admins or message.chat.type != 'private':
|
if message.from_user.id in admins or message.chat.type != 'private':
|
||||||
|
|
||||||
top_ = False
|
top_ = message['text'].startswith('/topdick')
|
||||||
glob_ = False
|
glob_ = message['text'].startswith('/globaldick')
|
||||||
dicks_collection = get_dicks_collection()
|
|
||||||
|
|
||||||
if message['text'].statswith('/topdick'):
|
if top_:
|
||||||
top_ = True
|
dickos = tops.get_tops( top_=True, chat_id=message.chat.id )
|
||||||
try:
|
elif glob_:
|
||||||
dicks = dicks_collection.find({'chat_id': message.chat.id}, skip=0, limit=1100)
|
dickos = tops.get_tops( glob_=True )
|
||||||
dicks = [d for d in dicks]
|
|
||||||
except Exception as e:
|
|
||||||
print('ошибка DB в /topdick')
|
|
||||||
print(e)
|
|
||||||
elif message['text'].statswith('/globaldick'):
|
|
||||||
glob_ = True
|
|
||||||
try:
|
|
||||||
dicks = dicks_collection.all( )
|
|
||||||
dicks = [d for d in dicks if d['user_id'] != d['chat_id']]
|
|
||||||
except Exception as e:
|
|
||||||
print('ошибка DB в /globaldick')
|
|
||||||
print(e)
|
|
||||||
else:
|
else:
|
||||||
print('вызывают хз что!')
|
print('вызывают хз что!')
|
||||||
|
|
||||||
top_dicks = sorted(dicks, key=lambda dick: dick['dick_size'], reverse=True)
|
if not dickos:
|
||||||
top_dicks = top_dicks[:( min(len(top_dicks), 10) )]
|
|
||||||
|
|
||||||
dickos = ''
|
|
||||||
emo = ['🏆','🚀','🍆','🍌','🐍','🐎','🌭','🌶','👌','💩']
|
|
||||||
|
|
||||||
if len(top_dicks) == 0:
|
|
||||||
await bot.send_message(message.chat.id, '🍆 Никто ничего не нарастил! 🍌')
|
await bot.send_message(message.chat.id, '🍆 Никто ничего не нарастил! 🍌')
|
||||||
else:
|
else:
|
||||||
for i in range(len(top_dicks)):
|
|
||||||
dickos += f' {emo[i]} {i+1}. {top_dicks[i]["user_fullname"]}: {top_dicks[i]["dick_size"]}см\n'
|
|
||||||
i += 1
|
|
||||||
|
|
||||||
if top_:
|
if top_:
|
||||||
await bot.send_message(message.chat.id, '🏆Топ 10 бубылд чата🏆\n\n' + dickos)
|
await bot.send_message(message.chat.id, '🏆Топ 10 бубылд чата🏆\n\n' + dickos)
|
||||||
elif glob_:
|
elif glob_:
|
||||||
|
Loading…
Reference in New Issue
Block a user