Best Python code snippet using pandera_python
dbhelper.py
Source:dbhelper.py  
1# This file is copied verbatim from https://kutt.it/8EL9Ol2# The author said "Ye."3# flake8: noqa: Q0004from userbot import MONGO, REDIS5# Mutes6async def mute(chatid, userid):7    if await is_muted(chatid, userid) is True:8        return False9    else:10        MONGO.mutes.insert_one({'chat_id': chatid, 'user_id': userid})11        return True12async def is_muted(chatid, userid):13    is_muted = MONGO.mutes.find_one({'chat_id': chatid, 'user_id': userid})14    if not is_muted:15        return False16    else:17        return True18async def unmute(chatid, userid):19    if await is_muted(chatid, userid) is False:20        return False21    else:22        MONGO.mutes.delete_one({'chat_id': chatid, 'user_id': userid})23        return True24async def get_muted(chatid):25    muted_db = MONGO.mutes.find({'chat_id': int(chatid)})26    muted = []27    for user in muted_db:28        muted.append(user["user_id"])29    return muted30# GMutes31async def gmute(userid):32    if await is_gmuted(userid) is True:33        return False34    else:35        MONGO.gmutes.insert_one({'user_id': userid})36        return True37async def is_gmuted(userid):38    is_gmuted = MONGO.gmutes.find_one({'user_id': userid})39    if not is_gmuted:40        return False41    else:42        return True43async def ungmute(userid):44    if await is_gmuted(userid) is False:45        return False46    else:47        MONGO.gmutes.delete_one({'user_id': userid})48        return True49async def get_gmuted():50    gmuted_db = MONGO.gmutes.find()51    gmuted = []52    for user in gmuted_db:53        gmuted.append(user["user_id"])54    return gmuted55# Filters56async def get_filters(chatid):57    return MONGO.filters.find({'chat_id': chatid})58async def get_filter(chatid, keyword):59    return MONGO.filters.find_one({'chat_id': chatid, 'keyword': keyword})60async def add_filter(chatid, keyword, msg):61    to_check = await get_filter(chatid, keyword)62    if not to_check:63        MONGO.filters.insert_one({64            'chat_id': chatid,65            'keyword': keyword,66            'msg': msg67        })68        return True69    else:70        MONGO.filters.update_one(71            {72                '_id': to_check["_id"],73                'chat_id': to_check["chat_id"],74                'keyword': to_check["keyword"],75            }, {"$set": {76                'msg': msg77            }})78        return False79async def delete_filter(chatid, keyword):80    to_check = await get_filter(chatid, keyword)81    if not to_check:82        return False83    else:84        MONGO.filters.delete_one({85            '_id': to_check["_id"],86            'chat_id': to_check["chat_id"],87            'keyword': to_check["keyword"],88            'msg': to_check["msg"]89        })90        return True91# Notes92async def get_notes(chatid):93    return MONGO.notes.find({'chat_id': chatid})94async def get_note(chatid, name):95    return MONGO.notes.find_one({'chat_id': chatid, 'name': name})96async def add_note(chatid, name, text):97    to_check = await get_note(chatid, name)98    if not to_check:99        MONGO.notes.insert_one({'chat_id': chatid, 'name': name, 'text': text})100        return True101    else:102        MONGO.notes.update_one(103            {104                '_id': to_check["_id"],105                'chat_id': to_check["chat_id"],106                'name': to_check["name"],107            }, {"$set": {108                'text': text109            }})110        return False111async def delete_note(chatid, name):112    to_check = await get_note(chatid, name)113    if not to_check:114        return False115    else:116        MONGO.notes.delete_one({117            '_id': to_check["_id"],118            'chat_id': to_check["chat_id"],119            'name': to_check["name"],120            'text': to_check["text"],121        })122# Lists123async def get_lists(chatid):124    return MONGO.lists.find({'$or': [{'chat_id': chatid}, {'chat_id': 0}]})125async def get_list(chatid, name):126    return MONGO.lists.find_one({127        '$or': [{128            'chat_id': chatid129        }, {130            'chat_id': 0131        }],132        'name': name133    })134async def add_list(chatid, name, items):135    to_check = await get_list(chatid, name)136    if not to_check:137        MONGO.lists.insert_one({138            'chat_id': chatid,139            'name': name,140            'items': items141        })142        return True143    else:144        MONGO.lists.update_one(145            {146                '_id': to_check["_id"],147                'chat_id': to_check["chat_id"],148                'name': to_check["name"],149            }, {"$set": {150                'items': items151            }})152        return False153async def delete_list(chatid, name):154    to_check = await get_list(chatid, name)155    if not to_check:156        return False157    else:158        MONGO.lists.delete_one({159            '_id': to_check["_id"],160            'chat_id': to_check["chat_id"],161            'name': to_check["name"],162            'items': to_check["items"],163        })164async def set_list(oldchatid, name, newchatid):165    to_check = await get_list(oldchatid, name)166    if not to_check:167        return False168    else:169        MONGO.lists.update_one(170            {171                '_id': to_check["_id"],172                'name': to_check["name"],173                'items': to_check["items"]174            }, {"$set": {175                'chat_id': newchatid176            }})177        return True178##########179async def approval(userid):180    to_check = MONGO.pmpermit.find_one({'user_id': userid})181    if to_check is None:182        MONGO.pmpermit.insert_one({'user_id': userid, 'approval': False})183        return False184    elif to_check['approval'] is False:185        return False186    elif to_check['approval'] is True:187        return True188async def approve(userid):189    if await approval(userid) is True:190        return False191    else:192        MONGO.pmpermit.update_one({'user_id': userid},193                                  {"$set": {194                                      'approval': True195                                  }})196        return True197async def block_pm(userid):198    if await approval(userid) is False:199        return False200    else:201        MONGO.pmpermit.update_one({'user_id': userid},202                                  {"$set": {203                                      'approval': False204                                  }})205        return True206async def notif_state():207    state = dict()208    state_db = MONGO.notif.find()209    for stat in state_db:210        state.update(stat)211    if not state:212        MONGO.notif.insert_one({'state': True})213        return True214    elif state["state"] is False:215        return False216    elif state["state"] is True:217        return True218async def __notif_id():219    id_real = dict()220    id_db = MONGO.notif.find()221    for id_s in id_db:222        id_real.update(id_s)223    return id_real["_id"]224async def notif_on():225    if await notif_state() is True:226        return False227    else:228        MONGO.notif.update({'_id': await __notif_id()},229                           {"$set": {230                               'state': True231                           }})232        return True233async def notif_off():234    if await notif_state() is False:235        return False236    else:237        MONGO.notif.update({'_id': await __notif_id()},238                           {"$set": {239                               'state': False240                           }})241        return True242def strb(redis_string):243    return str(redis_string)[2:-1]244async def is_afk():245    to_check = REDIS.get('is_afk')246    if to_check:247        return True248    else:249        return False250async def afk(reason):251    REDIS.set('is_afk', reason)252async def afk_reason():253    return strb(REDIS.get('is_afk'))254async def no_afk():255    REDIS.delete('is_afk')256# Fbans257async def get_fban():258    return MONGO.fban.find()259async def add_chat_fban(chatid):260    if await is_fban(chatid) is True:261        return False262    else:263        MONGO.fban.insert_one({'chatid': chatid})264async def remove_chat_fban(chatid):265    if await is_fban(chatid) is False:266        return False267    else:268        MONGO.fban.delete_one({'chatid': chatid})269        return True270async def is_fban(chatid):271    if not MONGO.fban.find_one({"chatid": chatid}):272        return False273    else:274        return True275# Gbans276async def get_gban():277    return MONGO.gban.find()278async def add_chat_gban(chatid):279    if await is_gban(chatid) is True:280        return False281    else:282        MONGO.gban.insert_one({'chatid': chatid})283async def remove_chat_gban(chatid):284    if await is_gban(chatid) is False:285        return False286    else:287        MONGO.gban.delete_one({'chatid': chatid})288        return True289async def is_gban(chatid):290    if not MONGO.gban.find_one({"chatid": chatid}):291        return False292    else:293        return True294# Time295async def get_time():296    return MONGO.misc.find_one({'timec': {297        '$exists': True298    }}, {299        'timec': 1,300        'timezone': 1301    })302async def set_time(country, timezone=1):303    to_check = await get_time()304    if to_check:305        MONGO.misc.update_one(306            {307                '_id': to_check['_id'],308                'timec': to_check['timec'],309                'timezone': to_check['timezone']310            }, {"$set": {311                'timec': country,312                'timezone': timezone313            }})314    else:315        MONGO.misc.insert_one({'timec': country, 'timezone': timezone})316# Weather317async def get_weather():318    return MONGO.misc.find_one({'weather_city': {319        '$exists': True320    }}, {'weather_city': 1})321async def set_weather(city):322    to_check = await get_weather()323    if to_check:324        MONGO.misc.update_one(325            {326                '_id': to_check['_id'],327                'weather_city': to_check['weather_city']328            }, {"$set": {329                'weather_city': city330            }})331    else:...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
