Пример #1
0
def addgvar(variable, value):
    if SESSION.query(Globals).filter(
            Globals.variable == str(variable)).one_or_none():
        delgvar(variable)
    adder = Globals(str(variable), value)
    SESSION.add(adder)
    SESSION.commit()
Пример #2
0
def set_warn_strength(chat_id, soft_warn):
    with WARN_SETTINGS_LOCK:
        curr_setting = SESSION.query(WarnSettings).get(str(chat_id))
        if not curr_setting:
            curr_setting = WarnSettings(chat_id, soft_warn=soft_warn)
        curr_setting.soft_warn = soft_warn
        SESSION.add(curr_setting)
        SESSION.commit()
Пример #3
0
def add_to_blacklist(chat_id, trigger):
    with BLACKLIST_FILTER_INSERTION_LOCK:
        blacklist_filt = BlackListFilters(str(chat_id), trigger)

        SESSION.merge(blacklist_filt)  # merge to avoid duplicate key issues
        SESSION.commit()
        BLACKLIST_SQL_.CHAT_BLACKLISTS.setdefault(str(chat_id),
                                                  set()).add(trigger)
Пример #4
0
def set_warn_limit(chat_id, warn_limit):
    with WARN_SETTINGS_LOCK:
        curr_setting = SESSION.query(WarnSettings).get(str(chat_id))
        if not curr_setting:
            curr_setting = WarnSettings(chat_id, warn_limit=warn_limit)
        curr_setting.warn_limit = warn_limit
        SESSION.add(curr_setting)
        SESSION.commit()
Пример #5
0
def add_s(user_id, chat_id, session_id, session_expires):
    adder = SESSION.query(LydiaAI).get((user_id, chat_id))
    if adder:
        adder.session_id = session_id
        adder.session_expires = session_expires
    else:
        adder = LydiaAI(user_id, chat_id, session_id, session_expires)
    SESSION.add(adder)
    SESSION.commit()
Пример #6
0
def init_locks(chat_id, reset=False):
    curr_restr = SESSION.query(Locks).get(str(chat_id))
    if reset:
        SESSION.delete(curr_restr)
        SESSION.flush()
    restr = Locks(str(chat_id))
    SESSION.add(restr)
    SESSION.commit()
    return restr
Пример #7
0
def reset_warns(user_id, chat_id):
    with WARN_INSERTION_LOCK:
        warned_user = SESSION.query(Warns).get((user_id, str(chat_id)))
        if warned_user:
            warned_user.num_warns = 0
            warned_user.reasons = ""
            SESSION.add(warned_user)
            SESSION.commit()
        SESSION.close()
Пример #8
0
def migrate_chat(old_chat_id, new_chat_id):
    with INSERTION_LOCK:
        flood = SESSION.query(FloodControl).get(str(old_chat_id))
        if flood:
            ANTIFLOOD_SQL_.CHAT_FLOOD[str(
                new_chat_id)] = ANTIFLOOD_SQL_.CHAT_FLOOD.get(
                    str(old_chat_id), DEF_OBJ)
            flood.chat_id = str(new_chat_id)
            SESSION.commit()

        SESSION.close()
Пример #9
0
def remove_warn(user_id, chat_id):
    with WARN_INSERTION_LOCK:
        removed = False
        warned_user = SESSION.query(Warns).get((user_id, str(chat_id)))
        if warned_user and warned_user.num_warns > 0:
            warned_user.num_warns -= 1
            SESSION.add(warned_user)
            SESSION.commit()
            removed = True
        SESSION.close()
        return removed
Пример #10
0
def set_flood(chat_id, amount):
    with INSERTION_LOCK:
        flood = SESSION.query(FloodControl).get(str(chat_id))
        if not flood:
            flood = FloodControl(str(chat_id))

        flood.user_id = None
        flood.limit = amount

        ANTIFLOOD_SQL_.CHAT_FLOOD[str(chat_id)] = (None, DEF_COUNT, amount)

        SESSION.add(flood)
        SESSION.commit()
Пример #11
0
def warn_user(user_id, chat_id, reason=None):
    with WARN_INSERTION_LOCK:
        warned_user = SESSION.query(Warns).get((user_id, str(chat_id)))
        if not warned_user:
            warned_user = Warns(user_id, str(chat_id))
        warned_user.num_warns += 1
        if reason:
            warned_user.reasons = warned_user.reasons + "\r\n\r\n" + reason
        reasons = warned_user.reasons
        num = warned_user.num_warns
        SESSION.add(warned_user)
        SESSION.commit()
        return num, reasons
Пример #12
0
def update_lock(chat_id, lock_type, locked):
    curr_perm = SESSION.query(Locks).get(str(chat_id))
    if not curr_perm:
        curr_perm = init_locks(chat_id)
    if lock_type == "bots":
        curr_perm.bots = locked
    elif lock_type == "commands":
        curr_perm.commands = locked
    elif lock_type == "email":
        curr_perm.email = locked
    elif lock_type == "forward":
        curr_perm.forward = locked
    elif lock_type == "url":
        curr_perm.url = locked
    SESSION.add(curr_perm)
    SESSION.commit()
Пример #13
0
def rm_from_blacklist(chat_id, trigger):
    with BLACKLIST_FILTER_INSERTION_LOCK:
        blacklist_filt = SESSION.query(BlackListFilters).get(
            (str(chat_id), trigger))
        if blacklist_filt:
            if trigger in BLACKLIST_SQL_.CHAT_BLACKLISTS.get(
                    str(chat_id), set()):  # sanity check
                BLACKLIST_SQL_.CHAT_BLACKLISTS.get(str(chat_id),
                                                   set()).remove(trigger)

            SESSION.delete(blacklist_filt)
            SESSION.commit()
            return True

        SESSION.close()
        return False
Пример #14
0
def gmute(sender):
    adder = GMute(str(sender))
    SESSION.add(adder)
    SESSION.commit()
Пример #15
0
def mute(sender, chat_id):
    adder = Mute(str(sender), str(chat_id))
    SESSION.add(adder)
    SESSION.commit()
Пример #16
0
def unmute(sender, chat_id):
    rem = SESSION.query(Mute).get((str(sender), str(chat_id)))
    if rem:
        SESSION.delete(rem)
        SESSION.commit()
Пример #17
0
def gparent_id(folder_id):
    adder = SESSION.query(Gdrive).get(folder_id)
    if not adder:
        adder = Gdrive(folder_id)
    SESSION.add(adder)
    SESSION.commit()
Пример #18
0
def addecho(user_id, chat_id):
    adder = ECHOSQL(str(user_id), str(chat_id))
    SESSION.add(adder)
    SESSION.commit()
Пример #19
0
def disapprove(chat_id):
    rem = SESSION.query(PMPermit).get(str(chat_id))
    if rem:
        SESSION.delete(rem)
        SESSION.commit()
Пример #20
0
def remove_echo(user_id, chat_id):
    note = SESSION.query(ECHOSQL).get((str(user_id), str(chat_id)))
    if note:
        SESSION.delete(note)
        SESSION.commit()
Пример #21
0
def approve(chat_id, reason):
    adder = PMPermit(str(chat_id), str(reason))
    SESSION.add(adder)
    SESSION.commit()
Пример #22
0
def ungmute(sender):
    rem = SESSION.query(GMute).get((str(sender)))
    if rem:
        SESSION.delete(rem)
        SESSION.commit()
Пример #23
0
def disapprove_all():
    SESSION.query(PMPermit).delete()
    SESSION.commit()
Пример #24
0
def approve(chat_id):
    adder = NOLogPMs(chat_id)
    SESSION.add(adder)
    SESSION.commit()
Пример #25
0
def delgvar(variable):
    rem = (SESSION.query(Globals).filter(
        Globals.variable == str(variable)).delete(synchronize_session="fetch"))
    if rem:
        SESSION.commit()
Пример #26
0
def disapprove(chat_id):
    rem = SESSION.query(NOLogPMs).get(chat_id)
    if rem:
        SESSION.delete(rem)
        SESSION.commit()
Пример #27
0
def remove_s(user_id, chat_id):
    note = SESSION.query(LydiaAI).get((user_id, chat_id))
    if note:
        SESSION.delete(note)
        SESSION.commit()
Пример #28
0
def catgban(chat_id, reason):
    adder = GBan(str(chat_id), str(reason))
    SESSION.add(adder)
    SESSION.commit()
Пример #29
0
def rmparent_id(folder_id):
    note = SESSION.query(Gdrive).filter(Gdrive.cat == folder_id)
    if note:
        note.delete()
        SESSION.commit()
Пример #30
0
def catungban(chat_id):
    rem = SESSION.query(GBan).get(str(chat_id))
    if rem:
        SESSION.delete(rem)
        SESSION.commit()