Python telegram.ext.Filters.user() Examples
The following are 30
code examples of telegram.ext.Filters.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.ext.Filters
, or try the search function
.
Example #1
Source File: misc.py From SkittBot with GNU General Public License v3.0 | 6 votes |
def get_id(bot: Bot, update: Update, args: List[str]): user_id = extract_user(update.effective_message, args) if user_id: if update.effective_message.reply_to_message and update.effective_message.reply_to_message.forward_from: user1 = update.effective_message.reply_to_message.from_user user2 = update.effective_message.reply_to_message.forward_from update.effective_message.reply_text( "The original sender, {}, has an ID of `{}`.\nThe forwarder, {}, has an ID of `{}`.".format( escape_markdown(user2.first_name), user2.id, escape_markdown(user1.first_name), user1.id), parse_mode=ParseMode.MARKDOWN) else: user = bot.get_chat(user_id) update.effective_message.reply_text("{}'s id is `{}`.".format(escape_markdown(user.first_name), user.id), parse_mode=ParseMode.MARKDOWN) else: chat = update.effective_chat # type: Optional[Chat] if chat.type == "private": update.effective_message.reply_text("Your id is `{}`.".format(chat.id), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text("This group's id is `{}`.".format(chat.id), parse_mode=ParseMode.MARKDOWN)
Example #2
Source File: special.py From EmiliaHikari with GNU General Public License v3.0 | 6 votes |
def getsticker(update, context): msg = update.effective_message chat_id = update.effective_chat.id if msg.reply_to_message and msg.reply_to_message.sticker: send_message(update.effective_message, "Hai " + "[{}](tg://user?id={})".format(msg.from_user.first_name, msg.from_user.id) + ", Silahkan cek file yang anda minta dibawah ini." "\nTolong gunakan fitur ini dengan bijak!", parse_mode=ParseMode.MARKDOWN) context.bot.sendChatAction(chat_id, "upload_document") file_id = msg.reply_to_message.sticker.file_id newFile = context.bot.get_file(file_id) newFile.download('sticker.png') context.bot.sendDocument(chat_id, document=open('sticker.png', 'rb')) context.bot.sendChatAction(chat_id, "upload_photo") context.bot.send_photo(chat_id, photo=open('sticker.png', 'rb')) else: send_message(update.effective_message, "Hai " + "[{}](tg://user?id={})".format(msg.from_user.first_name, msg.from_user.id) + ", Tolong balas pesan stiker untuk mendapatkan gambar stiker", parse_mode=ParseMode.MARKDOWN)
Example #3
Source File: admin.py From EmiliaHikari with GNU General Public License v3.0 | 6 votes |
def permanent_pin(update, context): user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] message = update.effective_message args = context.args get_permapin = sql.get_permapin(chat.id) if get_permapin and not user.id == context.bot.id: try: to_del = context.bot.pinChatMessage(chat.id, get_permapin, disable_notification=True) except BadRequest: sql.set_permapin(chat.id, 0) if chat.username: old_pin = "https://t.me/{}/{}".format(chat.username, get_permapin) else: old_pin = "https://t.me/c/{}/{}".format(str(chat.id)[4:], get_permapin) send_message(update.effective_message, tl(update.effective_message, "*Permanen pin error:*\nSaya tidak bisa menyematkan pesan di sini!\nPastikan saya admin dan dapat pin pesan.\n\nPermanen pin di nonaktifkan, [pesan permanen pin lama ada disini]({})").format(old_pin), parse_mode="markdown") return if to_del: try: context.bot.deleteMessage(chat.id, message.message_id+1) except BadRequest: print("Permanent pin error: cannot delete pin msg")
Example #4
Source File: feds.py From EmiliaHikari with GNU General Public License v3.0 | 6 votes |
def unset_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], None) if setlog: send_message(update.effective_message, tl(update.effective_message, "Log federasi `{}` telah di cabut 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 #5
Source File: feds.py From EmiliaHikari with GNU General Public License v3.0 | 6 votes |
def fed_chat(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] fed_id = sql.get_fed_id(chat.id) user_id = update.effective_message.from_user.id if not is_user_admin(update.effective_chat, user_id): send_message(update.effective_message, tl(update.effective_message, "Anda harus menjadi admin untuk menjalankan perintah ini")) return if not fed_id: send_message(update.effective_message, tl(update.effective_message, "Grup ini tidak dalam federasi apa pun!")) return 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, "Obrolan ini adalah bagian dari federasi berikut:") text += "\n{} (ID: <code>{}</code>)".format(info['fname'], fed_id) send_message(update.effective_message, text, parse_mode=ParseMode.HTML)
Example #6
Source File: feds.py From EmiliaHikari with GNU General Public License v3.0 | 6 votes |
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 #7
Source File: feds.py From EmiliaHikari with GNU General Public License v3.0 | 6 votes |
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 #8
Source File: feds.py From EmiliaHikari with GNU General Public License v3.0 | 6 votes |
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 #9
Source File: misc.py From Marie-2.0-English with GNU General Public License v3.0 | 5 votes |
def get_id(bot: Bot, update: Update, args: List[str]): user_id = extract_user(update.effective_message, args) if user_id: if update.effective_message.reply_to_message and update.effective_message.reply_to_message.forward_from: user1 = update.effective_message.reply_to_message.from_user user2 = update.effective_message.reply_to_message.forward_from update.effective_message.reply_text( "The original sender, {}, has an ID of `{}`.\nThe forwarder, {}, has an ID of `{}`.".format( escape_markdown(user2.first_name), user2.id, escape_markdown(user1.first_name), user1.id), parse_mode=ParseMode.MARKDOWN) else: user = bot.get_chat(user_id) update.effective_message.reply_text("{}'s id is `{}`.".format(escape_markdown(user.first_name), user.id), parse_mode=ParseMode.MARKDOWN) else: chat = update.effective_chat # type: Optional[Chat] if chat.type == "private": update.effective_message.reply_text("Your id is `{}`.".format(chat.id), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text("This group's id is `{}`.".format(chat.id), parse_mode=ParseMode.MARKDOWN)
Example #10
Source File: backups.py From EmiliaHikari with GNU General Public License v3.0 | 5 votes |
def put_chat(chat_id, user_id, value, chat_data): # print(chat_data) if value == False: status = False else: status = True chat_data[chat_id] = {'backups': {"status": status, "user": user_id, "value": value}}
Example #11
Source File: backups.py From EmiliaHikari with GNU General Public License v3.0 | 5 votes |
def get_chat(chat_id, chat_data): # print(chat_data) try: value = chat_data[chat_id]['backups'] return value except KeyError: return {"status": False, "user": None, "value": False}
Example #12
Source File: admin.py From EmiliaHikari with GNU General Public License v3.0 | 5 votes |
def invite(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] args = context.args 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": send_message(update.effective_message, tl(update.effective_message, "Anda bisa lakukan command ini pada grup, bukan pada PM")) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title if chat.username: send_message(update.effective_message, chat.username) elif chat.type == chat.SUPERGROUP or chat.type == chat.CHANNEL: bot_member = chat.get_member(context.bot.id) if bot_member.can_invite_users: invitelink = context.bot.exportChatInviteLink(chat.id) send_message(update.effective_message, invitelink) else: send_message(update.effective_message, tl(update.effective_message, "Saya tidak memiliki akses ke tautan undangan, coba ubah izin saya!")) else: send_message(update.effective_message, tl(update.effective_message, "Saya hanya dapat memberi Anda tautan undangan untuk supergroup dan saluran, maaf!"))
Example #13
Source File: admin.py From EmiliaHikari with GNU General Public License v3.0 | 5 votes |
def permapin(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] args = context.args conn = connected(context.bot, update, chat, user.id, need_admin=False) 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": send_message(update.effective_message, tl(update.effective_message, "Anda bisa lakukan command ini pada grup, bukan pada PM")) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title text, data_type, content, buttons = get_message_type(message) tombol = build_keyboard_alternate(buttons) try: message.delete() except BadRequest: pass if str(data_type) in ('Types.BUTTON_TEXT', 'Types.TEXT'): try: sendingmsg = context.bot.send_message(chat_id, text, parse_mode="markdown", disable_web_page_preview=True, reply_markup=InlineKeyboardMarkup(tombol)) except BadRequest: context.bot.send_message(chat_id, tl(update.effective_message, "Teks markdown salah!\nJika anda tidak tahu apa itu markdown, silahkan ketik `/markdownhelp` pada PM."), parse_mode="markdown") return else: sendingmsg = ENUM_FUNC_MAP[str(data_type)](chat_id, content, caption=text, parse_mode="markdown", disable_web_page_preview=True, reply_markup=InlineKeyboardMarkup(tombol)) try: context.bot.pinChatMessage(chat_id, sendingmsg.message_id) except BadRequest: send_message(update.effective_message, tl(update.effective_message, "Saya tidak punya akses untuk pin pesan!"))
Example #14
Source File: users.py From Marie-2.0-English with GNU General Public License v3.0 | 5 votes |
def get_user_id(username): # ensure valid userid if len(username) <= 5: return None if username.startswith('@'): username = username[1:] users = sql.get_userid_by_name(username) if not users: return None elif len(users) == 1: return users[0].user_id else: for user_obj in users: try: userdat = dispatcher.bot.get_chat(user_obj.user_id) if userdat.username == username: return userdat.id except BadRequest as excp: if excp.message == 'Chat not found': pass else: LOGGER.exception("Error extracting user ID") return None
Example #15
Source File: misc.py From Marie-2.0-English with GNU General Public License v3.0 | 5 votes |
def slap(bot: Bot, update: Update, args: List[str]): msg = update.effective_message # type: Optional[Message] # reply to correct message reply_text = msg.reply_to_message.reply_text if msg.reply_to_message else msg.reply_text # get user who sent message if msg.from_user.username: curr_user = "@" + escape_markdown(msg.from_user.username) else: curr_user = "[{}](tg://user?id={})".format(msg.from_user.first_name, msg.from_user.id) user_id = extract_user(update.effective_message, args) if user_id: slapped_user = bot.get_chat(user_id) user1 = curr_user if slapped_user.username: user2 = "@" + escape_markdown(slapped_user.username) else: user2 = "[{}](tg://user?id={})".format(slapped_user.first_name, slapped_user.id) # if no target found, bot targets the sender else: user1 = "[{}](tg://user?id={})".format(bot.first_name, bot.id) user2 = curr_user temp = random.choice(SLAP_TEMPLATES) item = random.choice(ITEMS) hit = random.choice(HIT) throw = random.choice(THROW) repl = temp.format(user1=user1, user2=user2, item=item, hits=hit, throws=throw) reply_text(repl, parse_mode=ParseMode.MARKDOWN)
Example #16
Source File: misc.py From SkittBot with GNU General Public License v3.0 | 5 votes |
def slap(bot: Bot, update: Update, args: List[str]): msg = update.effective_message # type: Optional[Message] # reply to correct message reply_text = msg.reply_to_message.reply_text if msg.reply_to_message else msg.reply_text # get user who sent message if msg.from_user.username: curr_user = "@" + escape_markdown(msg.from_user.username) else: curr_user = "[{}](tg://user?id={})".format(msg.from_user.first_name, msg.from_user.id) user_id = extract_user(update.effective_message, args) if user_id: slapped_user = bot.get_chat(user_id) user1 = curr_user if slapped_user.username: user2 = "@" + escape_markdown(slapped_user.username) else: user2 = "[{}](tg://user?id={})".format(slapped_user.first_name, slapped_user.id) # if no target found, bot targets the sender else: user1 = "[{}](tg://user?id={})".format(bot.first_name, bot.id) user2 = curr_user temp = random.choice(SLAP_TEMPLATES) item = random.choice(ITEMS) hit = random.choice(HIT) throw = random.choice(THROW) repl = temp.format(user1=user1, user2=user2, item=item, hits=hit, throws=throw) reply_text(repl, parse_mode=ParseMode.MARKDOWN)
Example #17
Source File: misc.py From Marie-2.0-English with GNU General Public License v3.0 | 5 votes |
def stickerid(bot: Bot, update: Update): msg = update.effective_message if msg.reply_to_message and msg.reply_to_message.sticker: update.effective_message.reply_text("Hello " + "[{}](tg://user?id={})".format(msg.from_user.first_name, msg.from_user.id) + ", The sticker id you are replying is :\n```" + escape_markdown(msg.reply_to_message.sticker.file_id) + "```", parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text("Hello " + "[{}](tg://user?id={})".format(msg.from_user.first_name, msg.from_user.id) + ", Please reply to sticker message to get id sticker", parse_mode=ParseMode.MARKDOWN)
Example #18
Source File: special.py From Marie-2.0-English with GNU General Public License v3.0 | 5 votes |
def quickscope(bot: Bot, update: Update, args: List[int]): if args: chat_id = str(args[1]) to_kick = str(args[0]) else: update.effective_message.reply_text("You don't seem to be referring to a chat/user") try: bot.kick_chat_member(chat_id, to_kick) update.effective_message.reply_text("Attempted banning " + to_kick + " from" + chat_id) except BadRequest as excp: update.effective_message.reply_text(excp.message + " " + to_kick)
Example #19
Source File: special.py From Marie-2.0-English with GNU General Public License v3.0 | 5 votes |
def quickunban(bot: Bot, update: Update, args: List[int]): if args: chat_id = str(args[1]) to_kick = str(args[0]) else: update.effective_message.reply_text("You don't seem to be referring to a chat/user") try: bot.unban_chat_member(chat_id, to_kick) update.effective_message.reply_text("Attempted unbanning " + to_kick + " from" + chat_id) except BadRequest as excp: update.effective_message.reply_text(excp.message + " " + to_kick)
Example #20
Source File: special.py From Marie-2.0-English with GNU General Public License v3.0 | 5 votes |
def banall(bot: Bot, update: Update, args: List[int]): if args: chat_id = str(args[0]) all_mems = sql.get_chat_members(chat_id) else: chat_id = str(update.effective_chat.id) all_mems = sql.get_chat_members(chat_id) for mems in all_mems: try: bot.kick_chat_member(chat_id, mems.user) update.effective_message.reply_text("Tried banning " + str(mems.user)) sleep(0.1) except BadRequest as excp: update.effective_message.reply_text(excp.message + " " + str(mems.user)) continue
Example #21
Source File: users.py From tgbot with GNU General Public License v3.0 | 5 votes |
def get_user_id(username): # ensure valid userid if len(username) <= 5: return None if username.startswith('@'): username = username[1:] users = sql.get_userid_by_name(username) if not users: return None elif len(users) == 1: return users[0].user_id else: for user_obj in users: try: userdat = dispatcher.bot.get_chat(user_obj.user_id) if userdat.username == username: return userdat.id except BadRequest as excp: if excp.message == 'Chat not found': pass else: LOGGER.exception("Error extracting user ID") return None
Example #22
Source File: misc.py From tgbot with GNU General Public License v3.0 | 5 votes |
def slap(bot: Bot, update: Update, args: List[str]): msg = update.effective_message # type: Optional[Message] # reply to correct message reply_text = msg.reply_to_message.reply_text if msg.reply_to_message else msg.reply_text # get user who sent message if msg.from_user.username: curr_user = "@" + escape_markdown(msg.from_user.username) else: curr_user = "[{}](tg://user?id={})".format(msg.from_user.first_name, msg.from_user.id) user_id = extract_user(update.effective_message, args) if user_id: slapped_user = bot.get_chat(user_id) user1 = curr_user if slapped_user.username: user2 = "@" + escape_markdown(slapped_user.username) else: user2 = "[{}](tg://user?id={})".format(slapped_user.first_name, slapped_user.id) # if no target found, bot targets the sender else: user1 = "[{}](tg://user?id={})".format(bot.first_name, bot.id) user2 = curr_user temp = random.choice(SLAP_TEMPLATES) item = random.choice(ITEMS) hit = random.choice(HIT) throw = random.choice(THROW) repl = temp.format(user1=user1, user2=user2, item=item, hits=hit, throws=throw) reply_text(repl, parse_mode=ParseMode.MARKDOWN)
Example #23
Source File: misc.py From tgbot with GNU General Public License v3.0 | 5 votes |
def get_id(bot: Bot, update: Update, args: List[str]): user_id = extract_user(update.effective_message, args) if user_id: if update.effective_message.reply_to_message and update.effective_message.reply_to_message.forward_from: user1 = update.effective_message.reply_to_message.from_user user2 = update.effective_message.reply_to_message.forward_from update.effective_message.reply_text( "The original sender, {}, has an ID of `{}`.\nThe forwarder, {}, has an ID of `{}`.".format( escape_markdown(user2.first_name), user2.id, escape_markdown(user1.first_name), user1.id), parse_mode=ParseMode.MARKDOWN) else: user = bot.get_chat(user_id) update.effective_message.reply_text("{}'s id is `{}`.".format(escape_markdown(user.first_name), user.id), parse_mode=ParseMode.MARKDOWN) else: chat = update.effective_chat # type: Optional[Chat] if chat.type == "private": update.effective_message.reply_text("Your id is `{}`.".format(chat.id), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text("This group's id is `{}`.".format(chat.id), parse_mode=ParseMode.MARKDOWN)
Example #24
Source File: misc.py From EmiliaHikari with GNU General Public License v3.0 | 5 votes |
def slap(update, context): args = context.args msg = update.effective_message # type: Optional[Message] # reply to correct message reply_text = msg.reply_to_message.reply_text if msg.reply_to_message else msg.reply_text # get user who sent message #if msg.from_user.username: # curr_user = "@" + escape_markdown(msg.from_user.username) #else: curr_user = "{}".format(mention_markdown(msg.from_user.id, msg.from_user.first_name)) user_id = extract_user(update.effective_message, args) if user_id and user_id != "error": slapped_user = context.bot.get_chat(user_id) user1 = curr_user #if slapped_user.username: # user2 = "@" + escape_markdown(slapped_user.username) #else: user2 = "{}".format(mention_markdown(slapped_user.id, slapped_user.first_name)) # if no target found, bot targets the sender else: user1 = "{}".format(mention_markdown(context.bot.id, context.bot.first_name)) user2 = curr_user temp = random.choice(tl(update.effective_message, "SLAP_TEMPLATES")) item = random.choice(tl(update.effective_message, "ITEMS")) hit = random.choice(tl(update.effective_message, "HIT")) throw = random.choice(tl(update.effective_message, "THROW")) repl = temp.format(user1=user1, user2=user2, item=item, hits=hit, throws=throw) send_message(update.effective_message, repl, parse_mode=ParseMode.MARKDOWN)
Example #25
Source File: users.py From SkittBot with GNU General Public License v3.0 | 5 votes |
def get_user_id(username): # ensure valid userid if len(username) <= 5: return None if username.startswith('@'): username = username[1:] users = sql.get_userid_by_name(username) if not users: return None elif len(users) == 1: return users[0].user_id else: for user_obj in users: try: userdat = dispatcher.bot.get_chat(user_obj.user_id) if userdat.username == username: return userdat.id except BadRequest as excp: if excp.message == 'Chat not found': pass else: LOGGER.exception("Error extracting user ID") return None
Example #26
Source File: special.py From SkittBot with GNU General Public License v3.0 | 5 votes |
def slist(bot: Bot, update: Update): message = update.effective_message text1 = "My sudo users are:" text2 = "My support users are:" for user_id in SUDO_USERS: try: user = bot.get_chat(user_id) name = "[{}](tg://user?id={})".format(user.first_name + (user.last_name or ""), user.id) if user.username: name = escape_markdown("@" + user.username) text1 += "\n - {}".format(name) except BadRequest as excp: if excp.message == 'Chat not found': text1 += "\n - ({}) - not found".format(user_id) for user_id in SUPPORT_USERS: try: user = bot.get_chat(user_id) name = "[{}](tg://user?id={})".format(user.first_name + (user.last_name or ""), user.id) if user.username: name = escape_markdown("@" + user.username) text2 += "\n - {}".format(name) except BadRequest as excp: if excp.message == 'Chat not found': text2 += "\n - ({}) - not found".format(user_id) message.reply_text(text1 + "\n", parse_mode=ParseMode.MARKDOWN) message.reply_text(text2 + "\n", parse_mode=ParseMode.MARKDOWN)
Example #27
Source File: users.py From EmiliaHikari with GNU General Public License v3.0 | 5 votes |
def get_user_id(username): # ensure valid userid if len(username) <= 5: return None if username.startswith('@'): username = username[1:] users = sql.get_userid_by_name(username) if not users: return None elif len(users) == 1: return users[0].user_id else: for user_obj in users: try: userdat = dispatcher.bot.get_chat(user_obj.user_id) if userdat.username == username: return userdat.id except BadRequest as excp: if excp.message == 'Chat not found': pass else: LOGGER.exception("Error extracting user ID") return None
Example #28
Source File: users.py From EmiliaHikari with GNU General Public License v3.0 | 5 votes |
def log_user(update, context): chat = update.effective_chat # type: Optional[Chat] msg = update.effective_message # type: Optional[Message] """text = msg.text if msg.text else "" uid = msg.from_user.id uname = msg.from_user.name print("{} | {} | {} | {}".format(text, uname, uid, chat.title))""" fed_id = fedsql.get_fed_id(chat.id) if fed_id: user = update.effective_user if user: fban, fbanreason, fbantime = fedsql.get_fban_user(fed_id, user.id) if fban: send_message(update.effective_message, languages.tl(update.effective_message, "Pengguna ini dilarang di federasi saat ini!\nAlasan: `{}`").format(fbanreason), parse_mode="markdown") try: context.bot.kick_chat_member(chat.id, user.id) except: print("Fban: cannot banned this user") sql.update_user(msg.from_user.id, msg.from_user.username, chat.id, chat.title) if msg.reply_to_message: sql.update_user(msg.reply_to_message.from_user.id, msg.reply_to_message.from_user.username, chat.id, chat.title) if msg.forward_from: sql.update_user(msg.forward_from.id, msg.forward_from.username)
Example #29
Source File: feds.py From EmiliaHikari with GNU General Public License v3.0 | 5 votes |
def new_fed(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message if chat.type != "private": send_message(update.effective_message, tl(update.effective_message, "Buat federasi Anda di PM saya, bukan dalam grup.")) return if len(message.text) == 1: send_message(update.effective_message, tl(update.effective_message, "Tolong tulis nama federasinya!")) return fednam = message.text.split(None, 1)[1] if not fednam == '': fed_id = str(uuid.uuid4()) fed_name = fednam LOGGER.info(fed_id) # Currently only for creator if fednam == "Team Nusantara Disciplinary Circle": fed_id = "TeamNusantaraDevs" elif fednam == "Emilia Official Support": fed_id = "EmiliaSupport" x = sql.new_fed(user.id, fed_name, fed_id) if not x: send_message(update.effective_message, tl(update.effective_message, "Tidak dapat membuat federasi! Tolong hubungi pembuat saya jika masalah masih berlanjut.")) return send_message(update.effective_message, tl(update.effective_message, "*Anda telah berhasil membuat federasi baru!*"\ "\nNama: `{}`"\ "\nID: `{}`" "\n\nGunakan perintah di bawah ini untuk bergabung dengan federasi:" "\n`/joinfed {}`").format(fed_name, fed_id, fed_id), parse_mode=ParseMode.MARKDOWN) try: context.bot.send_message(TEMPORARY_DATA, "Federasi <b>{}</b> telah di buat dengan ID: <pre>{}</pre>".format(fed_name, fed_id), parse_mode=ParseMode.HTML) except: LOGGER.warning("Cannot send a message to TEMPORARY_DATA") else: send_message(update.effective_message, tl(update.effective_message, "Tolong tulis nama federasinya!"))
Example #30
Source File: feds.py From EmiliaHikari with GNU General Public License v3.0 | 5 votes |
def del_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, "Hapus federasi Anda di PM saya, bukan dalam grup.")) return if args: is_fed_id = args[0] getinfo = sql.get_fed_info(is_fed_id) if getinfo == False: send_message(update.effective_message, tl(update.effective_message, "Federasi ini tidak di temukan!")) return if int(getinfo['owner']) == int(user.id) or int(user.id) == OWNER_ID: fed_id = is_fed_id else: send_message(update.effective_message, tl(update.effective_message, "Hanya pemilik federasi yang dapat melakukan ini!")) return else: send_message(update.effective_message, tl(update.effective_message, "Apa yang harus saya hapus?")) return if is_user_fed_owner(fed_id, user.id) == False: send_message(update.effective_message, tl(update.effective_message, "Hanya pemilik federasi yang dapat melakukan ini!")) return send_message(update.effective_message, tl(update.effective_message, "Anda yakin ingin menghapus federasi Anda? Tindakan ini tidak bisa dibatalkan, Anda akan kehilangan seluruh daftar larangan Anda, dan '{}' akan hilang secara permanen.").format(getinfo['fname']), reply_markup=InlineKeyboardMarkup( [[InlineKeyboardButton(text=tl(update.effective_message, "⚠️ Hapus Federasi ⚠️"), callback_data="rmfed_{}".format(fed_id))], [InlineKeyboardButton(text=tl(update.effective_message, "Batalkan"), callback_data="rmfed_cancel")]]))