Python telegram.User() Examples

The following are 30 code examples of telegram.User(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module telegram , or try the search function .
Example #1
Source File: global_bans.py    From SkittBot with GNU General Public License v3.0 7 votes vote down vote up
def enforce_gban(bot: Bot, update: Update):
    # Not using @restrict handler to avoid spamming - just ignore if cant gban.
    if sql.does_chat_gban(update.effective_chat.id) and update.effective_chat.get_member(bot.id).can_restrict_members:
        user = update.effective_user  # type: Optional[User]
        chat = update.effective_chat  # type: Optional[Chat]
        msg = update.effective_message  # type: Optional[Message]

        if user and not is_user_admin(chat, user.id):
            check_and_ban(update, user.id)

        if msg.new_chat_members:
            new_members = update.effective_message.new_chat_members
            for mem in new_members:
                check_and_ban(update, mem.id)

        if msg.reply_to_message:
            user = msg.reply_to_message.from_user  # type: Optional[User]
            if user and not is_user_admin(chat, user.id):
                check_and_ban(update, user.id, should_message=False) 
Example #2
Source File: connection.py    From EmiliaHikari with GNU General Public License v3.0 6 votes vote down vote up
def connection_chat(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]

    conn = connected(context.bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if update.effective_message.chat.type != "private":
            return
        chat = update.effective_chat
        chat_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title

    if conn:
        teks = languages.tl(update.effective_message, "Saat ini Anda terhubung dengan {}.\n").format(chat_name)
    else:
        teks = languages.tl(update.effective_message, "Saat ini Anda tidak terhubung dengan grup.\n")
    teks += languages.tl(update.effective_message, "supportcmd")
    send_message(update.effective_message, teks, parse_mode="markdown") 
Example #3
Source File: global_mutes.py    From SkittBot with GNU General Public License v3.0 6 votes vote down vote up
def enforce_gmute(bot: Bot, update: Update):
    # Not using @restrict handler to avoid spamming - just ignore if cant gmute.
    if sql.does_chat_gmute(update.effective_chat.id) and update.effective_chat.get_member(bot.id).can_restrict_members:
        user = update.effective_user  # type: Optional[User]
        chat = update.effective_chat  # type: Optional[Chat]
        msg = update.effective_message  # type: Optional[Message]

        if user and not is_user_admin(chat, user.id):
            check_and_mute(bot, update, user.id, should_message=True)
        if msg.new_chat_members:
            new_members = update.effective_message.new_chat_members
            for mem in new_members:
                check_and_mute(bot, update, mem.id, should_message=True)
        if msg.reply_to_message:
            user = msg.reply_to_message.from_user  # type: Optional[User]
            if user and not is_user_admin(chat, user.id):
                check_and_mute(bot, update, user.id, should_message=True) 
Example #4
Source File: welcome.py    From SkittBot with GNU General Public License v3.0 6 votes vote down vote up
def set_goodbye(bot: Bot, update: Update) -> str:
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    msg = update.effective_message  # type: Optional[Message]
    text, data_type, content, buttons = get_welcome_type(msg)

    if data_type is None:
        msg.reply_text("You didn't specify what to reply with!")
        return ""

    sql.set_custom_gdbye(chat.id, content or text, data_type, buttons)
    msg.reply_text("Successfully set custom goodbye message!")
    return "<b>{}:</b>" \
           "\n#SET_GOODBYE" \
           "\n<b>Admin:</b> {}" \
           "\nSet the goodbye message.".format(html.escape(chat.title),
                                               mention_html(user.id, user.first_name)) 
Example #5
Source File: userinfo.py    From SkittBot with GNU General Public License v3.0 6 votes vote down vote up
def set_about_bio(bot: Bot, update: Update):
    message = update.effective_message  # type: Optional[Message]
    sender = update.effective_user  # type: Optional[User]
    if message.reply_to_message:
        repl_message = message.reply_to_message
        user_id = repl_message.from_user.id
        if user_id == message.from_user.id:
            message.reply_text("Ha, you can't set your own bio! You're at the mercy of others here...")
            return
        elif user_id == bot.id and sender.id not in SUDO_USERS:
            message.reply_text("Erm... yeah, I only trust sudo users to set my bio.")
            return

        text = message.text
        bio = text.split(None, 1)  # use python's maxsplit to only remove the cmd, hence keeping newlines.
        if len(bio) == 2:
            if len(bio[1]) < MAX_MESSAGE_LENGTH // 4:
                sql.set_user_bio(user_id, bio[1])
                message.reply_text("Updated {}'s bio!".format(repl_message.from_user.first_name))
            else:
                message.reply_text(
                    "A bio needs to be under {} characters! You tried to set {}.".format(
                        MAX_MESSAGE_LENGTH // 4, len(bio[1])))
    else:
        message.reply_text("Reply to someone's message to set their bio!") 
Example #6
Source File: disable.py    From SkittBot with GNU General Public License v3.0 6 votes vote down vote up
def check_update(self, update):
            chat = update.effective_chat  # type: Optional[Chat]
            user = update.effective_user  # type: Optional[User]
            if super().check_update(update):
                # Should be safe since check_update passed.
                command = update.effective_message.text_html.split(None, 1)[0][1:].split('@')[0]

                # disabled, admincmd, user admin
                if sql.is_command_disabled(chat.id, command):
                    return command in ADMIN_CMDS and is_user_admin(chat, user.id)

                # not disabled
                else:
                    return True

            return False 
Example #7
Source File: welcome.py    From SkittBot with GNU General Public License v3.0 6 votes vote down vote up
def set_welcome(bot: Bot, update: Update) -> str:
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    msg = update.effective_message  # type: Optional[Message]

    text, data_type, content, buttons = get_welcome_type(msg)

    if data_type is None:
        msg.reply_text("You didn't specify what to reply with!")
        return ""

    sql.set_custom_welcome(chat.id, content or text, data_type, buttons)
    msg.reply_text("Successfully set custom welcome message!")

    return "<b>{}:</b>" \
           "\n#SET_WELCOME" \
           "\n<b>Admin:</b> {}" \
           "\nSet the welcome message.".format(html.escape(chat.title),
                                               mention_html(user.id, user.first_name)) 
Example #8
Source File: locks.py    From SkittBot with GNU General Public License v3.0 6 votes vote down vote up
def lock(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    if can_delete(chat, bot.id):
        if len(args) >= 1:
            if args[0] in LOCK_TYPES:
                sql.update_lock(chat.id, args[0], locked=True)
                message.reply_text("Locked {} messages for all non-admins!".format(args[0]))

                return "<b>{}:</b>" \
                       "\n#LOCK" \
                       "\n<b>Admin:</b> {}" \
                       "\nLocked <code>{}</code>.".format(html.escape(chat.title),
                                                          mention_html(user.id, user.first_name), args[0])

            elif args[0] in RESTRICTION_TYPES:
                sql.update_restriction(chat.id, args[0], locked=True)
                if args[0] == "previews":
                    members = users_sql.get_chat_members(str(chat.id))
                    restr_members(bot, chat.id, members, messages=True, media=True, other=True)

                message.reply_text("Locked {} for all non-admins!".format(args[0]))
                return "<b>{}:</b>" \
                       "\n#LOCK" \
                       "\n<b>Admin:</b> {}" \
                       "\nLocked <code>{}</code>.".format(html.escape(chat.title),
                                                          mention_html(user.id, user.first_name), args[0])

            else:
                message.reply_text("What are you trying to lock...? Try /locktypes for the list of lockables")

    else:
        message.reply_text("I'm not an administrator, or haven't got delete rights.")

    return "" 
Example #9
Source File: warns.py    From SkittBot with GNU General Public License v3.0 6 votes vote down vote up
def reset_warns(bot: Bot, update: Update, args: List[str]) -> str:
    message = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]

    user_id = extract_user(message, args)

    if user_id:
        sql.reset_warns(user_id, chat.id)
        message.reply_text("Warnings have been reset!")
        warned = chat.get_member(user_id).user
        return "<b>{}:</b>" \
               "\n#RESETWARNS" \
               "\n<b>Admin:</b> {}" \
               "\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title),
                                                            mention_html(user.id, user.first_name),
                                                            mention_html(warned.id, warned.first_name),
                                                            warned.id)
    else:
        message.reply_text("No user has been designated!")
    return "" 
Example #10
Source File: warns.py    From SkittBot with GNU General Public License v3.0 6 votes vote down vote up
def reply_filter(bot: Bot, update: Update) -> str:
    chat = update.effective_chat  # type: Optional[Chat]
    message = update.effective_message  # type: Optional[Message]

    chat_warn_filters = sql.get_chat_warn_triggers(chat.id)
    to_match = extract_text(message)
    if not to_match:
        return ""

    for keyword in chat_warn_filters:
        pattern = r"( |^|[^\w])" + re.escape(keyword) + r"( |$|[^\w])"
        if re.search(pattern, to_match, flags=re.IGNORECASE):
            user = update.effective_user  # type: Optional[User]
            warn_filter = sql.get_warn_filter(chat.id, keyword)
            return warn(user, chat, warn_filter.reply, message)
    return "" 
Example #11
Source File: warns.py    From SkittBot with GNU General Public License v3.0 6 votes vote down vote up
def set_warn_limit(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    msg = update.effective_message  # type: Optional[Message]

    if args:
        if args[0].isdigit():
            if int(args[0]) < 3:
                msg.reply_text("The minimum warn limit is 3!")
            else:
                sql.set_warn_limit(chat.id, int(args[0]))
                msg.reply_text("Updated the warn limit to {}".format(args[0]))
                return "<b>{}:</b>" \
                       "\n#SET_WARN_LIMIT" \
                       "\n<b>Admin:</b> {}" \
                       "\nSet the warn limit to <code>{}</code>".format(html.escape(chat.title),
                                                                        mention_html(user.id, user.first_name), args[0])
        else:
            msg.reply_text("Give me a number as an arg!")
    else:
        limit, soft_warn = sql.get_warn_setting(chat.id)

        msg.reply_text("The current warn limit is {}".format(limit))
    return "" 
Example #12
Source File: admin.py    From SkittBot with GNU General Public License v3.0 6 votes vote down vote up
def pin(bot: Bot, update: Update, args: List[str]) -> str:
    user = update.effective_user  # type: Optional[User]
    chat = update.effective_chat  # type: Optional[Chat]

    is_group = chat.type != "private" and chat.type != "channel"

    prev_message = update.effective_message.reply_to_message

    is_silent = True
    if len(args) >= 1:
        is_silent = not (args[0].lower() == 'notify' or args[0].lower() == 'loud' or args[0].lower() == 'violent')

    if prev_message and is_group:
        try:
            bot.pinChatMessage(chat.id, prev_message.message_id, disable_notification=is_silent)
        except BadRequest as excp:
            if excp.message == "Chat_not_modified":
                pass
            else:
                raise
        return "<b>{}:</b>" \
               "\n#PINNED" \
               "\n<b>Admin:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name))

    return "" 
Example #13
Source File: admin.py    From SkittBot with GNU General Public License v3.0 6 votes vote down vote up
def unpin(bot: Bot, update: Update) -> str:
    chat = update.effective_chat
    user = update.effective_user  # type: Optional[User]

    try:
        bot.unpinChatMessage(chat.id)
    except BadRequest as excp:
        if excp.message == "Chat_not_modified":
            pass
        else:
            raise

    return "<b>{}:</b>" \
           "\n#UNPINNED" \
           "\n<b>Admin:</b> {}".format(html.escape(chat.title),
                                       mention_html(user.id, user.first_name)) 
Example #14
Source File: __main__.py    From EmiliaHikari with GNU General Public License v3.0 6 votes vote down vote up
def get_settings(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    msg = update.effective_message  # type: Optional[Message]
    args = msg.text.split(None, 1)

    # ONLY send settings in PM
    if chat.type != chat.PRIVATE:
        if is_user_admin(chat, user.id):
            text = tl(update.effective_message, "Klik di sini untuk mendapatkan pengaturan obrolan ini, serta milik Anda.")
            msg.reply_text(text,
                           reply_markup=InlineKeyboardMarkup(
                               [[InlineKeyboardButton(text="Pengaturan",
                                                      url="t.me/{}?start=stngs_{}".format(
                                                          context.bot.username, chat.id))]]))
        # else:
        #     text = tl(update.effective_message, "Klik di sini untuk memeriksa pengaturan Anda.")

    else:
        send_settings(chat.id, user.id, True) 
Example #15
Source File: chat_status.py    From EmiliaHikari with GNU General Public License v3.0 6 votes vote down vote up
def user_admin(func):
	@wraps(func)
	def is_admin(update, context, *args, **kwargs):
		if update.effective_chat.type == "private":
			return func(update, context, *args, **kwargs)
		user = update.effective_user  # type: Optional[User]
		if user and is_user_admin(update.effective_chat, user.id):
			return func(update, context, *args, **kwargs)

		elif not user:
			pass

		elif DEL_CMDS and " " not in update.effective_message.text:
			update.effective_message.delete()

		else:
			update.effective_message.reply_text(languages.tl(update.effective_message, "Siapa ini yang bukan admin memberikan perintah kepada saya?"))

	return is_admin 
Example #16
Source File: global_bans.py    From EmiliaHikari with GNU General Public License v3.0 6 votes vote down vote up
def enforce_gban(update, context):
    # Not using @restrict handler to avoid spamming - just ignore if cant gban.
    if sql.does_chat_gban(update.effective_chat.id) and update.effective_chat.get_member(context.bot.id).can_restrict_members:
        user = update.effective_user  # type: Optional[User]
        chat = update.effective_chat  # type: Optional[Chat]
        msg = update.effective_message  # type: Optional[Message]

        if user and not is_user_admin(chat, user.id):
            check_and_ban(update, user.id)

        if msg.new_chat_members:
            new_members = update.effective_message.new_chat_members
            for mem in new_members:
                check_and_ban(update, mem.id)

        if msg.reply_to_message:
            user = msg.reply_to_message.from_user  # type: Optional[User]
            if user and not is_user_admin(chat, user.id):
                check_and_ban(update, user.id, should_message=False) 
Example #17
Source File: welcome.py    From EmiliaHikari with GNU General Public License v3.0 6 votes vote down vote up
def set_welcome(update, context) -> str:
	chat = update.effective_chat  # type: Optional[Chat]
	user = update.effective_user  # type: Optional[User]
	msg = update.effective_message  # type: Optional[Message]

	# If user is not set text and not reply a message
	if not msg.reply_to_message:
		if len(msg.text.split()) == 1:
			send_message(update.effective_message, tl(update.effective_message, "Anda harus memberikan isi dalam pesan selamat datang!\nKetik `/welcomehelp` untuk beberapa bantuan pada welcome"), parse_mode="markdown")
			return ""

	text, data_type, content, buttons = get_welcome_type(msg)

	if data_type is None:
		send_message(update.effective_message, tl(update.effective_message, "Anda tidak menentukan apa yang harus dibalas!"))
		return ""

	sql.set_custom_welcome(chat.id, content, text, data_type, buttons)
	send_message(update.effective_message, tl(update.effective_message, "Berhasil mengatur pesan sambutan kustom!"))

	return "<b>{}:</b>" \
		   "\n#SET_WELCOME" \
		   "\n<b>Admin:</b> {}" \
		   "\nSet a welcome message.".format(html.escape(chat.title),
											   mention_html(user.id, user.first_name)) 
Example #18
Source File: welcome.py    From EmiliaHikari with GNU General Public License v3.0 6 votes vote down vote up
def set_goodbye(update, context) -> str:
	chat = update.effective_chat  # type: Optional[Chat]
	user = update.effective_user  # type: Optional[User]
	msg = update.effective_message  # type: Optional[Message]

	# If user is not set text and not reply a message
	if not msg.reply_to_message:
		if len(msg.text.split()) == 1:
			send_message(update.effective_message, tl(update.effective_message, "Anda harus memberikan isi dalam pesan selamat datang!\nKetik `/welcomehelp` untuk beberapa bantuan pada welcome"), parse_mode="markdown")
			return ""

	text, data_type, content, buttons = get_welcome_type(msg)

	if data_type is None:
		send_message(update.effective_message, tl(update.effective_message, "Anda tidak menentukan apa yang harus dibalas!"))
		return ""

	sql.set_custom_gdbye(chat.id, content, text, data_type, buttons)
	send_message(update.effective_message, tl(update.effective_message, "Berhasil mengatur pesan selamat tinggal kustom!"))
	return "<b>{}:</b>" \
		   "\n#SET_GOODBYE" \
		   "\n<b>Admin:</b> {}" \
		   "\nSet a goodbye message.".format(html.escape(chat.title),
											   mention_html(user.id, user.first_name)) 
Example #19
Source File: welcome.py    From EmiliaHikari with GNU General Public License v3.0 6 votes vote down vote up
def check_sw(bot: Bot, user_id, user, message):
	try:
		SWT = SPAMWATCH_TOKEN
	except:
		return False
	json = requests.get(SPAMWATCH_URL + str(user_id), headers={"Authorization": "Bearer {}".format(SWT)}).json()
	if json.get('code') == 404:
		return False
	is_success = False
	try:
		context.bot.kickChatMember(message.chat.id, user_id)
		is_success = True
	except:
		context.bot.sendMessage(message.chat.id, "*⚠️ WARNING!*\n{} is a spammer from SpamWatch and has been added to fedban list of *Team Nusantara Disciplinary Circle*!\n\nIt's recommended to banned him/her!".format(mention_markdown(user_id, user.first_name)), parse_mode="markdown", disable_web_page_preview=True)
	if is_success:
		context.bot.sendMessage(message.chat.id, "{} has been banned and added to fedban list of *Team Nusantara Disciplinary Circle*!\nReason: {}.".format(mention_markdown(user_id, user.first_name), json.get('reason') if json.get('reason') else "Unknown reason"), parse_mode="markdown", disable_web_page_preview=True)
	fed_id = fedsql.get_fed_info("TeamNusantaraDevs")
	if fed_id:
		x = fedsql.fban_user("TeamNusantaraDevs", user_id, user.first_name, user.last_name, user.username, json.get('reason') if json.get('reason') else "Unknown reason", int(time.time()))
		if not x:
			LOGGER.warning("Cannot fban spammer user!")
			return
		text = "*New FedBan*\n*Fed:* `TeamNusantaraDevs`\n*FedAdmin*: {}\n*User:* {}\n*User ID:* `{}`\n*Reason:* [SpamWatch] {}".format(mention_markdown(692882995, "Emilia"), mention_markdown(user_id, user.first_name + (" " + user.last_name if user.last_name != None else "")), user_id, json.get('reason') if json.get('reason') else "Unknown reason")
		context.bot.sendMessage(-1001338861977, text, parse_mode="markdown", disable_web_page_preview=True)
		print(">>> NEW FBAN SW: {} {} in {}".format(user.first_name, user_id, message.chat.title)) 
Example #20
Source File: reporting.py    From EmiliaHikari with GNU General Public License v3.0 6 votes vote down vote up
def user_protection_checker(bot, user_id):
	if not user_id:
		return False, tl(update.effective_message, "Anda sepertinya tidak mengacu pada pengguna.")

	if int(user_id) == OWNER_ID:
		return False, "\n\nError: This one is my owner!"

	if int(user_id) in SUDO_USERS:
		return False, "\n\nError: User is under protection"

	# if int(user_id) in SUPPORT_USERS:
	# 	return False, "Error: User is under protection"

	if int(user_id) == bot.id:
		return False, "\n\nError: This is myself!"

	return True, "" 
Example #21
Source File: feds.py    From EmiliaHikari with GNU General Public License v3.0 6 votes vote down vote up
def leave_fed(update, context):
	chat = update.effective_chat  # type: Optional[Chat]
	user = update.effective_user  # type: Optional[User]
	args = context.args

	if chat.type == 'private':
		send_message(update.effective_message, tl(update.effective_message, "Perintah ini di khususkan untuk grup, bukan pada PM!"))
		return

	fed_id = sql.get_fed_id(chat.id)
	fed_info = sql.get_fed_info(fed_id)

	# administrators = chat.get_administrators().status
	getuser = context.bot.get_chat_member(chat.id, user.id).status
	if getuser in 'creator' or user.id in SUDO_USERS:
		if sql.chat_leave_fed(chat.id) == True:
			get_fedlog = sql.get_fed_log(fed_id)
			if get_fedlog:
				if eval(get_fedlog):
					context.bot.send_message(get_fedlog, tl(update.effective_message, "Obrolan *{}* telah keluar ke federasi *{}*").format(chat.title, fed_info['fname']), parse_mode="markdown")
			send_message(update.effective_message, tl(update.effective_message, "Obrolan ini telah keluar dari federasi {}!").format(fed_info['fname']))
		else:
			send_message(update.effective_message, tl(update.effective_message, "Mengapa Anda meninggalkan federasi ketika Anda belum bergabung?!"))
	else:
		send_message(update.effective_message, tl(update.effective_message, "Hanya pembuat grup yang dapat melakukannya!")) 
Example #22
Source File: connection.py    From EmiliaHikari with GNU General Public License v3.0 6 votes vote down vote up
def connected(bot, update, chat, user_id, need_admin=True):
    user = update.effective_user  # type: Optional[User]
        
    if chat.type == chat.PRIVATE and sql.get_connected_chat(user_id):
        conn_id = sql.get_connected_chat(user_id).chat_id
        getstatusadmin = bot.get_chat_member(conn_id, update.effective_message.from_user.id)
        isadmin = getstatusadmin.status in ('administrator', 'creator')
        ismember = getstatusadmin.status in ('member')
        isallow = sql.allow_connect_to_chat(conn_id)
        if (isadmin) or (isallow and ismember) or (user.id in SUDO_USERS):
            if need_admin == True:
                if getstatusadmin.status in ('administrator', 'creator') or user_id in SUDO_USERS:
                    return conn_id
                else:
                    send_message(update.effective_message, languages.tl(update.effective_message, "Anda harus menjadi admin dalam grup yang terhubung!"))
            else:
                return conn_id
        else:
            send_message(update.effective_message, languages.tl(update.effective_message, "Grup mengubah koneksi hak atau Anda bukan admin lagi.\nSaya putuskan koneksi Anda."))
            disconnect_chat(update, bot)
    else:
        return False 
Example #23
Source File: feds.py    From EmiliaHikari with GNU General Public License v3.0 6 votes vote down vote up
def fed_notif(update, context):
	chat = update.effective_chat  # type: Optional[Chat]
	user = update.effective_user  # type: Optional[User]
	msg = update.effective_message  # type: Optional[Message]
	args = context.args
	fed_id = sql.get_fed_id(chat.id)

	if not fed_id:
		send_message(update.effective_message, tl(update.effective_message, "Grup ini tidak dalam federasi apa pun!"))
		return

	if args:
		if args[0] in ("yes", "on", "ya"):
			sql.set_feds_setting(user.id, True)
			send_message(update.effective_message, tl(update.effective_message, "Pelaporan federasi hidup! Setiap ada pengguna yang di fban/unfban anda akan di beritahu via PM."))
		elif args[0] in ("no", "off", "ga"):
			sql.set_feds_setting(user.id, False)
			send_message(update.effective_message, tl(update.effective_message, "Pelaporan federasi mati! Setiap ada pengguna yang di fban/unfban anda tidak akan di beritahu via PM."))
		else:
			send_message(update.effective_message, tl(update.effective_message, "Tolong masukan `ya`/`on`/`ga`/`off`"), parse_mode="markdown")
	else:
		getreport = sql.user_feds_report(user.id)
		send_message(update.effective_message, tl(update.effective_message, "Preferensi laporan federasi anda saat ini: `{}`").format(getreport), parse_mode="markdown") 
Example #24
Source File: feds.py    From EmiliaHikari with GNU General Public License v3.0 6 votes vote down vote up
def set_fed_log(update, context):
	chat = update.effective_chat  # type: Optional[Chat]
	user = update.effective_user  # type: Optional[User]
	msg = update.effective_message  # type: Optional[Message]
	args = context.args

	if chat.type == 'private':
		send_message(update.effective_message, tl(update.effective_message, "Perintah ini di khususkan untuk grup, bukan pada PM!"))
		return

	if args:
		fedinfo = sql.get_fed_info(args[0])
		if not fedinfo:
			send_message(update.effective_message, tl(update.effective_message, "Federasi ini tidak ada!"))
			return
		isowner = is_user_fed_owner(args[0], user.id)
		if not isowner:
			send_message(update.effective_message, tl(update.effective_message, "Hanya pencipta federasi yang bisa menetapkan log federasi."))
			return
		setlog = sql.set_fed_log(args[0], chat.id)
		if setlog:
			send_message(update.effective_message, tl(update.effective_message, "Log federasi `{}` telah di setel pada {}").format(fedinfo['fname'], chat.title), parse_mode="markdown")
	else:
		send_message(update.effective_message, tl(update.effective_message, "Anda belum memberikan ID federasinya!")) 
Example #25
Source File: userinfo.py    From EmiliaHikari with GNU General Public License v3.0 6 votes vote down vote up
def set_about_bio(update, context):
    message = update.effective_message  # type: Optional[Message]
    sender = update.effective_user  # type: Optional[User]
    if message.reply_to_message:
        repl_message = message.reply_to_message
        user_id = repl_message.from_user.id
        if user_id == message.from_user.id:
            send_message(update.effective_message, tl(update.effective_message, "Ha, Anda tidak dapat mengatur bio Anda sendiri! Anda berada di bawah belas kasihan orang lain di sini..."))
            return
        elif user_id == bot.id and sender.id not in SUDO_USERS:
            send_message(update.effective_message, tl(update.effective_message, "Umm ... yah, saya hanya mempercayai pengguna sudo untuk mengatur bio saya."))
            return

        text = message.text
        bio = text.split(None, 1)  # use python's maxsplit to only remove the cmd, hence keeping newlines.
        if len(bio) == 2:
            if len(bio[1]) < MAX_MESSAGE_LENGTH // 4:
                sql.set_user_bio(user_id, bio[1])
                send_message(update.effective_message, tl(update.effective_message, "Bio {} diperbarui!").format(repl_message.from_user.first_name))
            else:
                send_message(update.effective_message, 
                    tl(update.effective_message, "Biografi harus di bawah {} karakter! Anda mencoba mengatur {}.").format(
                        MAX_MESSAGE_LENGTH // 4, len(bio[1])))
    else:
        send_message(update.effective_message, tl(update.effective_message, "Balas pesan seseorang untuk mengatur bio mereka!")) 
Example #26
Source File: chat_status.py    From EmiliaHikari with GNU General Public License v3.0 6 votes vote down vote up
def user_admin_no_reply(func):
	@wraps(func)
	def is_admin(update, context, *args, **kwargs):
		user = update.effective_user  # type: Optional[User]
		if user and is_user_admin(update.effective_chat, user.id):
			return func(update, context, *args, **kwargs)

		elif not user:
			pass

		elif DEL_CMDS and " " not in update.effective_message.text:
			update.effective_message.delete()

		else:
			context.bot.answer_callback_query(update.callback_query.id, languages.tl(update.effective_message, "Anda bukan admin di grup ini!"))

	return is_admin 
Example #27
Source File: connection.py    From EmiliaHikari with GNU General Public License v3.0 5 votes vote down vote up
def help_connect_chat(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    args = context.args

    if update.effective_message.chat.type != "private":
        send_message(update.effective_message, languages.tl(update.effective_message, "PM saya dengan command itu untuk mendapatkan bantuan Koneksi"))
        return
    else:
        send_message(update.effective_message, languages.tl(update.effective_message, "supportcmd"), parse_mode="markdown") 
Example #28
Source File: welcome.py    From EmiliaHikari with GNU General Public License v3.0 5 votes vote down vote up
def clean_welcome(update, context):
	chat = update.effective_chat  # type: Optional[Chat]
	user = update.effective_user  # type: Optional[User]
	args = context.args

	if not args:
		clean_pref = sql.get_clean_pref(chat.id)
		if clean_pref:
			send_message(update.effective_message, tl(update.effective_message, "Saya *akan* menghapus pesan selamat datang hingga dua hari."), parse_mode="markdown")
		else:
			send_message(update.effective_message, tl(update.effective_message, "Saat ini saya *tidak akan* menghapus pesan selamat datang yang lama!"), parse_mode="markdown")
		return ""

	if args[0].lower() in ("on", "yes"):
		sql.set_clean_welcome(str(chat.id), True)
		send_message(update.effective_message, tl(update.effective_message, "Saya *akan* mencoba menghapus pesan selamat datang yang lama!"), parse_mode="markdown")
		return "<b>{}:</b>" \
			   "\n#CLEAN_WELCOME" \
			   "\n<b>Admin:</b> {}" \
			   "\nHas toggled clean welcomes to <code>ON</code>.".format(html.escape(chat.title),
																							 mention_html(user.id, user.first_name))
	elif args[0].lower() in ("off", "no"):
		sql.set_clean_welcome(str(chat.id), False)
		send_message(update.effective_message, tl(update.effective_message, "Saya *tidak akan* menghapus pesan selamat datang yang lama."), parse_mode="markdown")
		return "<b>{}:</b>" \
			   "\n#CLEAN_WELCOME" \
			   "\n<b>Admin:</b> {}" \
			   "\nHas toggled clean welcomes to <code>OFF</code>.".format(html.escape(chat.title),
																		  mention_html(user.id, user.first_name))
	else:
		# idk what you're writing, say yes or no
		send_message(update.effective_message, tl(update.effective_message, "Saya hanya mengerti 'on/yes' or 'off/no' saja!"))
		return "" 
Example #29
Source File: models.py    From selfmailbot with MIT License 5 votes vote down vote up
def get_user_instance(user: telegram.User, chat_id: int) -> User:
    instance, created = User.get_or_create(
        pk=user.id,
        defaults=dict(
            pk=user.id,
            full_name=user.full_name,
            username=user.username,
            confirmation=str(uuid.uuid4()),
            chat_id=chat_id,
        ),
    )
    return instance 
Example #30
Source File: feds.py    From EmiliaHikari with GNU General Public License v3.0 5 votes vote down vote up
def fed_info(update, context):
	chat = update.effective_chat  # type: Optional[Chat]
	user = update.effective_user  # type: Optional[User]
	args = context.args
	if args:
		fed_id = args[0]
		info = sql.get_fed_info(fed_id)
	else:
		fed_id = sql.get_fed_id(chat.id)
		if not fed_id:
			send_message(update.effective_message, tl(update.effective_message, "Grup ini tidak dalam federasi apa pun!"))
			return
		info = sql.get_fed_info(fed_id)

	owner = context.bot.get_chat(info['owner'])
	try:
		owner_name = owner.first_name + " " + owner.last_name
	except:
		owner_name = owner.first_name
	FEDADMIN = sql.all_fed_users(fed_id)
	FEDADMIN.append(int(owner.id))
	TotalAdminFed = len(FEDADMIN)

	user = update.effective_user  # type: Optional[Chat]
	chat = update.effective_chat  # type: Optional[Chat]
	info = sql.get_fed_info(fed_id)

	text = tl(update.effective_message, "<b>ℹ️ Info federasi:</b>")
	text += "\nFedID: <code>{}</code>".format(fed_id)
	text += tl(update.effective_message, "\nNama: {}").format(info['fname'])
	text += tl(update.effective_message, "\nPembuat: {}").format(mention_html(owner.id, owner_name))
	text += tl(update.effective_message, "\nSeluruh admin: <code>{}</code>").format(TotalAdminFed)
	getfban = sql.get_all_fban_users(fed_id)
	text += tl(update.effective_message, "\nTotal yang di banned: <code>{}</code>").format(len(getfban))
	getfchat = sql.all_fed_chats(fed_id)
	text += tl(update.effective_message, "\nTotal grup yang terkoneksi: <code>{}</code>").format(len(getfchat))

	send_message(update.effective_message, text, parse_mode=ParseMode.HTML)