示例#1
0
文件: locks.py 项目: yupisky/Halubot
def list_locks(bot: Bot, update: Update):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user

    # Connection check
    conn = connected(bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = chat.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

    res = build_lock_message(chat.id)
    if conn:
        res = res.replace(tl(update.effective_message, 'obrolan ini'),
                          '*{}*'.format(chat_name))

    send_message(update.effective_message, res, parse_mode=ParseMode.MARKDOWN)
示例#2
0
def connection_chat(bot, update):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]

    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    conn = connected(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")
示例#3
0
def getsticker(bot: Bot, update: Update):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    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)
        bot.sendChatAction(chat_id, "upload_document")
        file_id = msg.reply_to_message.sticker.file_id
        newFile = bot.get_file(file_id)
        newFile.download('sticker.png')
        bot.sendDocument(chat_id, document=open('sticker.png', 'rb'))
        bot.sendChatAction(chat_id, "upload_photo")
        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)
示例#4
0
def get_settings(bot: Bot, update: Update):
    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)

    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return

    # 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(
                                       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)
示例#5
0
文件: rules.py 项目: yupisky/Halubot
def clear_rules(bot: Bot, update: Update):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    chat = update.effective_chat
    chat_id = update.effective_chat.id
    user = update.effective_user

    conn = connected(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

    chat_id = update.effective_chat.id
    sql.set_rules(chat_id, "")
    send_message(update.effective_message,
                 tl(update.effective_message, "Berhasil membersihkan aturan!"))
示例#6
0
def report_setting(bot: Bot, update: Update, args: List[str]):
	spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message)
	if spam == True:
		return
	chat = update.effective_chat  # type: Optional[Chat]
	msg = update.effective_message  # type: Optional[Message]

	if chat.type == chat.PRIVATE:
		if len(args) >= 1:
			if args[0] in ("yes", "on"):
				sql.set_user_setting(chat.id, True)
				send_message(update.effective_message, tl(update.effective_message, "Menghidupkan pelaporan! Anda akan diberi tahu setiap kali ada yang melaporkan sesuatu."))

			elif args[0] in ("no", "off"):
				sql.set_user_setting(chat.id, False)
				send_message(update.effective_message, tl(update.effective_message, "Mematikan pelaporan! Anda tidak akan mendapatkan laporan apa pun."))
		else:
			send_message(update.effective_message, tl(update.effective_message, "Preferensi laporan Anda saat ini: `{}`").format(sql.user_should_report(chat.id)),
						   parse_mode=ParseMode.MARKDOWN)

	else:
		if len(args) >= 1:
			if args[0] in ("yes", "on"):
				sql.set_chat_setting(chat.id, True)
				send_message(update.effective_message, tl(update.effective_message, "Menghidupkan pelaporan! Admin yang telah mengaktifkan laporan akan diberi tahu ketika seseorang menyebut /report "
							   "atau @admin."))

			elif args[0] in ("no", "off"):
				sql.set_chat_setting(chat.id, False)
				send_message(update.effective_message, tl(update.effective_message, "Mematikan pelaporan! Tidak ada admin yang akan diberitahukan ketika seseorang menyebut /report atau @admin."))
		else:
			send_message(update.effective_message, tl(update.effective_message, "Pengaturan obrolan saat ini adalah: `{}`").format(sql.chat_should_report(chat.id)),
						   parse_mode=ParseMode.MARKDOWN)
示例#7
0
文件: rss.py 项目: yupisky/Halubot
def add_url(bot, update, args):
    spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    if len(args) >= 1:
        chat = update.effective_chat

        tg_chat_id = str(update.effective_chat.id)

        tg_feed_link = args[0]

        link_processed = parse(tg_feed_link)

        # check if link is a valid RSS Feed link
        if link_processed.bozo == 0:
            if len(link_processed.entries[0]) >= 1:
                tg_old_entry_link = link_processed.entries[0].link
            else:
                tg_old_entry_link = ""

            # gather the row which contains exactly that telegram group ID and link for later comparison
            row = sql.check_url_availability(tg_chat_id, tg_feed_link)

            # check if there's an entry already added to DB by the same user in the same group with the same link
            if row:
                send_message(update.effective_message, tl(update.effective_message, "URL ini sudah ditambahkan"))
            else:
                sql.add_url(tg_chat_id, tg_feed_link, tg_old_entry_link)

                send_message(update.effective_message, tl(update.effective_message, "URL ditambahkan ke langganan"))
        else:
            send_message(update.effective_message, tl(update.effective_message, "Tautan ini bukan tautan Umpan RSS"))
    else:
        send_message(update.effective_message, tl(update.effective_message, "URL hilang"))
示例#8
0
def disconnect_chat(bot, update):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return

    if update.effective_chat.type == 'private':
        disconnection_status = sql.disconnect(
            update.effective_message.from_user.id)
        if disconnection_status:
            sql.disconnected_chat = send_message(
                update.effective_message,
                languages.tl(update.effective_message,
                             "Terputus dari obrolan!"))
        else:
            send_message(
                update.effective_message,
                languages.tl(update.effective_message,
                             "Anda tidak terkoneksi!"))
    else:
        send_message(
            update.effective_message,
            languages.tl(update.effective_message,
                         "Penggunaan terbatas hanya untuk PM"))
示例#9
0
def about_bio(bot: Bot, update: Update, args: List[str]):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return

    message = update.effective_message  # type: Optional[Message]

    user_id = extract_user(message, args)
    if user_id:
        user = bot.get_chat(user_id)
    else:
        user = message.from_user

    info = sql.get_user_bio(user.id)

    if info:
        send_message(update.effective_message,
                     "*{}*:\n{}".format(user.first_name,
                                        escape_markdown(info)),
                     parse_mode=ParseMode.MARKDOWN)
    elif message.reply_to_message:
        username = user.first_name
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "{} belum memiliki pesan tentang dirinya sendiri!").format(
                   username))
    else:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda belum memiliki bio set tentang diri Anda!"))
示例#10
0
def runs(bot: Bot, update: Update):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    send_message(update.effective_message,
                 random.choice(tl(update.effective_message, "RUN_STRINGS")))
示例#11
0
文件: rules.py 项目: yupisky/Halubot
def get_rules(bot: Bot, update: Update):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    chat_id = update.effective_chat.id
    send_rules(update, chat_id)
示例#12
0
def add_blacklist(bot: Bot, update: Update):
    msg = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    words = msg.text.split(None, 1)

    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return

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

    if len(words) > 1:
        text = words[1]
        to_blacklist = list(
            set(trigger.strip() for trigger in text.split("\n")
                if trigger.strip()))
        for trigger in to_blacklist:
            sql.add_to_blacklist(chat_id, trigger.lower())

        if len(to_blacklist) == 1:
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "<code>{}</code> ditambahkan ke daftar hitam di <b>{}</b>!"
                ).format(html.escape(to_blacklist[0]), chat_name),
                parse_mode=ParseMode.HTML)

        else:
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "<code>{}</code> Pemicu ditambahkan ke daftar hitam di <b>{}</b>!"
                ).format(len(to_blacklist), chat_name),
                parse_mode=ParseMode.HTML)

    else:
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Beri tahu saya kata-kata apa yang ingin Anda hapus dari daftar hitam."
            ))
示例#13
0
def set_language(bot, update):
    msg = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]

    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return

    getlang = sql.get_lang(chat.id)
    if getlang == 'None' or not getlang:
        if msg.from_user.language_code:
            sql.set_lang(msg.chat.id, msg.from_user.language_code)
            getlang = msg.from_user.language_code
        else:
            if msg.chat.type == "private":
                sql.set_lang(msg.chat.id, 'en')
                getlang = 'en'
            else:
                sql.set_lang(msg.chat.id, 'id')
                getlang = 'id'
    loaded_langs = []
    counter = 0

    for x in LOADED_LANGS_ID:
        if counter % 2 == 0:
            loaded_langs.append(
                InlineKeyboardButton(LANGS_TEXT[x],
                                     callback_data="set_lang({})".format(x)))
        else:
            loaded_langs.append(
                InlineKeyboardButton(LANGS_TEXT[x],
                                     callback_data="set_lang({})".format(x)))
        counter += 1

    loaded_langs = list(zip(loaded_langs[::2], loaded_langs[1::2]))

    keyboard = InlineKeyboardMarkup(loaded_langs)

    if chat.title:
        chatname = chat.title
    else:
        if chat.type == "private":
            chatname = user.first_name
        else:
            chatname = tl(update.effective_message, "obrolan saat ini")

    send_message(
        update.effective_message,
        tl(msg,
           "Bahasa di *{}* saat ini adalah:\n{}.\n\nPilih bahasa:").format(
               chatname, LANGS_TEXT[getlang]),
        parse_mode="markdown",
        reply_markup=keyboard)
示例#14
0
文件: notes.py 项目: yupisky/Halubot
def hash_get(bot: Bot, update: Update):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    message = update.effective_message.text
    fst_word = message.split()[0]
    no_hash = fst_word[1:]
    get(bot, update, no_hash, show_none=False)
示例#15
0
def ramalan(bot: Bot, update: Update):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    text = ""
    if random.randint(1, 10) >= 7:
        text += random.choice(tl(update.effective_message, "RAMALAN_FIRST"))
    text += random.choice(tl(update.effective_message, "RAMALAN_STRINGS"))
    send_message(update.effective_message, text)
示例#16
0
文件: locks.py 项目: yupisky/Halubot
def locktypes(bot: Bot, update: Update):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    locklist = list(LOCK_TYPES) + list(RESTRICTION_TYPES)
    locklist.sort()
    send_message(
        update.effective_message, "\n - ".join([
            tl(update.effective_message, "Jenis kunci yang tersedia adalah: ")
        ] + locklist))
示例#17
0
def get_time(bot: Bot, update: Update, args: List[str]):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    location = " ".join(args)
    if location.lower() == bot.first_name.lower():
        send_message(
            update.effective_message,
            tl(update.effective_message, "Selalu ada waktu banned untukku!"))
        bot.send_sticker(update.effective_chat.id, BAN_STICKER)
        return

    res = requests.get(GMAPS_LOC, params=dict(address=location, key=MAPS_API))
    print(res.text)

    if res.status_code == 200:
        loc = json.loads(res.text)
        if loc.get('status') == 'OK':
            lat = loc['results'][0]['geometry']['location']['lat']
            long = loc['results'][0]['geometry']['location']['lng']

            country = None
            city = None

            address_parts = loc['results'][0]['address_components']
            for part in address_parts:
                if 'country' in part['types']:
                    country = part.get('long_name')
                if 'administrative_area_level_1' in part['types'] and not city:
                    city = part.get('long_name')
                if 'locality' in part['types']:
                    city = part.get('long_name')

            if city and country:
                location = "{}, {}".format(city, country)
            elif country:
                location = country

            timenow = int(datetime.utcnow().timestamp())
            res = requests.get(GMAPS_TIME,
                               params=dict(location="{},{}".format(lat, long),
                                           timestamp=timenow))
            if res.status_code == 200:
                offset = json.loads(res.text)['dstOffset']
                timestamp = json.loads(res.text)['rawOffset']
                time_there = datetime.fromtimestamp(
                    timenow + timestamp +
                    offset).strftime("%H:%M:%S hari %A %d %B")
                send_message(
                    update.effective_message,
                    "Sekarang pukul {} di {}".format(time_there, location))
示例#18
0
def blacklist(bot: Bot, update: Update, args: List[str]):
    msg = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]

    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return

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

    filter_list = tl(
        update.effective_message,
        "<b>Kata daftar hitam saat ini di {}:</b>\n").format(chat_name)

    all_blacklisted = sql.get_chat_blacklist(chat_id)

    if len(args) > 0 and args[0].lower() == 'copy':
        for trigger in all_blacklisted:
            filter_list += "<code>{}</code>\n".format(html.escape(trigger))
    else:
        for trigger in all_blacklisted:
            filter_list += " - <code>{}</code>\n".format(html.escape(trigger))

    # for trigger in all_blacklisted:
    #     filter_list += " - <code>{}</code>\n".format(html.escape(trigger))

    split_text = split_message(filter_list)
    for text in split_text:
        if filter_list == tl(
                update.effective_message,
                "<b>Kata daftar hitam saat ini di {}:</b>\n").format(
                    chat_name):
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Tidak ada pesan daftar hitam di <b>{}</b>!").format(
                       chat_name),
                parse_mode=ParseMode.HTML)
            return
        send_message(update.effective_message, text, parse_mode=ParseMode.HTML)
示例#19
0
def set_about_bio(bot: Bot, update: Update):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return

    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!"))
示例#20
0
文件: notes.py 项目: yupisky/Halubot
def cmd_get(bot: Bot, update: Update, args: List[str]):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    if len(args) >= 2 and args[1].lower() == "noformat":
        get(bot, update, args[0], show_none=True, no_format=True)
    elif len(args) >= 1:
        get(bot, update, args[0], show_none=True)
    else:
        send_message(update.effective_message,
                     tl(update.effective_message, "Get apa?"))
示例#21
0
def afk(bot: Bot, update: Update):
    spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message)
    if spam == True:
        return

    args = update.effective_message.text.split(None, 1)
    if len(args) >= 2:
        reason = args[1]
    else:
        reason = ""

    sql.set_afk(update.effective_user.id, reason)
    send_message(update.effective_message, tl(update.effective_message, "{} sekarang AFK!").format(update.effective_user.first_name))
示例#22
0
    def list_cmds(bot: Bot, update: Update):
        spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message)
        if spam == True:
            return

        if DISABLE_CMDS + DISABLE_OTHER:
            result = ""
            for cmd in set(DISABLE_CMDS + DISABLE_OTHER):
                result += " - `{}`\n".format(escape_markdown(cmd))
            send_message(update.effective_message, languages.tl(update.effective_message, "Perintah berikut dapat diubah:\n{}").format(result),
                                                parse_mode=ParseMode.MARKDOWN)
        else:
            send_message(update.effective_message, languages.tl(update.effective_message, "Tidak ada perintah yang dapat dinonaktifkan."))
示例#23
0
def kamusbesarbahasaindonesia(bot: Bot, update: Update):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    msg = update.effective_message
    chat_id = update.effective_chat.id
    try:
        args = update.effective_message.text.split(None, 1)
        teks = args[1]
        message = update.effective_message
        try:
            api = requests.get(
                'http://kateglo.com/api.php?format=json&phrase=' +
                teks).json()
        except json.decoder.JSONDecodeError:
            send_message(update.effective_message,
                         "Hasil tidak ditemukan!",
                         parse_mode=ParseMode.MARKDOWN)
            return
        #kamusid = KBBI(teks)
        parsing = "***Hasil dari kata {} ({}) di {}***\n\n".format(
            api['kateglo']['phrase'], api['kateglo']['lex_class_name'],
            api['kateglo']['ref_source_name'])
        if len(api['kateglo']['definition']) >= 6:
            jarak = 5
        else:
            jarak = len(api['kateglo']['definition'])
        for x in range(jarak):
            parsing += "*{}.* {}".format(
                x + 1, api['kateglo']['definition'][x]['def_text'])
            contoh = api['kateglo']['definition'][x]['sample']
            if contoh:
                parsing += "\nContoh: `{}`".format(
                    str(BeautifulSoup(contoh, "lxml")).replace(
                        '<html><body><p>', '').replace('</p></body></html>',
                                                       ''))
            parsing += "\n\n"
        send_message(update.effective_message,
                     parsing,
                     parse_mode=ParseMode.MARKDOWN)

    except IndexError:
        send_message(
            update.effective_message,
            "Tulis pesan untuk mencari dari kamus besar bahasa indonesia")
    except KBBI.TidakDitemukan:
        send_message(update.effective_message, "Hasil tidak ditemukan")
    else:
        return
示例#24
0
文件: rules.py 项目: yupisky/Halubot
def private_rules(bot: Bot, update: Update, args: List[str]):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    conn = connected(bot, update, chat, user.id)
    if conn:
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        chat_id = update.effective_chat.id
        if chat.type == "private":
            chat_name = chat.title
        else:
            chat_name = chat.title

    if len(args) >= 1:
        if args[0] in ("yes", "on", "ya"):
            sql.private_rules(str(chat_id), True)
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Private Rules di *aktifkan*, pesan peraturan akan di kirim di PM."
                ),
                parse_mode="markdown")
        elif args[0] in ("no", "off"):
            sql.private_rules(str(chat_id), False)
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Private Rules di *non-aktifkan*, pesan peraturan akan di kirim di grup."
                ),
                parse_mode="markdown")
        else:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Argumen tidak dikenal - harap gunakan 'yes', atau 'no'."))
    else:
        is_private = sql.get_private_rules(chat_id)
        send_message(update.effective_message,
                     tl(update.effective_message,
                        "Pengaturan Private Rules di {}: *{}*").format(
                            chat_name,
                            "Enabled" if is_private else "Disabled"),
                     parse_mode="markdown")
示例#25
0
    def unsetlog(bot: Bot, update: Update):
        spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message)
        if spam == True:
            return
        message = update.effective_message  # type: Optional[Message]
        chat = update.effective_chat  # type: Optional[Chat]

        log_channel = sql.stop_chat_logging(chat.id)
        if log_channel:
            bot.send_message(log_channel, tl(update.effective_message, "Channel telah dibatalkan tautannya {}").format(chat.title))
            send_message(update.effective_message, tl(update.effective_message, "Log saluran telah dinonaktifkan."))

        else:
            send_message(update.effective_message, tl(update.effective_message, "Belum ada saluran log yang ditetapkan!"))
示例#26
0
def stop_filter(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    args = update.effective_message.text.split(None, 1)

    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return

    conn = connected(bot, update, chat, user.id)
    if not conn == False:
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        chat_id = update.effective_chat.id
        if chat.type == "private":
            chat_name = tl(update.effective_message, "catatan lokal")
        else:
            chat_name = chat.title

    if len(args) < 2:
        send_message(
            update.effective_message,
            tl(update.effective_message, "Apa yang harus saya hentikan?"))
        return

    chat_filters = sql.get_chat_triggers(chat_id)

    if not chat_filters:
        send_message(
            update.effective_message,
            tl(update.effective_message, "Tidak ada filter aktif di sini!"))
        return

    for keyword in chat_filters:
        if keyword == args[1]:
            sql.remove_filter(chat_id, args[1])
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Ya, saya akan berhenti menjawabnya di *{}*.").format(
                       chat_name),
                parse_mode=telegram.ParseMode.MARKDOWN)
            raise DispatcherHandlerStop

    send_message(
        update.effective_message,
        "Itu bukan filter aktif - jalankan /filter untuk semua filter aktif.")
示例#27
0
def get_time_alt(bot: Bot, update: Update, args: List[str]):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    if args:
        location = " ".join(args)
        if location.lower() == bot.first_name.lower():
            send_message(update.effective_message,
                         "Selalu ada waktu banned untukku!")
            bot.send_sticker(update.effective_chat.id, BAN_STICKER)
            return

        res = requests.get(
            'https://dev.virtualearth.net/REST/v1/timezone/?query={}&key={}'.
            format(location, MAPS_API))

        if res.status_code == 200:
            loc = res.json()
            if len(loc['resourceSets'][0]['resources'][0]
                   ['timeZoneAtLocation']) == 0:
                send_message(
                    update.effective_message,
                    tl(update.effective_message, "Lokasi tidak di temukan!"))
                return
            placename = loc['resourceSets'][0]['resources'][0][
                'timeZoneAtLocation'][0]['placeName']
            localtime = loc['resourceSets'][0]['resources'][0][
                'timeZoneAtLocation'][0]['timeZone'][0]['convertedTime'][
                    'localTime']
            if lang_sql.get_lang(update.effective_chat.id) == "id":
                locale.setlocale(locale.LC_TIME, 'id_ID.UTF-8')
                time = datetime.strptime(
                    localtime,
                    '%Y-%m-%dT%H:%M:%S').strftime("%H:%M:%S hari %A, %d %B")
            else:
                time = datetime.strptime(
                    localtime,
                    '%Y-%m-%dT%H:%M:%S').strftime("%H:%M:%S %A, %d %B")
            send_message(update.effective_message,
                         tl(update.effective_message,
                            "Sekarang pukul `{}` di `{}`").format(
                                time, placename),
                         parse_mode="markdown")
    else:
        send_message(update.effective_message,
                     tl(update.effective_message,
                        "Gunakan `/time nama daerah`\nMisal: `/time jakarta`"),
                     parse_mode="markdown")
示例#28
0
def ping(bot: Bot, update: Update):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    start_time = time.time()
    test = send_message(update.effective_message, "Pong!")
    end_time = time.time()
    ping_time = float(end_time - start_time)
    bot.editMessageText(chat_id=update.effective_chat.id,
                        message_id=test.message_id,
                        text=tl(update.effective_message,
                                "Pong!\nKecepatannya: {0:.2f} detik").format(
                                    round(ping_time, 2) % 60))
示例#29
0
def kickme(bot: Bot, update: Update):
    user_id = update.effective_message.from_user.id
    if is_user_admin(update.effective_chat, user_id):
        send_message(update.effective_message, tl(update.effective_message, "Saya berharap saya bisa... tetapi Anda seorang admin 😒"))
        return

    spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message)
    if spam == True:
        return

    res = update.effective_chat.unban_member(user_id)  # unban on current user = kick
    if res:
        send_message(update.effective_message, tl(update.effective_message, "Tidak masalah 😊"))
    else:
        send_message(update.effective_message, tl(update.effective_message, "Hah? Aku tidak bisa 🙄"))
示例#30
0
def flood(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return

    conn = connected(bot, update, chat, user.id, need_admin=False)
    if 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_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title

    limit = sql.get_flood_limit(chat_id)
    if limit == 0:
        if conn:
            text = tl(
                update.effective_message,
                "Saat ini saya tidak memberlakukan pengendalian pesan beruntun pada *{}*!"
            ).format(chat_name)
        else:
            text = tl(
                update.effective_message,
                "Saat ini saya tidak memberlakukan pengendalian pesan beruntun"
            )
        send_message(update.effective_message, text, parse_mode="markdown")
    else:
        if conn:
            text = tl(
                update.effective_message,
                "Saat ini saya melarang pengguna jika mereka mengirim lebih dari *{}* pesan berturut-turut pada *{}*."
            ).format(limit, chat_name)
        else:
            text = tl(
                update.effective_message,
                "Saat ini saya melarang pengguna jika mereka mengirim lebih dari *{}* pesan berturut-turut."
            ).format(limit)
        send_message(update.effective_message, text, parse_mode="markdown")