コード例 #1
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()
コード例 #2
0
def enable_gbans(chat_id):
    with GBAN_SETTING_LOCK:
        chat = SESSION.query(GbanSettings).get(str(chat_id))
        if not chat:
            chat = GbanSettings(chat_id, True)

        chat.setting = True
        SESSION.add(chat)
        SESSION.commit()
        if str(chat_id) in GBANSTAT_LIST:
            GBANSTAT_LIST.remove(str(chat_id))
コード例 #3
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()
コード例 #4
0
def gban_user(user_id, name, reason=None):
    with GBANNED_USERS_LOCK:
        user = SESSION.query(GloballyBannedUsers).get(user_id)
        if not user:
            user = GloballyBannedUsers(user_id, name, reason)
        else:
            user.name = name
            user.reason = reason

        SESSION.merge(user)
        SESSION.commit()
        __load_gbanned_userid_list()
コード例 #5
0
ファイル: welcome_sql.py プロジェクト: sourya/UniBorg
def add_welcome_setting(chat_id, should_clean_welcome, previous_welcome,
                        f_mesg_id):
    adder = SESSION.query(Welcome).get(chat_id)
    if adder:
        adder.should_clean_welcome = should_clean_welcome
        adder.previous_welcome = previous_welcome
        adder.f_mesg_id = f_mesg_id
    else:
        adder = Welcome(chat_id, should_clean_welcome, previous_welcome,
                        f_mesg_id)
    SESSION.add(adder)
    SESSION.commit()
コード例 #6
0
def update_gban_reason(user_id, name, reason=None):
    with GBANNED_USERS_LOCK:
        user = SESSION.query(GloballyBannedUsers).get(user_id)
        if not user:
            return None
        old_reason = user.reason
        user.name = name
        user.reason = reason

        SESSION.merge(user)
        SESSION.commit()
        return old_reason
コード例 #7
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 CHAT_BLACKLISTS.get(str(chat_id), set()):
                CHAT_BLACKLISTS.get(str(chat_id), set()).remove(trigger)

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

        SESSION.close()
        return False
コード例 #8
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()
コード例 #9
0
ファイル: snips_sql.py プロジェクト: BigZ3R0/Z3R0Borg
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()
コード例 #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

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

        SESSION.add(flood)
        SESSION.commit()
コード例 #11
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()
コード例 #12
0
ファイル: warns_sql.py プロジェクト: RanaBaby/Rainbowrole
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
コード例 #13
0
ファイル: locks_sql.py プロジェクト: ziddibccha/UniBorg
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 == "url":
        curr_perm.url = locked
    elif lock_type == "bots":
        curr_perm.bots = locked
    elif lock_type == "forward":
        curr_perm.forward = locked
    elif lock_type == "commands":
        curr_perm.commands = locked
    SESSION.add(curr_perm)
    SESSION.commit()
コード例 #14
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()
コード例 #15
0
ファイル: welcome_sql.py プロジェクト: Nabijonova/UniBorg
def add_welcome_setting(chat_id,
                        custom_welcome_message,
                        should_clean_welcome,
                        previous_welcome,
                        message_type=0,
                        media_id=None,
                        media_access_hash=None,
                        media_file_reference=None):
    # adder = SESSION.query(Welcome).get(chat_id)
    adder = Welcome(chat_id, custom_welcome_message, should_clean_welcome,
                    previous_welcome, message_type, media_id,
                    media_access_hash, media_file_reference)
    SESSION.add(adder)
    SESSION.commit()
コード例 #16
0
def add_welcome_setting(
    chat_id,
    custom_welcome_message,
    should_clean_welcome,
    previous_welcome,
    media_file_id=None
):
    # 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()
コード例 #17
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  # TODO:: double check this wizardry

        reasons = warned_user.reasons
        num = warned_user.num_warns

        SESSION.add(warned_user)
        SESSION.commit()

        return num, reasons
コード例 #18
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()
コード例 #19
0
def remove_filter(chat_id, keyword):
    saved_filter = SESSION.query(Filters).get((chat_id, keyword))
    if saved_filter:
        SESSION.delete(saved_filter)
        SESSION.commit()
コード例 #20
0
def remove_chat_fban(chat_id):
    rem = SESSION.query(FBan).get(str(chat_id))
    if rem:
        SESSION.delete(rem)
        SESSION.commit()
コード例 #21
0
def add_chat_fban(chat_id):
    adder = FBan(str(chat_id))
    SESSION.add(adder)
    SESSION.commit()
コード例 #22
0
ファイル: globals.py プロジェクト: ImAnmusics1/BotHub-
def delgvar(variable):
    rem = SESSION.query(Globals).filter(Globals.variable == str(variable))\
        .delete(synchronize_session="fetch")
    if rem:
        SESSION.commit()
コード例 #23
0
ファイル: welcome_sql.py プロジェクト: sourya/UniBorg
def rm_welcome_setting(chat_id):
    rem = SESSION.query(Welcome).get(chat_id)
    if rem:
        SESSION.delete(rem)
        SESSION.commit()
コード例 #24
0
def disapprove(chat_id):
    rem = SESSION.query(forceSubscribe).get(chat_id)
    if rem:
        SESSION.delete(rem)
        SESSION.commit()
コード例 #25
0
def disapprove(chat_id):
    rem = SESSION.query(NOLogPMs).get(chat_id)
    if rem:
        SESSION.delete(rem)
        SESSION.commit()
コード例 #26
0
def approve(chat_id):
    adder = NOLogPMs(chat_id)
    SESSION.add(adder)
    SESSION.commit()
コード例 #27
0
def remove_all_filters(chat_id):
    saved_filter = SESSION.query(Filters).filter(Filters.chat_id == chat_id)
    if saved_filter:
        saved_filter.delete()
        SESSION.commit()
コード例 #28
0
ファイル: welcome_sql.py プロジェクト: sourya/UniBorg
def update_previous_welcome(chat_id, previous_welcome):
    row = SESSION.query(Welcome).get(chat_id)
    row.previous_welcome = previous_welcome
    # commit the changes to the DB
    SESSION.commit()
コード例 #29
0
def remove_s(user_id, chat_id):
    note = SESSION.query(LydiaAI).get((user_id, chat_id))
    if note:
        SESSION.delete(note)
        SESSION.commit()
コード例 #30
0
def rm_all_notes(chat_id):
    notes = SESSION.query(Notes).filter(Notes.chat_id == str(chat_id))
    if notes:
        notes.delete()
        SESSION.commit()