def setlog(update, context): message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] if chat.type == chat.CHANNEL: send_message( update.effective_message, tl( update.effective_message, "Sekarang, teruskan /setlog ke grup yang Anda ingin ikat saluran ini!" )) elif message.forward_from_chat: sql.set_chat_log_channel(chat.id, message.forward_from_chat.id) try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception( "Error deleting message in log channel. Should work anyway though." ) try: context.bot.send_message( message.forward_from_chat.id, tl( update.effective_message, "Saluran ini telah ditetapkan sebagai saluran log untuk {}." ).format(chat.title or chat.first_name)) except Unauthorized as excp: if excp.message == "Forbidden: bot is not a member of the channel chat": context.bot.send_message( chat.id, tl( update.effective_message, "Gagal menyetel saluran log!\nSaya mungkin bukan admin di channel tersebut." )) sql.stop_chat_logging(chat.id) return else: LOGGER.exception("ERROR in setting the log channel.") context.bot.send_message( chat.id, tl(update.effective_message, "Berhasil mengatur saluran log!")) else: send_message( update.effective_message, tl( update.effective_message, "Langkah-langkah untuk mengatur saluran log adalah:\n" " - tambahkan bot ke saluran yang diinginkan\n" " - Kirimkan /setlog ke saluran\n" " - Teruskan /setlog ke grup\n"))
def setlog(bot: Bot, update: Update): spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id) if spam == True: return update.effective_message.reply_text( "Saya kecewa dengan anda, saya tidak akan mendengar kata-kata anda sekarang!" ) message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] if chat.type == chat.CHANNEL: message.reply_text( "Sekarang, teruskan /setlog ke grup yang Anda ingin ikat saluran ini!" ) elif message.forward_from_chat: sql.set_chat_log_channel(chat.id, message.forward_from_chat.id) try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception( "Error deleting message in log channel. Should work anyway though." ) try: bot.send_message( message.forward_from_chat.id, "Saluran ini telah ditetapkan sebagai saluran log untuk {}." .format(chat.title or chat.first_name)) except Unauthorized as excp: if excp.message == "Forbidden: bot is not a member of the channel chat": bot.send_message(chat.id, "Successfully set log channel!") else: LOGGER.exception("ERROR in setting the log channel.") bot.send_message(chat.id, "Berhasil mengatur saluran log!") else: message.reply_text( "Langkah-langkah untuk mengatur saluran log adalah:\n" " - tambahkan bot ke saluran yang diinginkan\n" " - Kirimkan /setlog ke saluran\n" " - Teruskan /setlog ke grup\n")