示例#1
0
def set_del_joined(chat_id, del_joined):
    with INSERTION_LOCK:
        curr = SESSION.query(Welcome).get(str(chat_id))
        if not curr:
            curr = Welcome(str(chat_id))

        curr.del_joined = int(del_joined)

        SESSION.add(curr)
        SESSION.commit()
示例#2
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()
示例#3
0
def set_gdbye_preference(chat_id, should_goodbye):
    with INSERTION_LOCK:
        curr = SESSION.query(Welcome).get(str(chat_id))
        if not curr:
            curr = Welcome(str(chat_id), should_goodbye=should_goodbye)
        else:
            curr.should_goodbye = should_goodbye

        SESSION.add(curr)
        SESSION.commit()
示例#4
0
def set_clean_welcome(chat_id, clean_welcome):
    with INSERTION_LOCK:
        curr = SESSION.query(Welcome).get(str(chat_id))
        if not curr:
            curr = Welcome(str(chat_id))

        curr.clean_welcome = int(clean_welcome)

        SESSION.add(curr)
        SESSION.commit()
示例#5
0
def disable_gmutes(chat_id):
    with GMUTE_SETTING_LOCK:
        chat = SESSION.query(GmuteSettings).get(str(chat_id))
        if not chat:
            chat = GmuteSettings(chat_id, False)

        chat.setting = False
        SESSION.add(chat)
        SESSION.commit()
        GMUTESTAT_LIST.add(str(chat_id))
示例#6
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

        SESSION.add(flood)
        SESSION.commit()
示例#7
0
def toggle_dnd(user_id, reason=""):
    with INSERTION_LOCK:
        curr = SESSION.query(DND).get(user_id)
        if not curr:
            curr = DND(user_id, reason, True)
        elif curr.is_dnd:
            curr.is_dnd = False
        elif not curr.is_dnd:
            curr.is_dnd = True
        SESSION.add(curr)
        SESSION.commit()
示例#8
0
def enable_nlp(chat_id):
    with NLP_SETTING_LOCK:
        chat = SESSION.query(NLPSettings).get(str(chat_id))
        if not chat:
            chat = NLPSettings(chat_id, True)

        chat.setting = True
        SESSION.add(chat)
        SESSION.commit()
        if str(chat_id) in NLPSTAT_LIST:
            NLPSTAT_LIST.remove(str(chat_id))
示例#9
0
def add_iLike(chat_id, msg_id, user_id, iliketype):
    with INSERTION_LOCK:
        new_ilikes_id = str(chat_id)+str(msg_id)
        ilikes_id = SESSION.query(iLikes).get(str(new_ilikes_id))
        if not ilikes_id:
            ilikes_id = iLikes(new_ilikes_id, user_id, str(iliketype))
            SESSION.add(ilikes_id)
            SESSION.commit()
            return True
        else:
            return False
示例#10
0
def migrate_chat(old_chat_id, new_chat_id):
    with DISABLE_INSERTION_LOCK:
        chats = SESSION.query(Disable).filter(Disable.chat_id == str(old_chat_id)).all()
        for chat in chats:
            chat.chat_id = str(new_chat_id)
            SESSION.add(chat)

        if str(old_chat_id) in DISABLED:
            DISABLED[str(new_chat_id)] = DISABLED.get(str(old_chat_id), set())

        SESSION.commit()
示例#11
0
def toggle_afk(user_id, reason=""):
    with INSERTION_LOCK:
        curr = SESSION.query(AFK).get(user_id)
        if not curr:
            curr = AFK(user_id, reason, True)
        elif curr.is_afk:
            curr.is_afk = False
        elif not curr.is_afk:
            curr.is_afk = True
        SESSION.add(curr)
        SESSION.commit()
示例#12
0
def set_frules(fed_id, rules):
    with FEDS_LOCK:
        r = SESSION.query(RulesF).get(fed_id)
        if r:
            print("fund prev")
            SESSION.delete(r)
        r = RulesF(str(fed_id), rules)

        SESSION.add(r)
        SESSION.commit()
        return r
示例#13
0
def add_filter(
    chat_id,
    keyword,
    reply,
    is_sticker=False,
    is_document=False,
    is_image=False,
    is_audio=False,
    is_voice=False,
    is_video=False,
    buttons=None,
):
    global CHAT_FILTERS

    if buttons is None:
        buttons = []

    with CUST_FILT_LOCK:
        prev = SESSION.query(CustomFilters).get((str(chat_id), keyword))
        if prev:
            with BUTTON_LOCK:
                prev_buttons = (
                    SESSION.query(Buttons)
                    .filter(Buttons.chat_id == str(chat_id), Buttons.keyword == keyword)
                    .all()
                )
                for btn in prev_buttons:
                    SESSION.delete(btn)
            SESSION.delete(prev)

        filt = CustomFilters(
            str(chat_id),
            keyword,
            reply,
            is_sticker,
            is_document,
            is_image,
            is_audio,
            is_voice,
            is_video,
            bool(buttons),
        )

        if keyword not in CHAT_FILTERS.get(str(chat_id), []):
            CHAT_FILTERS[str(chat_id)] = sorted(
                CHAT_FILTERS.get(str(chat_id), []) + [keyword],
                key=lambda x: (-len(x), x),
            )

        SESSION.add(filt)
        SESSION.commit()

    for b_name, url, same_line in buttons:
        add_note_button_to_db(chat_id, keyword, b_name, url, same_line)
示例#14
0
def enable_birthdays(chat_id):
	with BIRTHDAY_LOCK:
		chat = SESSION.query(BirthdaySettings).get(str(chat_id))
		if not chat:
			chat = BirthdaySettings(chat_id, True)

		chat.setting = True
		SESSION.add(chat)
		SESSION.commit()
		if str(chat_id) in BIRTHDAYSTAT_LIST:
			BIRTHDAYSTAT_LIST.remove(str(chat_id))
示例#15
0
def enable_gmutes(chat_id):
    with GMUTE_SETTING_LOCK:
        chat = SESSION.query(GmuteSettings).get(str(chat_id))
        if not chat:
            chat = GmuteSettings(chat_id, True)

        chat.setting = True
        SESSION.add(chat)
        SESSION.commit()
        if str(chat_id) in GMUTESTAT_LIST:
            GMUTESTAT_LIST.remove(str(chat_id))
示例#16
0
def enable_antispam(chat_id):
    with ASPAM_SETTING_LOCK:
        chat = SESSION.query(AntispamSettings).get(str(chat_id))
        if not chat:
            chat = AntispamSettings(chat_id, True)

        chat.setting = True
        SESSION.add(chat)
        SESSION.commit()
        if str(chat_id) in GBANSTAT_LIST:
            GBANSTAT_LIST.remove(str(chat_id))
示例#17
0
def blacklist_user(user_id, reason=None):
    with BLACKLIST_LOCK:
        user = SESSION.query(BlacklistUsers).get(str(user_id))
        if not user:
            user = BlacklistUsers(str(user_id), reason)
        else:
            user.reason = reason

        SESSION.add(user)
        SESSION.commit()
        __load_blacklist_userid_list()
示例#18
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))
示例#19
0
def set_feds_setting(user_id: int, setting: bool):
    with FEDS_SETTINGS_LOCK:
        global FEDERATION_NOTIFICATION
        user_setting = SESSION.query(FedsUserSettings).get(user_id)
        if not user_setting:
            user_setting = FedsUserSettings(user_id)

        user_setting.should_report = setting
        FEDERATION_NOTIFICATION[str(user_id)] = setting
        SESSION.add(user_setting)
        SESSION.commit()
示例#20
0
def set_ses(chat_id, ses_id, expires):
    with INSERTION_LOCK:
        autochat = SESSION.query(ChatbotChats).get(str(chat_id))
        if not autochat:
            autochat = ChatbotChats(str(chat_id), str(ses_id), str(expires))
        else:
            autochat.ses_id = str(ses_id)
            autochat.expires = str(expires)

        SESSION.add(autochat)
        SESSION.commit()
示例#21
0
def set_chat_log_channel(chat_id, log_channel):
    with LOGS_INSERTION_LOCK:
        res = SESSION.query(GroupLogs).get(str(chat_id))
        if res:
            res.log_channel = log_channel
        else:
            res = GroupLogs(chat_id, log_channel)
            SESSION.add(res)

        CHANNELS[str(chat_id)] = log_channel
        SESSION.commit()
示例#22
0
def enable_gkicks(chat_id):
    with GKICK_SETTING_LOCK:
        chat = SESSION.query(GkickSettings).get(str(chat_id))
        if not chat:
            chat = GkickSettings(chat_id, True)

        chat.setting = True
        SESSION.add(chat)
        SESSION.commit()
        if str(chat_id) in GKICKSTAT_LIST:
            GKICKSTAT_LIST.remove(str(chat_id))
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.add(user)
        SESSION.commit()
        __load_gbanned_userid_list()
示例#24
0
def set_afk(user_id, afk_time, reason=""):
    with INSERTION_LOCK:
        curr = SESSION.query(AFK).get(user_id)
        if not curr:
            curr = AFK(user_id, afk_time, reason, True)
        else:
            curr.is_afk = True

        AFK_USERS[user_id] = reason

        SESSION.add(curr)
        SESSION.commit()
示例#25
0
def chat_join_fed(fed_id, chat_id):
    with FEDS_LOCK:
        global FEDERATION_CHATS, FEDERATION_CHATS_BYID
        r = ChatF(chat_id, fed_id)
        SESSION.add(r)
        FEDERATION_CHATS[str(chat_id)] = {"fid": fed_id}
        checkid = FEDERATION_CHATS_BYID.get(fed_id)
        if checkid is None:
            FEDERATION_CHATS_BYID[fed_id] = []
        FEDERATION_CHATS_BYID[fed_id].append(str(chat_id))
        SESSION.commit()
        return r
示例#26
0
def increment(article_id, title):
    article_id = int(article_id)  # ensure int

    with SEARCHES_LOCK:
        article = SESSION.query(TopSearches).get(article_id)
        if not article:
            article = TopSearches(article_id, title)

        article.hits = article.hits + 1
        article.title = title
        SESSION.add(article)
        SESSION.commit()
示例#27
0
def set_channel_for_force_join(chat_id, channel_id):
    with INSERTION_LOCK:
        curr = SESSION.query(Channel).get(chat_id)
        if not curr:
            curr = Channel(chat_id, channel_id)
        else:
            curr.channel_id = channel_id

        ENABLED_CHATS[chat_id] = channel_id

        SESSION.add(curr)
        SESSION.commit()
示例#28
0
def set_lang(chat_id: str, lang: str) -> None:
    with LANG_LOCK:
        curr = SESSION.query(ChatLangs).get(str(chat_id))
        if not curr:
            curr = ChatLangs(str(chat_id), lang)
            SESSION.add(curr)
            SESSION.flush()
        else:
            curr.language = lang

        CHAT_LANG[str(chat_id)] = lang
        SESSION.commit()
示例#29
0
def new_fed(owner_id, fed_id, fed_name):
    with FEDS_LOCK:
        r = Federations(str(owner_id), fed_id, fed_name)
        SESSION.add(r)
        try:
            SESSION.commit()
            return r
        except:
            SESSION.rollback()
            return False
        finally:
            SESSION.commit()
示例#30
0
def disable_command(chat_id, disable):
    with DISABLE_INSERTION_LOCK:
        disabled = SESSION.query(Disable).get((str(chat_id), disable))

        if not disabled:
            disabled = Disable(str(chat_id), disable)
            SESSION.add(disabled)
            SESSION.commit()
            return True

        SESSION.close()
        return False