Ejemplo n.º 1
0
def help_connect_chat(bot, update, args):
    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
    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")
Ejemplo n.º 2
0
def google(update, context):

    # SHOW_DESCRIPTION = False
    args = context.args
    information = str(args)
    input_str = information  # + " -inurl:(htm|html|php|pls|txt) intitle:index.of \"last modified\" (mkv|mp4|avi|epub|pdf|mp3)"
    input_url = "https://bots.shrimadhavuk.me/search/?q={}".format(input_str)
    headers = {"USER-AGENT": "UniBorg"}
    response = requests.get(input_url, headers=headers).json()
    output_str = " "
    for result in response["results"]:
        text = result.get("title")
        url = result.get("url")
        description = result.get("description")
        last = html2text.html2text(description)
        output_str += "[{}]({})\n{}\n".format(text, url, last)
    send_message(update.effective_message,
                 "{}".format(output_str),
                 link_preview=False,
                 parse_mode='Markdown')
Ejemplo n.º 3
0
def ping(update, context):
    start_time = time.time()
    test = send_message(update.effective_message, "Pong!")
    end_time = time.time()
    ping_time = float(end_time - start_time)
    context.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))
Ejemplo n.º 4
0
    def unsetlog(update, context):
        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:
            context.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!"))
Ejemplo n.º 5
0
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]

        is_pinned = False
        if len(args) >= 2:
            if args[1] == "pin":
                is_pinned = True

        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,
                            is_pinned)

                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"))
Ejemplo n.º 6
0
def permapin(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]

    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 = 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 = bot.send_message(chat_id, text, parse_mode="markdown",
                                 disable_web_page_preview=True, reply_markup=InlineKeyboardMarkup(tombol))
        except BadRequest:
            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:
        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!"))
Ejemplo n.º 7
0
def get_time(update, context):
    args = context.args
    location = " ".join(args)
    if location.lower() == context.bot.first_name.lower():
        send_message(update.effective_message, tl(update.effective_message, "Selalu ada waktu banned untukku!"))
        context.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))
Ejemplo n.º 8
0
def connected(bot, update, chat, user_id, need_admin=True):
    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

    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!"
                        ))
                    raise Exception("Bukan admin!")
            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(bot, update)
            raise Exception("Bukan admin!")
    else:
        return False
Ejemplo n.º 9
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
Ejemplo n.º 10
0
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")
Ejemplo n.º 11
0
def clear_rules(update, context):
    chat = update.effective_chat
    chat_id = update.effective_chat.id
    user = update.effective_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":
            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!"))
Ejemplo n.º 12
0
    def logging(update, context):
        message = update.effective_message  # type: Optional[Message]
        chat = update.effective_chat  # type: Optional[Chat]

        log_channel = sql.get_chat_log_channel(chat.id)
        if log_channel:
            log_channel_info = context.bot.get_chat(log_channel)
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Grup ini memiliki semua log yang dikirim ke: {} (`{}`)").
                format(escape_markdown(log_channel_info.title), log_channel),
                parse_mode=ParseMode.MARKDOWN)

        else:
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Tidak ada saluran log yang telah ditetapkan untuk grup ini!"
                ))
Ejemplo n.º 13
0
def leavechat(update, context):
    args = context.args
    if args:
        chat_id = int(args[0])
    else:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda sepertinya tidak mengacu pada obrolan"))
    try:
        chat = context.bot.getChat(chat_id)
        titlechat = context.bot.get_chat(chat_id).title
        context.bot.sendMessage(
            chat_id, tl(update.effective_message,
                        "Selamat tinggal semua ЁЯШБ"))
        context.bot.leaveChat(chat_id)
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Saya telah keluar dari grup {}").format(titlechat))

    except BadRequest as excp:
        if excp.message == "Chat not found":
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Sepertinya saya sudah keluar atau di tendang di grup tersebut"
                ))
        else:
            return
Ejemplo n.º 14
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")
Ejemplo n.º 15
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.")
Ejemplo n.º 16
0
def show_url(update, context):
    args = context.args
    tg_chat_id = str(update.effective_chat.id)

    if len(args) >= 1:
        tg_feed_link = args[0]
        link_processed = parse(tg_feed_link)

        if link_processed.bozo == 0:
            feed_title = link_processed.feed.get("title", default="Unknown")
            feed_description = "<i>{}</i>".format(
                re.sub('<[^<]+?>', '', link_processed.feed.get("description", default="Unknown")))
            feed_link = link_processed.feed.get("link", default="Unknown")

            feed_message = tl(update.effective_message, "<b>Judul Feed:</b> \n{}" \
                           "\n\n<b>Deskripsi Feed:</b> \n{}" \
                           "\n\n<b>Link Feed:</b> \n{}").format(html.escape(feed_title),
                                                               feed_description,
                                                               html.escape(feed_link))

            if len(link_processed.entries) >= 1:
                entry_title = link_processed.entries[0].get("title", default="Unknown")
                entry_description = "<i>{}</i>".format(
                    re.sub('<[^<]+?>', '', link_processed.entries[0].get("description", default="Unknown")))
                entry_link = link_processed.entries[0].get("link", default="Unknown")

                entry_message = tl(update.effective_message, "\n\n<b>Judul Entri:</b> \n{}" \
                                "\n\n<b>Deskripsi Entri:</b> \n{}" \
                                "\n\n<b>Entri Masuk:</b> \n{}").format(html.escape(entry_title),
                                                                     entry_description,
                                                                     html.escape(entry_link))
                final_message = feed_message + entry_message

                context.bot.send_message(chat_id=tg_chat_id, text=final_message, parse_mode=ParseMode.HTML)
            else:
                context.bot.send_message(chat_id=tg_chat_id, text=feed_message, parse_mode=ParseMode.HTML)
        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"))
Ejemplo n.º 17
0
def pin(update, context):
	user = update.effective_user  # type: Optional[User]
	chat = update.effective_chat  # type: Optional[Chat]
	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
		if len(args)  <= 1:
			send_message(update.effective_message, tl(update.effective_message, "Gunakan /pin <notify/loud/silent/violent> <link pesan>"))
			return ""
		prev_message = args[1]
		if "/" in prev_message:
			prev_message = prev_message.split("/")[-1]
	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 update.effective_message.reply_to_message:
			prev_message = update.effective_message.reply_to_message.message_id
		else:
			send_message(update.effective_message, tl(update.effective_message, "Balas pesan untuk pin pesan tersebut pada grup ini"))
			return ""

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

	is_silent = True
	if len(args) >= 1:
		is_silent = not (args[0].lower() == 'silent' or args[0].lower() == 'off' or args[0].lower() == 'mute')

	if prev_message and is_group:
		try:
			context.bot.pinChatMessage(chat.id, prev_message, disable_notification=is_silent)
			if conn:
				send_message(update.effective_message, tl(update.effective_message, "Saya sudah pin pesan dalam grup {}").format(chat_name))
		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 ""
Ejemplo n.º 18
0
def security_mute(bot: Bot, update: Update, args: List[str]) -> 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]
	message = update.effective_message  # type: Optional[Message]
	getcur, cur_value, cust_text = sql.welcome_security(chat.id)
	if len(args) >= 1:
		var = args[0]
		if var[:1] == "0":
			mutetime = "0"
			sql.set_welcome_security(chat.id, getcur, "0", cust_text)
			text = tl(update.effective_message, "Setiap member baru akan di bisukan selamanya sampai dia menekan tombol selamat datang!")
		else:
			mutetime = extract_time(message, var)
			if mutetime == "":
				return
			sql.set_welcome_security(chat.id, getcur, str(var), cust_text)
			text = tl(update.effective_message, "Setiap member baru akan di bisukan selama {} sampai dia menekan tombol selamat datang!").format(var)
		send_message(update.effective_message, text)
	else:
		if str(cur_value) == "0":
			send_message(update.effective_message, tl(update.effective_message, "Pengaturan saat ini: member baru akan di bisukan selamanya sampai dia menekan tombol selamat datang!"))
		else:
			send_message(update.effective_message, tl(update.effective_message, "Pengaturan saat ini: member baru akan di bisukan selama {} sampai dia menekan tombol selamat datang!").format(cur_value))
Ejemplo n.º 19
0
def set_goodbye(bot: Bot, update: Update) -> 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]
	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))
Ejemplo n.º 20
0
def list_handlers(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=False)
	if not conn == False:
		chat_id = conn
		chat_name = dispatcher.bot.getChat(conn).title
		filter_list = "*Filter di {}:*\n"
	else:
		chat_id = update.effective_chat.id
		if chat.type == "private":
			chat_name = tl(update.effective_message, "filter lokal")
			filter_list = tl(update.effective_message, "*filter lokal:*\n")
		else:
			chat_name = chat.title
			filter_list = tl(update.effective_message, "*Filter di {}*:\n")

	all_handlers = sql.get_chat_triggers(chat_id)


	if not all_handlers:
		send_message(update.effective_message, tl(update.effective_message, "Tidak ada filter di {}!").format(chat_name))
		return

	for keyword in all_handlers:
		entry = " - {}\n".format(escape_markdown(keyword))
		if len(entry) + len(filter_list) > telegram.MAX_MESSAGE_LENGTH:
			send_message(update.effective_message, filter_list.format(chat_name), parse_mode=telegram.ParseMode.MARKDOWN)
			filter_list = entry
		else:
			filter_list += entry

	send_message(update.effective_message, filter_list.format(chat_name), parse_mode=telegram.ParseMode.MARKDOWN)
Ejemplo n.º 21
0
def set_language(update, context):
	msg = update.effective_message  # type: Optional[Message]
	chat = update.effective_chat  # type: Optional[Chat]
	user = update.effective_user  # type: Optional[User]

	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:
			sql.set_lang(msg.chat.id, 'en')
			getlang = 'en'
	loaded_langs = []
	tmp_list = []
	counter = 0

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

	loaded_langs.append([InlineKeyboardButton("Translate", url="https://github.com/AyraHikari/EmiliaHikari/blob/master/TRANSLATION.md")])

	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")

	currlang = LANGS_TEXT[getlang] if LANGS_TEXT.get(getlang) else "(Deleted langs)"
	send_message(update.effective_message, tl(msg, "Bahasa di *{}* saat ini adalah:\n{}.\n\nPilih bahasa:").format(chatname, currlang), parse_mode="markdown", reply_markup=keyboard)
Ejemplo n.º 22
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)
Ejemplo n.º 23
0
def gbanstat(update, context):
    args = context.args
    if len(args) > 0:
        if args[0].lower() in ["on", "yes"]:
            sql.enable_gbans(update.effective_chat.id)
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "I've enabled gbans in this group. This will help protect you from "
                    "spammers, unsavoury characters, and the biggest trolls."))
        elif args[0].lower() in ["off", "no"]:
            sql.disable_gbans(update.effective_chat.id)
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "I've disabled gbans in this group. GBans wont affect your users anymore. "
                    "You'll be less protected from any trolls and spammers though!"
                ))
    else:
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Give me some arguments to choose a setting! on/off, yes/no!\n\n"
                "Your current setting is: {}\n"
                "When True, any gbans that happen will also happen in your group. "
                "When False, they won't, leaving you at the possible mercy of "
                "spammers.").format(
                    sql.does_chat_gban(update.effective_chat.id)))
Ejemplo n.º 24
0
def gbanstat(update, context):
    args = context.args
    if len(args) > 0:
        if args[0].lower() in ["on", "yes"]:
            sql.enable_gbans(update.effective_chat.id)
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Saya telah mengaktifkan larangan global dalam grup ini. Ini akan membantu melindungi Anda "
                    "dari spammer, karakter tidak menyenangkan, dan troll terbesar."
                ))
        elif args[0].lower() in ["off", "no"]:
            sql.disable_gbans(update.effective_chat.id)
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Saya telah menonaktifkan larangan global dalam grup ini. Larangan global tidak akan memengaruhi pengguna Anda "
                    "lagi. Anda akan kurang terlindungi dari troll dan spammer sekalipun"
                ))
    else:
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Berikan saya beberapa argumen untuk memilih pengaturan! on/off, yes/no!\n\n"
                "Pengaturan Anda saat ini: {}\n"
                "Ketika Benar, setiap larangan global yang terjadi juga akan terjadi di grup Anda. "
                "Ketika Salah, mereka tidak akan meninggalkan Anda pada belas kasihan yang mungkin dari "
                "spammer.").format(sql.does_chat_gban(
                    update.effective_chat.id)))
Ejemplo n.º 25
0
def about_bio(update, context):
    message = update.effective_message  # type: Optional[Message]
    args = context.args

    user_id = extract_user(message, args)
    if user_id and user_id != "error":
        user = context.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!"))
Ejemplo n.º 26
0
def about_me(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_me_info(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 = message.reply_to_message.from_user.first_name
        send_message(
            update.effective_message,
            username + tl(update.effective_message,
                          " belum mengatur pesan info tentang diri mereka!"))
    else:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda belum mengatur pesan info tentang diri Anda!"))
Ejemplo n.º 27
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 and user_id != "error":
        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!"))
Ejemplo n.º 28
0
def flood(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=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")
Ejemplo n.º 29
0
def add_blacklist(update, context):
	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)

	conn = connected(context.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."))
Ejemplo n.º 30
0
def reply_afk(bot: Bot, update: Update):
    message = update.effective_message  # type: Optional[Message]

    entities = message.parse_entities(
        [MessageEntity.TEXT_MENTION, MessageEntity.MENTION])
    if message.entities and entities:
        for ent in entities:
            if ent.type == MessageEntity.TEXT_MENTION:
                user_id = ent.user.id
                fst_name = ent.user.first_name

            elif ent.type == MessageEntity.MENTION:
                user_id = get_user_id(message.text[ent.offset:ent.offset +
                                                   ent.length])
                if not user_id:
                    # Should never happen, since for a user to become AFK they must have spoken. Maybe changed username?
                    return
                try:
                    chat = bot.get_chat(user_id)
                except BadRequest:
                    print("Error: Could not fetch userid {} for AFK module".
                          format(user_id))
                    return
                fst_name = chat.first_name

            else:
                return

            if sql.is_afk(user_id):
                valid, reason = sql.check_afk_status(user_id)
                if valid:
                    if not reason:
                        res = tl(update.effective_message,
                                 "{} sedang AFK!").format(fst_name)
                    else:
                        res = tl(update.effective_message,
                                 "{} sedang AFK!\nKarena : {}").format(
                                     fst_name, reason)
                    send_message(update.effective_message, res)