Ejemplo n.º 1
0
def user_join_fed(bot: Bot, update: Update, args: List[str]):

        chat = update.effective_chat  # type: Optional[Chat]
        user = update.effective_user  # type: Optional[User]
        fed_id = sql.get_fed_id(chat.id)

        if is_user_fed_owner(fed_id, user.id) == False:
                update.effective_message.reply_text(tld(chat.id, "Only fed owner can do this!"))
                return

        msg = update.effective_message  # type: Optional[Message]
        user_id = extract_user(msg, args)
        if user_id:
                user = bot.get_chat(user_id)

        elif not msg.reply_to_message and not args:
                user = msg.from_user

        elif not msg.reply_to_message and (not args or (
                len(args) >= 1 and not args[0].startswith("@") and not args[0].isdigit() and not msg.parse_entities(
                [MessageEntity.TEXT_MENTION]))):
                msg.reply_text(tld(chat.id, "I can't extract a user from this."))
                return

        else:
            return

        print(sql.search_user_in_fed(fed_id, user_id))

        #if user_id == user_id:
        #        update.effective_message.reply_text(tld(chat.id, "Are you gonna promote yourself?"))
        #        return

        fed_id = sql.get_fed_id(chat.id)
        info = sql.get_fed_info(fed_id)
        OW = bot.get_chat(info.owner_id)
        HAHA = OW.id
        if user_id == HAHA:
                update.effective_message.reply_text(tld(chat.id, "Why are you trying to promote federation owner!?"))
                return

        if not sql.search_user_in_fed(fed_id, user_id) == False:
                update.effective_message.reply_text(tld(chat.id, "I can't promote user which is already a fed admin! But I can demote them."))
                return

        if user_id == bot.id:
                update.effective_message.reply_text(tld(chat.id, "I am already the federation admin and the one that manage it!"))
                return

        #else:
        #        return

        res = sql.user_join_fed(fed_id, user_id)
        if not res:
                update.effective_message.reply_text(tld(chat.id, "Failed to promoted! It might be because you are admin in another federation! Our code is still buggy, We are sorry for that!"))
                return

        update.effective_message.reply_text(tld(chat.id, "Promoted Successfully!"))
Ejemplo n.º 2
0
def user_join_fed(bot: Bot, update: Update, args: List[str]):

    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    fed_id = sql.get_fed_id(chat.id)

    if is_user_fed_owner(fed_id, user.id) == False:
        update.effective_message.reply_text(
            tld(chat.id, "Only fed owner can do this!"))
        return

    msg = update.effective_message  # type: Optional[Message]
    user_id = extract_user(msg, args)
    if user_id:
        user = bot.get_chat(user_id)

    elif not msg.reply_to_message and not args:
        user = msg.from_user

    elif not msg.reply_to_message and (
            not args or
        (len(args) >= 1 and not args[0].startswith("@")
         and not args[0].isdigit()
         and not msg.parse_entities([MessageEntity.TEXT_MENTION]))):
        msg.reply_text(tld(chat.id, "I can't extract a user from this."))
        return

    else:
        return

    print(sql.search_user_in_fed(fed_id, user_id))

    if is_user_fed_owner(fed_id, user.id) == True:
        update.effective_message.reply_text(
            tld(chat.id, "Are you gonna promote yourself?"))
        return

    elif not sql.search_user_in_fed(fed_id, user_id) == False:
        update.effective_message.reply_text(
            tld(
                chat.id,
                "I can't promote user which is already a fed admin! But I can demote them."
            ))
        return

    if user_id == bot.id:
        update.effective_message.reply_text(
            tld(
                chat.id,
                "I am already the federation admin and the one that manage it!"
            ))
        return

    #else:
    #        return

    res = sql.user_join_fed(fed_id, user_id)
    update.effective_message.reply_text(tld(chat.id, "Promoted Successfully!"))
Ejemplo n.º 3
0
def user_demote_fed(bot: Bot, update: Update, args: List[str]):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    fed_id = sql.get_fed_id(chat.id)

    if is_user_fed_owner(fed_id, user.id) == False:
        update.effective_message.reply_text(
            tld(chat.id, "Only fed owner can do this!"))
        return

    msg = update.effective_message  # type: Optional[Message]
    user_id = extract_user(msg, args)
    if user_id:
        user = bot.get_chat(user_id)

    elif not msg.reply_to_message and not args:
        user = msg.from_user

    elif not msg.reply_to_message and (
            not args or
        (len(args) >= 1 and not args[0].startswith("@")
         and not args[0].isdigit()
         and not msg.parse_entities([MessageEntity.TEXT_MENTION]))):
        msg.reply_text(tld(chat.id, "I can't extract a user from this."))
        return

    #else:
    #        return

    if user_id == bot.id:
        update.effective_message.reply_text(
            tld(
                chat.id,
                "What are you trying to do? Demoting me from your federation?")
        )
        return

    if sql.search_user_in_fed(fed_id, user_id) == False:
        update.effective_message.reply_text(
            tld(
                chat.id,
                "I can't demote user which not a fed admin! If you wanna bring him to tears, promote him first!"
            ))
        return

    res = sql.user_demote_fed(fed_id, user_id)
    if res == True:
        update.effective_message.reply_text(tld(chat.id, "Get out of here!"))
    else:
        update.effective_message.reply_text(
            tld(chat.id, "I can not remove him, I am powerless!"))
Ejemplo n.º 4
0
def user_join_fed(bot: Bot, update: Update, args: List[str]):
    chat = update.effective_chat
    user = update.effective_user
    msg = update.effective_message
    fed_id = sql.get_fed_id(chat.id)

    if is_user_fed_owner(fed_id, user.id):
        user_id = extract_user(msg, args)
        if user_id:
            user = bot.get_chat(user_id)
        elif not msg.reply_to_message and not args:
            user = msg.from_user
        elif not msg.reply_to_message and (
                not args or
            (len(args) >= 1 and not args[0].startswith("@")
             and not args[0].isdigit()
             and not msg.parse_entities([MessageEntity.TEXT_MENTION]))):
            msg.reply_text(tld(chat.id, "common_err_no_user"))
            return
        else:
            LOGGER.warning('error')
        getuser = sql.search_user_in_fed(fed_id, user_id)
        fed_id = sql.get_fed_id(chat.id)
        info = sql.get_fed_info(fed_id)
        get_owner = eval(info['fusers'])['owner']
        get_owner = bot.get_chat(get_owner).id
        if user_id == get_owner:
            update.effective_message.reply_text(
                tld(chat.id, "feds_promote_owner"))
            return
        if getuser:
            update.effective_message.reply_text(
                tld(chat.id, "feds_promote_owner"))
            return
        if user_id == bot.id:
            update.effective_message.reply_text(
                tld(chat.id, "feds_promote_bot"))
            return
        res = sql.user_join_fed(fed_id, user_id)
        if res:
            update.effective_message.reply_text(
                tld(chat.id, "feds_promote_success"))
        else:
            update.effective_message.reply_text("")
    else:
        update.effective_message.reply_text(tld(chat.id, "feds_owner_only"))
Ejemplo n.º 5
0
def user_demote_fed(bot: Bot, update: Update, args: List[str]):
    chat = update.effective_chat
    user = update.effective_user
    fed_id = sql.get_fed_id(chat.id)

    if is_user_fed_owner(fed_id, user.id):
        msg = update.effective_message
        user_id = extract_user(msg, args)
        if user_id:
            user = bot.get_chat(user_id)

        elif not msg.reply_to_message and not args:
            user = msg.from_user

        elif not msg.reply_to_message and (
                not args or
            (len(args) >= 1 and not args[0].startswith("@")
             and not args[0].isdigit()
             and not msg.parse_entities([MessageEntity.TEXT_MENTION]))):
            msg.reply_text(tld(chat.id, "common_err_no_user"))
            return
        else:
            LOGGER.warning('error')

        if user_id == bot.id:
            update.effective_message.reply_text(tld(chat.id,
                                                    "feds_demote_bot"))
            return

        if sql.search_user_in_fed(fed_id, user_id) == False:
            update.effective_message.reply_text(
                tld(chat.id, "feds_demote_target_not_admin"))
            return

        res = sql.user_demote_fed(fed_id, user_id)
        if res == True:
            update.effective_message.reply_text(
                tld(chat.id, "feds_demote_success"))
        else:
            update.effective_message.reply_text(
                tld(chat.id, "feds_demote_failed"))
    else:
        update.effective_message.reply_text(tld(chat.id, "feds_owner_only"))
        return
Ejemplo n.º 6
0
def user_join_fed(bot: Bot, update: Update, args: List[str]):
	chat = update.effective_chat  # type: Optional[Chat]
	user = update.effective_user  # type: Optional[User]
	msg = update.effective_message  # type: Optional[Message]
	fed_id = sql.get_fed_id(chat.id)

	if is_user_fed_owner(fed_id, user.id):
		user_id = extract_user(msg, args)
		if user_id:
			user = bot.get_chat(user_id)
		elif not msg.reply_to_message and not args:
			user = msg.from_user
		elif not msg.reply_to_message and (not args or (
			len(args) >= 1 and not args[0].startswith("@") and not args[0].isdigit() and not msg.parse_entities(
			[MessageEntity.TEXT_MENTION]))):
			msg.reply_text("I cannot extract users from this message")
			return
		else:
			LOGGER.warning('error')
		getuser = sql.search_user_in_fed(fed_id, user_id)
		fed_id = sql.get_fed_id(chat.id)
		info = sql.get_fed_info(fed_id)
		get_owner = eval(info['fusers'])['owner']
		get_owner = bot.get_chat(get_owner).id
		if user_id == get_owner:
			update.effective_message.reply_text("Why are you trying to promote a federation owner?")
			return
		if getuser:
			update.effective_message.reply_text("I cannot promote users who are already federation admins! But I can remove them if you want!")
			return
		if user_id == bot.id:
			update.effective_message.reply_text("I already am a federation admin in all federations!")
			return
		res = sql.user_join_fed(fed_id, user_id)
		if res:
			update.effective_message.reply_text("Successfully Promoted!")
		else:
			update.effective_message.reply_text("Failed to promote!")
	else:
		update.effective_message.reply_text("Only federation owners can do this!")
Ejemplo n.º 7
0
def user_demote_fed(bot: Bot, update: Update, args: List[str]):
	chat = update.effective_chat  # type: Optional[Chat]
	user = update.effective_user  # type: Optional[User]
	fed_id = sql.get_fed_id(chat.id)

	if is_user_fed_owner(fed_id, user.id):
		msg = update.effective_message  # type: Optional[Message]
		user_id = extract_user(msg, args)
		if user_id:
			user = bot.get_chat(user_id)

		elif not msg.reply_to_message and not args:
			user = msg.from_user

		elif not msg.reply_to_message and (not args or (
			len(args) >= 1 and not args[0].startswith("@") and not args[0].isdigit() and not msg.parse_entities(
			[MessageEntity.TEXT_MENTION]))):
			msg.reply_text("I cannot extract users from this message")
			return
		else:
			LOGGER.warning('error')

		if user_id == bot.id:
			update.effective_message.reply_text("Are you trying to demote me as a federation admin? Do you think I am stupid?")
			return

		if sql.search_user_in_fed(fed_id, user_id) == False:
			update.effective_message.reply_text("I cannot demote people who are not federation admins!")
			return

		res = sql.user_demote_fed(fed_id, user_id)
		if res == True:
			update.effective_message.reply_text("Get out of here!")
		else:
			update.effective_message.reply_text("Demotion failed!")
	else:
		update.effective_message.reply_text("Only federation owners can do this!")
		return