Example #1
0
def add_flist(chat_id, fed_name):

    adder = Fban(str(chat_id), fed_name)

    SESSION.add(adder)

    SESSION.commit()
Example #2
0
def add_welcome_setting(chat_id, custom_welcome_message, should_clean_welcome,
                        previous_welcome, media_file_id):
    # adder = SESSION.query(Welcome).get(chat_id)
    adder = Welcome(chat_id, custom_welcome_message, should_clean_welcome,
                    previous_welcome, media_file_id)
    SESSION.add(adder)
    SESSION.commit()
Example #3
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()
Example #4
0
def add_filter(
    chat_id,
    keyword,
    reply,
    snip_type,
    media_id,
    media_access_hash,
    media_file_reference,
):
    adder = SESSION.query(Filters).get((str(chat_id), keyword))
    if adder:
        adder.reply = reply
        adder.snip_type = snip_type
        adder.media_id = media_id
        adder.media_access_hash = media_access_hash
        adder.media_file_reference = media_file_reference
    else:
        adder = Filters(
            chat_id,
            keyword,
            reply,
            snip_type,
            media_id,
            media_access_hash,
            media_file_reference,
        )
    SESSION.add(adder)
    SESSION.commit()
Example #5
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()
        CHAT_BLACKLISTS.setdefault(str(chat_id), set()).add(trigger)
def addgmex(chat_id):
    try:
        adder = GMEX(str(chat_id))
        SESSION.add(adder)
        SESSION.commit()
    except Exception as e:
        print(str(e))
Example #7
0
def add_to_broadcastlist(keywoard, group_id):
    with USERBROADCAST_INSERTION_LOCK:
        broadcast_group = UserBroadcast(keywoard, str(group_id))

        SESSION.merge(broadcast_group)
        SESSION.commit()
        BROADCAST_SQL_.BROADCAST_CHANNELS.setdefault(keywoard,
                                                     set()).add(str(group_id))
Example #8
0
def remove_s(
    user_id,
    chat_id
):
    note = SESSION.query(LydiaAI).get((user_id, chat_id))
    if note:
        SESSION.delete(note)
        SESSION.commit()
Example #9
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()
Example #10
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()
Example #11
0
def delgvar(variable):
    rem = (
        SESSION.query(Globals)
        .filter(Globals.variable == str(variable))
        .delete(synchronize_session="fetch")
    )
    if rem:
        SESSION.commit()
Example #12
0
def add_note(chat_id, keyword, reply):
    adder = SESSION.query(Notes).get((str(chat_id), keyword))
    if adder:
        adder.reply = reply
    else:
        adder = Notes(str(chat_id), keyword, reply)
    SESSION.add(adder)
    SESSION.commit()
Example #13
0
def add_channel(chat_id, channel):
    adder = SESSION.query(forceSubscribe).get(chat_id)
    if adder:
        adder.channel = channel
    else:
        adder = forceSubscribe(chat_id, channel)
    SESSION.add(adder)
    SESSION.commit()
Example #14
0
def del_flist(chat_id):

    rem = SESSION.query(Fban).get(str(chat_id))

    if rem:

        SESSION.delete(rem)

        SESSION.commit()
Example #15
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()
Example #16
0
def add_url(tg_chat_id, tg_feed_link, tg_old_entry_link):

    with INSERTION_LOCK:

        action = RSS(tg_chat_id, tg_feed_link, tg_old_entry_link)

        SESSION.add(action)

        SESSION.commit()
Example #17
0
def rm_note(chat_id, keyword):
    to_check = get_note(chat_id, keyword)
    if not to_check:
        return False
    else:
        rem = SESSION.query(Notes).get((str(chat_id), keyword))
        SESSION.delete(rem)
        SESSION.commit()
        return True
Example #18
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
Example #19
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()
Example #20
0
def rm_wafu_setting(chat_id):
    try:
        rem = SESSION.query(Joinwafu).get(str(chat_id))
        if rem:
            SESSION.delete(rem)
            SESSION.commit()
            return True
    except BaseException:
        return False
Example #21
0
def save_credentials(user, credentials):
    saved_credentials = SESSION.query(GoogleDriveCreds).get(user)
    if not saved_credentials:
        saved_credentials = GoogleDriveCreds(user)

    saved_credentials.credentials = credentials

    SESSION.add(saved_credentials)
    SESSION.commit()
    return True
Example #22
0
def migrate_chat(old_chat_id, new_chat_id):
    with INSERTION_LOCK:
        flood = SESSION.query(FloodControl).get(str(old_chat_id))
        if flood:
            CHAT_FLOOD[str(new_chat_id)] = CHAT_FLOOD.get(
                str(old_chat_id), DEF_OBJ)
            flood.chat_id = str(new_chat_id)
            SESSION.commit()

        SESSION.close()
Example #23
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
Example #24
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

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

        SESSION.add(flood)
        SESSION.commit()
Example #25
0
def remove_url(tg_chat_id, tg_feed_link):

    with INSERTION_LOCK:

        # this loops to delete any possible duplicates for the same TG User ID, TG Chat ID and link

        for row in check_url_availability(tg_chat_id, tg_feed_link):

            # add the action to the DB query

            SESSION.delete(row)

        SESSION.commit()
Example #26
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
Example #27
0
def update_url(row_id, new_entry_links):

    with INSERTION_LOCK:

        row = SESSION.query(RSS).get(row_id)

        # set the new old_entry_link with the latest update from the RSS Feed

        row.old_entry_link = new_entry_links[0]

        # commit the changes to the DB

        SESSION.commit()
Example #28
0
def add_snip(keyword, reply, snip_type, media_id, media_access_hash, media_file_reference):
    adder = SESSION.query(Snips).get(keyword)
    if adder:
        adder.reply = reply
        adder.snip_type = snip_type
        adder.media_id = media_id
        adder.media_access_hash = media_access_hash
        adder.media_file_reference = media_file_reference
    else:
        adder = Snips(keyword, reply, snip_type, media_id,
                      media_access_hash, media_file_reference)
    SESSION.add(adder)
    SESSION.commit()
Example #29
0
def add_note(keyword, reply, note_type, media_id, media_access_hash,
             media_file_reference):
    adder = SESSION.query(notes).get(keyword)
    if adder:
        adder.reply = reply
        adder.note_type = note_type
        adder.media_id = media_id
        adder.media_access_hash = media_access_hash
        adder.media_file_reference = media_file_reference
    else:
        adder = notes(keyword, reply, note_type, media_id, media_access_hash,
                      media_file_reference)
    SESSION.add(adder)
    SESSION.commit()
Example #30
0
def rf_bl(chat_id, trigger):
    with BLACKLIST_FILTER_INSERTION_LOCK:
        blacklist_filt = SESSION.query(BLF2).get((str(chat_id), trigger))
        if blacklist_filt:
            if trigger in CHAT_BLACKLISTS.get(str(chat_id),
                                              set()):  # sanity check
                CHAT_BLACKLISTS.get(str(chat_id), set()).remove(trigger)

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

        SESSION.close()
        return False