File size: 2,903 Bytes
19e1d1f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
import pymongo
from info import DATABASE_URI, DATABASE_NAME
from pyrogram import enums
import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.ERROR)
myclient = pymongo.MongoClient(DATABASE_URI)
mydb = myclient[DATABASE_NAME]
async def add_gfilter(gfilters, text, reply_text, btn, file, alert):
mycol = mydb[str(gfilters)]
# mycol.create_index([('text', 'text')])
data = {
'text':str(text),
'reply':str(reply_text),
'btn':str(btn),
'file':str(file),
'alert':str(alert)
}
try:
mycol.update_one({'text': str(text)}, {"$set": data}, upsert=True)
except:
logger.exception('Some error occured!', exc_info=True)
async def find_gfilter(gfilters, name):
mycol = mydb[str(gfilters)]
query = mycol.find( {"text":name})
# query = mycol.find( { "$text": {"$search": name}})
try:
for file in query:
reply_text = file['reply']
btn = file['btn']
fileid = file['file']
try:
alert = file['alert']
except:
alert = None
return reply_text, btn, alert, fileid
except:
return None, None, None, None
async def get_gfilters(gfilters):
mycol = mydb[str(gfilters)]
texts = []
query = mycol.find()
try:
for file in query:
text = file['text']
texts.append(text)
except:
pass
return texts
async def delete_gfilter(message, text, gfilters):
mycol = mydb[str(gfilters)]
myquery = {'text':text }
query = mycol.count_documents(myquery)
if query == 1:
mycol.delete_one(myquery)
await message.reply_text(
f"'`{text}`' deleted. I'll not respond to that gfilter anymore.",
quote=True,
parse_mode=enums.ParseMode.MARKDOWN
)
else:
await message.reply_text("Couldn't find that gfilter!", quote=True)
async def del_allg(message, gfilters):
if str(gfilters) not in mydb.list_collection_names():
await message.edit_text("Nothing to Remove !")
return
mycol = mydb[str(gfilters)]
try:
mycol.drop()
await message.edit_text(f"All gfilters has been removed !")
except:
await message.edit_text("Couldn't remove all gfilters !")
return
async def count_gfilters(gfilters):
mycol = mydb[str(gfilters)]
count = mycol.count()
return False if count == 0 else count
async def gfilter_stats():
collections = mydb.list_collection_names()
if "CONNECTION" in collections:
collections.remove("CONNECTION")
totalcount = 0
for collection in collections:
mycol = mydb[collection]
count = mycol.count()
totalcount += count
totalcollections = len(collections)
return totalcollections, totalcount
|