Exemple #1
0
def build_lock_message(chat, chatP, user, chatname):
    locks = sql.get_locks(chat.id)
    restr = sql.get_restr(chat.id)
    chat_name = chat.title
    if not (locks or restr):
        res = tld(chatP.id,
                  "There are no current locks in *{}*.".format(chat_name))
    else:
        res = tld(chatP.id, "These are the locks in *{}*:".format(chat_name))
        if locks:
            res += "\n - sticker = `{}`" \
                   "\n - audio = `{}`" \
                   "\n - voice = `{}`" \
                   "\n - document = `{}`" \
                   "\n - video = `{}`" \
                   "\n - videonote = `{}`" \
                   "\n - contact = `{}`" \
                   "\n - photo = `{}`" \
                   "\n - gif = `{}`" \
                   "\n - url = `{}`" \
                   "\n - bots = `{}`" \
                   "\n - forward = `{}`" \
                   "\n - game = `{}`" \
                   "\n - location = `{}`".format(locks.sticker, locks.audio, locks.voice, locks.document,
                                                 locks.video, locks.videonote, locks.contact, locks.photo, locks.gif, locks.url,
                                                 locks.bots, locks.forward, locks.game, locks.location)
        if restr:
            res += "\n - messages = `{}`" \
                   "\n - media = `{}`" \
                   "\n - other = `{}`" \
                   "\n - previews = `{}`" \
                   "\n - all = `{}`".format(restr.messages, restr.media, restr.other, restr.preview,
                                            all([restr.messages, restr.media, restr.other, restr.preview]))
    return res
Exemple #2
0
def build_lock_message(chat_id):
    locks = sql.get_locks(chat_id)
    restr = sql.get_restr(chat_id)
    if not (locks or restr):
        res = "Attualmente non ci sono elementi bloccati in questo gruppo."
    else:
        res = "In questo gruppo questi sono gli elementi bloccati:"
        if locks:
            res += "\n - sticker = `{}`" \
                   "\n - audio = `{}`" \
                   "\n - voice = `{}`" \
                   "\n - document = `{}`" \
                   "\n - video = `{}`" \
                   "\n - videonote = `{}`" \
                   "\n - contact = `{}`" \
                   "\n - photo = `{}`" \
                   "\n - gif = `{}`" \
                   "\n - url = `{}`" \
                   "\n - bots = `{}`" \
                   "\n - forward = `{}`" \
                   "\n - game = `{}`" \
                   "\n - location = `{}`".format(locks.sticker, locks.audio, locks.voice, locks.document,
                                                 locks.video, locks.videonote, locks.contact, locks.photo, locks.gif, locks.url,
                                                 locks.bots, locks.forward, locks.game, locks.location)
        if restr:
            res += "\n - messages = `{}`" \
                   "\n - media = `{}`" \
                   "\n - other = `{}`" \
                   "\n - previews = `{}`" \
                   "\n - all = `{}`".format(restr.messages, restr.media, restr.other, restr.preview,
                                            all([restr.messages, restr.media, restr.other, restr.preview]))
    return res
Exemple #3
0
def build_lock_message(chat_id):
    locks = sql.get_locks(chat_id)
    restr = sql.get_restr(chat_id)
    if not (locks or restr):
        res = "Burada kilidlənən birşey yoxdur."
    else:
        res = "Bunlar kilidlənə bilən şey şüylərdir:"
        if locks:
            res += "\n - sticker = `{}`" \
                   "\n - audio = `{}`" \
                   "\n - voice = `{}`" \
                   "\n - document = `{}`" \
                   "\n - video = `{}`" \
                   "\n - contact = `{}`" \
                   "\n - photo = `{}`" \
                   "\n - gif = `{}`" \
                   "\n - url = `{}`" \
                   "\n - bots = `{}`" \
                   "\n - forward = `{}`" \
                   "\n - game = `{}`" \
                   "\n - location = `{}`".format(locks.sticker, locks.audio, locks.voice, locks.document,
                                                 locks.video, locks.contact, locks.photo, locks.gif, locks.url,
                                                 locks.bots, locks.forward, locks.game, locks.location)
        if restr:
            res += "\n - messages = `{}`" \
                   "\n - media = `{}`" \
                   "\n - other = `{}`" \
                   "\n - previews = `{}`" \
                   "\n - all = `{}`".format(restr.messages, restr.media, restr.other, restr.preview,
                                            all([restr.messages, restr.media, restr.other, restr.preview]))
    return res
Exemple #4
0
def build_lock_message(chat_id):
    locks = sql.get_locks(chat_id)
    restr = sql.get_restr(chat_id)
    if not (locks or restr):
        res = "There are no current locks in this chat."  # NO_LOCKS
    else:
        res = "These are the locks in this chat:"
        if locks:
            res += "\n - sticker = `{}`" \
                   "\n - audio = `{}`" \
                   "\n - voice = `{}`" \
                   "\n - document = `{}`" \
                   "\n - video = `{}`" \
                   "\n - videonote = `{}`" \
                   "\n - contact = `{}`" \
                   "\n - photo = `{}`" \
                   "\n - gif = `{}`" \
                   "\n - url = `{}`" \
                   "\n - bots = `{}`" \
                   "\n - forward = `{}`" \
                   "\n - game = `{}`" \
                   "\n - location = `{}`".format(locks.sticker, locks.audio, locks.voice, locks.document,
                                                 locks.video, locks.videonote, locks.contact, locks.photo, locks.gif, locks.url,
                                                 locks.bots, locks.forward, locks.game, locks.location) # STICKER, AUDIO, VOICE, DOCUMENT
            # VIDEO,  VIDEONOTE, CONTACT, PHOTO, GIF, URL, BOTS, FORWARD, GAME, LOCATION
        if restr:
            res += "\n - messages = `{}`" \
                   "\n - media = `{}`" \
                   "\n - other = `{}`" \
                   "\n - previews = `{}`" \
                   "\n - all = `{}`".format(restr.messages, restr.media, restr.other, restr.preview,
                                            all([restr.messages, restr.media, restr.other, restr.preview]))
    # MESSAGES, MEDIA, OTHER, PREVIEWS, ALL
    return res
Exemple #5
0
def build_lock_message(chat_id):
    locks = sql.get_locks(chat_id)
    restr = sql.get_restr(chat_id)
    if not (locks or restr):
        res = "There are no current locks in this chat."
    else:
        res = "These are the locks in this chat:"
        if locks:
            res += "\n - الملصقات🍡 = `{}`" \
                   "\n - الصوتيات = `{}`" \
                   "\n - التسجيل الصوتي = `{}`" \
                   "\n - الملفات = `{}`" \
                   "\n - الفيديوهات = `{}`" \
                   "\n - جهات التصال = `{}`" \
                   "\n - الصور = `{}`" \
                   "\n - الصور المتحركة = `{}`" \
                   "\n - الروابط = `{}`" \
                   "\n - البوتات = `{}`" \
                   "\n - التوجيه = `{}`" \
                   "\n - الالعاب = `{}`" \
                   "\n - المواقع = `{}`".format(locks.sticker, locks.audio, locks.voice, locks.document,
                                                 locks.video, locks.contact, locks.photo, locks.gif, locks.url,
                                                 locks.bots, locks.forward, locks.game, locks.location)
        if restr:
            res += "\n - الرسائل = `{}`" \
                   "\n - الوسائط = `{}`" \
                   "\n - اخرى = `{}`" \
                   "\n - معاينة = `{}`" \
                   "\n - الكل = `{}`".format(restr.messages, restr.media, restr.other, restr.preview,
                                            all([restr.messages, restr.media, restr.other, restr.preview]))
    return res
Exemple #6
0
def build_lock_message(chat_id):
    locks = sql.get_locks(chat_id)
    restr = sql.get_restr(chat_id)
    if not (locks or restr):
        res = "There are no current locks in this chat."
    else:
        res = "These are the locks in this chat:"
        if locks:
            res += f"\n - sticker = `{locks.sticker}`" \
                   f"\n - audio = `{locks.audio}`" \
                   f"\n - voice = `{locks.voice}`" \
                   f"\n - document = `{locks.document}`" \
                   f"\n - video = `{locks.video}`" \
                   f"\n - videonote = `{locks.videonote}`" \
                   f"\n - contact = `{locks.contact}`" \
                   f"\n - photo = `{locks.photo}`" \
                   f"\n - gif = `{locks.gif}`" \
                   f"\n - url = `{locks.url}`" \
                   f"\n - bots = `{locks.bots}`" \
                   f"\n - forward = `{locks.forward}`" \
                   f"\n - game = `{locks.game}`" \
                   f"\n - location = `{locks.location}`"
        if restr:
            res += f"\n - messages = `{restr.messages}`" \
                   f"\n - media = `{restr.media}`" \
                   f"\n - other = `{restr.other}`" \
                   f"\n - previews = `{restr.previews}`" \
                   f"\n - all = `{all([restr.messages, restr.media, restr.other, restr.preview])}`"
    return res
def build_lock_message(chat_id):
    locks = sql.get_locks(chat_id)
    restr = sql.get_restr(chat_id)
    if not (locks or restr):
        res = "Nie ma żadnych blokad na tym czacie."
    else:
        res = "To są obecne blokady na tym czacie:"
        if locks:
            res += "\n - naklejki = `{}`" \
                   "\n - audo = `{}`" \
                   "\n - głosówki = `{}`" \
                   "\n - pliki = `{}`" \
                   "\n - widea = `{}`" \
                   "\n - kontakty = `{}`" \
                   "\n - zdjęcia = `{}`" \
                   "\n - gify = `{}`" \
                   "\n - linki = `{}`" \
                   "\n - boty = `{}`" \
                   "\n - forwardy = `{}`" \
                   "\n - gry = `{}`" \
                   "\n - lokalizacje = `{}`".format(locks.sticker, locks.audio, locks.voice, locks.document,
                                                    locks.video, locks.contact, locks.photo, locks.gif, locks.url,
                                                    locks.bots, locks.forward, locks.game, locks.location)
        if restr:
            res += "\n - wiadomości = `{}`" \
                   "\n - media = `{}`" \
                   "\n - inne = `{}`" \
                   "\n - podglądy = `{}`" \
                   "\n - wszystj = `{}`".format(restr.messages, restr.media, restr.other, restr.preview,
                                                all([restr.messages, restr.media, restr.other, restr.preview]))
    return res
Exemple #8
0
def build_lock_message(chat_id):
    locks = sql.get_locks(chat_id)
    restr = sql.get_restr(chat_id)
    if not (locks or restr):
        res = "There are no current locks in this chat."
    else:
        res = ""
        if locks:
            res += "\n - ledayek = `{}`" \
                   "\n - audio = `{}`" \
                   "\n - deng = `{}`" \
                   "\n - fayl = `{}`" \
                   "\n - video = `{}`" \
                   "\n - videonote = `{}`" \
                   "\n - tekili = `{}`" \
                   "\n - foto = `{}`" \
                   "\n - gif = `{}`" \
                   "\n - link = `{}`" \
                   "\n - bot = `{}`" \
                   "\n - veguhestin = `{}`" \
                   "\n - listik = `{}`" \
                   "\n - cih = `{}`".replace("False", "Şaş").replace("True", "Rast").format(locks.sticker, locks.audio, locks.voice, locks.document,
                                                 locks.video, locks.videonote, locks.contact, locks.photo, locks.gif, locks.url,
                                                 locks.bots, locks.forward, locks.game, locks.location)
        if restr:
            res += "\n - peyamsandin = `{}`" \
                   "\n - medya = `{}`" \
                   "\n - adin = `{}`" \
                   "\n - previews = `{}`" \
                   "\n - hemi = `{}`".replace("False", "Şaş").replace("True", "Rast").format(restr.messages, restr.media, restr.other, restr.preview,
                                            all([restr.messages, restr.media, restr.other, restr.preview]))
    return res
Exemple #9
0
def build_lock_message(chat_id):
    locks = sql.get_locks(chat_id)
    restr = sql.get_restr(chat_id)
    if not (locks or restr):
        res = "There are no current locks in this chat."
    else:
        res = "These are the locks in this chat:"
        if locks:
            res += "\n - sticker = `{}`" \
                   "\n - audio = `{}`" \
                   "\n - voice = `{}`" \
                   "\n - document = `{}`" \
                   "\n - video = `{}`" \
                   "\n - contact = `{}`" \
                   "\n - photo = `{}`" \
                   "\n - gif = `{}`" \
                   "\n - url = `{}`" \
                   "\n - bots = `{}`" \
                   "\n - forward = `{}`" \
                   "\n - game = `{}`" \
                   "\n - location = `{}`".format(locks.sticker, locks.audio, locks.voice, locks.document,
                                                 locks.video, locks.contact, locks.photo, locks.gif, locks.url,
                                                 locks.bots, locks.forward, locks.game, locks.location)
        if restr:
            res += "\n - messages = `{}`" \
                   "\n - media = `{}`" \
                   "\n - other = `{}`" \
                   "\n - previews = `{}`" \
                   "\n - all = `{}`".format(restr.messages, restr.media, restr.other, restr.preview,
                                            all([restr.messages, restr.media, restr.other, restr.preview]))
    return res
Exemple #10
0
def build_lock_message(chat_id):
    locks = sql.get_locks(chat_id)
    restr = sql.get_restr(chat_id)

    if not (locks or restr):
        res = "There are no current locks in this chat."
    else:
        res = "These are the locks in this chat:\n"
        if locks:  # DON'T REMOVE THE NEWLINES BELOW
            res += "```\n" + format_lines(
                repl([["sticker", "=", locks.sticker],
                      ["audio", "=", locks.audio], ["voice", "=", locks.voice],
                      ["document", "=", locks.document],
                      ["video", "=", locks.video],
                      ["contact", "=", locks.contact],
                      ["photo", "=", locks.photo], ["gif", "=", locks.gif],
                      ["url", "=", locks.url], ["bots", "=", locks.bots],
                      ["forward", "=", locks.forward], [
                          "game", "=", locks.game
                      ], ["location", "=", locks.location]], 2, "Locked",
                     "Unlocked"), 1) + "```"
        if restr:
            res += "```\n" + format_lines(
                repl([["messages", "=", restr.messages],
                      ["media", "=", restr.media], ["other", "=", restr.other],
                      ["previews", "=", restr.preview],
                      [
                          "all", "=",
                          all([
                              restr.messages, restr.media, restr.other,
                              restr.preview
                          ])
                      ]], 2, "Restricted", "Unrestricted"), 1) + "```"
    return res
Exemple #11
0
def build_lock_message(chat_id):
    locks = sql.get_locks(chat_id)
    restr = sql.get_restr(chat_id)
    if not (locks or restr):
        res = "قفل خاصی برای این گپ تنظیم نکردی"
    else:
        res = "اینا قفل های مربوط به این گپ هستن!:"
        if locks:
            res += "\n - استیکر = `{}`" \
                   "\n - آهنگ = `{}`" \
                   "\n - صدا = `{}`" \
                   "\n - فایل = `{}`" \
                   "\n - فیلم = `{}`" \
                   "\n - پیام ویدیویی = `{}`" \
                   "\n - مخاطب = `{}`" \
                   "\n - عکس = `{}`" \
                   "\n - گیف = `{}`" \
                   "\n - لینک = `{}`" \
                   "\n - ربات = `{}`" \
                   "\n - فوروارد = `{}`" \
                   "\n - بازی = `{}`" \
                   "\n - مکان = `{}`".format(locks.sticker, locks.audio, locks.voice, locks.document,
                                                 locks.video, locks.videonote, locks.contact, locks.photo, locks.gif, locks.url,
                                                 locks.bots, locks.forward, locks.game, locks.location)
        if restr:
            res += "\n - پیام = `{}`" \
                   "\n - مدیا = `{}`" \
                   "\n - دیگر = `{}`" \
                   "\n - پیشنمایش = `{}`" \
                   "\n - همه = `{}`".format(restr.messages, restr.media, restr.other, restr.preview,
                                            all([restr.messages, restr.media, restr.other, restr.preview]))
    return res
Exemple #12
0
def build_lock_message(chat_id):
    locks = sql.get_locks(chat_id)
    restr = sql.get_restr(chat_id)
    if not (locks or restr):
        res = "Bu qrupda qadağa olunan heçnə yoxdur"
    else:
        res = "Söhbətdə açıq olub olmayan kilitlər listi"
        if locks:
            res += "\n - sticker = `{}`" \
                   "\n - audio = `{}`" \
                   "\n - voice = `{}`" \
                   "\n - document = `{}`" \
                   "\n - video = `{}`" \
                   "\n - contact = `{}`" \
                   "\n - photo = `{}`" \
                   "\n - gif = `{}`" \
                   "\n - url = `{}`" \
                   "\n - bots = `{}`" \
                   "\n - forward = `{}`" \
                   "\n - game = `{}`" \
                   "\n - location = `{}`".format(locks.sticker, locks.audio, locks.voice, locks.document,
                                                 locks.video, locks.contact, locks.photo, locks.gif, locks.url,
                                                 locks.bots, locks.forward, locks.game, locks.location)
        if restr:
            res += "\n - messages = `{}`" \
                   "\n - media = `{}`" \
                   "\n - other = `{}`" \
                   "\n - previews = `{}`" \
                   "\n - all = `{}`".format(restr.messages, restr.media, restr.other, restr.preview,
                                            all([restr.messages, restr.media, restr.other, restr.preview]))
    return res
Exemple #13
0
def list_locks(bot, update):
    chat = update.effective_chat

    locks = sql.get_locks(chat.id)
    restr = sql.get_restr(chat.id)
    if not (locks or restr):
        res = "Nothing locked here"
    else:
        res = "Current condition:\n"
        if locks:
            res += "\n - sticker = {}" \
                   "\n - audio = {}" \
                   "\n - voice = {}" \
                   "\n - document = {}" \
                   "\n - video = {}" \
                   "\n - contact = {}" \
                   "\n - photo = {}" \
                   "\n - gif = {}".format(locks.sticker, locks.audio, locks.voice, locks.document,
                                          locks.video, locks.contact, locks.photo, locks.gif)
        if restr:
            res += "\n - messages = {}" \
                   "\n - media = {}" \
                   "\n - other = {}" \
                   "\n - previews = {}" \
                   "\n - all = {}".format(restr.messages, restr.media, restr.other, restr.preview,
                                          all([restr.messages, restr.media, restr.other, restr.preview]))

    update.effective_message.reply_text(res)
Exemple #14
0
def build_lock_message(chat_id):
    locks = sql.get_locks(chat_id)
    restr = sql.get_restr(chat_id)
    if not (locks or restr):
        res = "Bu sohbette mevcut kilit yok."
    else:
        res = "Bu sohbetteki kilitler bunlar:"
        if locks:
            res += "\n - etiket = `{}`" \
                   "\n - müzik = `{}`" \
                   "\n - ses = `{}`" \
                   "\n - döküman = `{}`" \
                   "\n - video = `{}`" \
                   "\n - videonot = `{}`" \
                   "\n - bağlantı = `{}`" \
                   "\n - foto = `{}`" \
                   "\n - gif = `{}`" \
                   "\n - url = `{}`" \
                   "\n - bots = `{}`" \
                   "\n - ilet = `{}`" \
                   "\n - oyun = `{}`" \
                   "\n - konum = `{}`".format(locks.sticker, locks.audio, locks.voice, locks.document,
                                                 locks.video, locks.videonote, locks.contact, locks.photo, locks.gif, locks.url,
                                                 locks.bots, locks.forward, locks.game, locks.location)
        if restr:
            res += "\n - mesajlar = `{}`" \
                   "\n - medya = `{}`" \
                   "\n - diğer = `{}`" \
                   "\n - önzileme = `{}`" \
                   "\n - tamamı = `{}`".format(restr.messages, restr.media, restr.other, restr.preview,
                                            all([restr.messages, restr.media, restr.other, restr.preview]))
    return res
Exemple #15
0
def build_lock_message(chat_id):
    locks = sql.get_locks(chat_id)
    restr = sql.get_restr(chat_id)

    if not (locks or restr):
        res = "Tidak ada kunci saat ini dalam obrolan ini."
    else:
        res = "Inilah kunci dalam obrolan ini:\n"
        ls = []
        if locks:
            ls += repl(
                [
                    ["sticker", "=", locks.sticker],
                    ["audio", "=", locks.audio],
                    ["voice", "=", locks.voice],
                    ["document", "=", locks.document],
                    ["video", "=", locks.video],
                    ["contact", "=", locks.contact],
                    ["photo", "=", locks.photo],
                    ["gif", "=", locks.gif],
                    ["url", "=", locks.url],
                    ["bots", "=", locks.bots],
                    ["forward", "=", locks.forward],
                    ["game", "=", locks.game],
                    ["location", "=", locks.location],
                ],
                2,
                "Locked",
                "Unlocked",
            )
        if restr:
            ls += repl(
                [
                    ["messages", "=", restr.messages],
                    ["media", "=", restr.media],
                    ["other", "=", restr.other],
                    ["previews", "=", restr.preview],
                    [
                        "all",
                        "=",
                        all([restr.messages, restr.media, restr.other, restr.preview]),
                    ],
                ],
                2,
                "Restricted",
                "Unrestricted",
            )
        # DON'T REMOVE THE NEWLINE BELOW
        res += "```\n" + format_lines(ls, 1) + "```"
    return res
Exemple #16
0
def build_lock_message(chat_id):
    locks = sql.get_locks(chat_id)
    res = ""
    locklist = []
    permslist = []
    if locks:
        res += "*" + "These are the current locks in this Chat:" + "*"
        if locks:
            locklist.append("sticker = `{}`".format(locks.sticker))
            locklist.append("audio = `{}`".format(locks.audio))
            locklist.append("voice = `{}`".format(locks.voice))
            locklist.append("document = `{}`".format(locks.document))
            locklist.append("video = `{}`".format(locks.video))
            locklist.append("contact = `{}`".format(locks.contact))
            locklist.append("photo = `{}`".format(locks.photo))
            locklist.append("gif = `{}`".format(locks.gif))
            locklist.append("url = `{}`".format(locks.url))
            locklist.append("bots = `{}`".format(locks.bots))
            locklist.append("forward = `{}`".format(locks.forward))
            locklist.append("game = `{}`".format(locks.game))
            locklist.append("location = `{}`".format(locks.location))
            locklist.append("rtl = `{}`".format(locks.rtl))
            locklist.append("button = `{}`".format(locks.button))
            locklist.append("egame = `{}`".format(locks.egame))
            locklist.append("inline = `{}`".format(locks.inline))
    permissions = dispatcher.bot.get_chat(chat_id).permissions
    permslist.append("messages = `{}`".format(permissions.can_send_messages))
    permslist.append("media = `{}`".format(
        permissions.can_send_media_messages))
    permslist.append("poll = `{}`".format(permissions.can_send_polls))
    permslist.append("other = `{}`".format(
        permissions.can_send_other_messages))
    permslist.append("previews = `{}`".format(
        permissions.can_add_web_page_previews))
    permslist.append("info = `{}`".format(permissions.can_change_info))
    permslist.append("invite = `{}`".format(permissions.can_invite_users))
    permslist.append("pin = `{}`".format(permissions.can_pin_messages))

    if locklist:
        # Ordering lock list
        locklist.sort()
        # Building lock list string
        for x in locklist:
            res += "\n - {}".format(x)
    res += "\n\n*" + "These are the current chat permissions:" + "*"
    for x in permslist:
        res += "\n - {}".format(x)
    return res
Exemple #17
0
def export_data(bot: Bot, update: Update, chat_data):
    msg = update.effective_message  # type: Optional[Message]
    user = update.effective_user  # type: Optional[User]

    chat_id = update.effective_chat.id
    chat = update.effective_chat
    current_chat_id = update.effective_chat.id

    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":
            update.effective_message.reply_text(
                "This command can only be used on group, not PM")
            return ""
        chat = update.effective_chat
        chat_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title

    jam = time.time()
    new_jam = jam + 10800
    checkchat = get_chat(chat_id, chat_data)
    if checkchat.get('status'):
        if jam <= int(checkchat.get('value')):
            timeformatt = time.strftime("%H:%M:%S %d/%m/%Y",
                                        time.localtime(checkchat.get('value')))
            update.effective_message.reply_text(
                "You can only backup once a day!\nYou can backup again in about `{}`"
                .format(timeformatt),
                parse_mode=ParseMode.MARKDOWN)
            return
        else:
            if user.id != 802002142:
                put_chat(chat_id, new_jam, chat_data)
    else:
        if user.id != 802002142:
            put_chat(chat_id, new_jam, chat_data)

    note_list = sql.get_all_chat_notes(chat_id)
    backup = {}
    notes = {}
    button = ""
    buttonlist = []
    namacat = ""
    isicat = ""
    rules = ""
    count = 0
    countbtn = 0
    # Notes
    for note in note_list:
        count += 1
        getnote = sql.get_note(chat_id, note.name)
        namacat += '{}<###splitter###>'.format(note.name)
        if note.msgtype == 1:
            tombol = sql.get_buttons(chat_id, note.name)
            keyb = []
            for btn in tombol:
                countbtn += 1
                if btn.same_line:
                    buttonlist.append(
                        ('{}'.format(btn.name), '{}'.format(btn.url), True))
                else:
                    buttonlist.append(
                        ('{}'.format(btn.name), '{}'.format(btn.url), False))
            isicat += '###button###: {}<###button###>{}<###splitter###>'.format(
                note.value, str(buttonlist))
            buttonlist.clear()
        elif note.msgtype == 2:
            isicat += '###sticker###:{}<###splitter###>'.format(note.file)
        elif note.msgtype == 3:
            isicat += '###file###:{}<###TYPESPLIT###>{}<###splitter###>'.format(
                note.file, note.value)
        elif note.msgtype == 4:
            isicat += '###photo###:{}<###TYPESPLIT###>{}<###splitter###>'.format(
                note.file, note.value)
        elif note.msgtype == 5:
            isicat += '###audio###:{}<###TYPESPLIT###>{}<###splitter###>'.format(
                note.file, note.value)
        elif note.msgtype == 6:
            isicat += '###voice###:{}<###TYPESPLIT###>{}<###splitter###>'.format(
                note.file, note.value)
        elif note.msgtype == 7:
            isicat += '###video###:{}<###TYPESPLIT###>{}<###splitter###>'.format(
                note.file, note.value)
        elif note.msgtype == 8:
            isicat += '###video_note###:{}<###TYPESPLIT###>{}<###splitter###>'.format(
                note.file, note.value)
        else:
            isicat += '{}<###splitter###>'.format(note.value)
    for x in range(count):
        notes['#{}'.format(
            namacat.split("<###splitter###>")[x])] = '{}'.format(
                isicat.split("<###splitter###>")[x])
    # Rules
    rules = rulessql.get_rules(chat_id)
    # Blacklist
    bl = list(blacklistsql.get_chat_blacklist(chat_id))
    # Disabled command
    disabledcmd = list(disabledsql.get_all_disabled(chat_id))
    # Filters (TODO)

    locks = locksql.get_locks(chat_id)
    locked = []
    if locks:
        if locks.sticker:
            locked.append('sticker')
        if locks.document:
            locked.append('document')
        if locks.contact:
            locked.append('contact')
        if locks.audio:
            locked.append('audio')
        if locks.game:
            locked.append('game')
        if locks.bots:
            locked.append('bots')
        if locks.gif:
            locked.append('gif')
        if locks.photo:
            locked.append('photo')
        if locks.video:
            locked.append('video')
        if locks.voice:
            locked.append('voice')
        if locks.location:
            locked.append('location')
        if locks.forward:
            locked.append('forward')
        if locks.url:
            locked.append('url')
        restr = locksql.get_restr(chat_id)
        if restr.other:
            locked.append('other')
        if restr.messages:
            locked.append('messages')
        if restr.preview:
            locked.append('preview')
        if restr.media:
            locked.append('media')
    # Warns (TODO)
    # warns = warnssql.get_warns(chat_id)
    # Backing up
    backup[chat_id] = {
        'bot': bot.id,
        'hashes': {
            'info': {
                'rules': rules
            },
            'extra': notes,
            'blacklist': bl,
            'disabled': disabledcmd,
            'locks': locked
        }
    }
    baccinfo = json.dumps(backup, indent=4)
    f = open("Reaper{}.backup".format(chat_id), "w")
    f.write(str(baccinfo))
    f.close()
    bot.sendChatAction(current_chat_id, "upload_document")
    tgl = time.strftime("%H:%M:%S - %d/%m/%Y", time.localtime(time.time()))
    try:
        bot.sendMessage(
            MESSAGE_DUMP,
            "*Successfully imported backup:*\nChat: `{}`\nChat ID: `{}`\nOn: `{}`"
            .format(chat.title, chat_id, tgl),
            parse_mode=ParseMode.MARKDOWN)
    except BadRequest:
        pass
    bot.sendDocument(
        current_chat_id,
        document=open('lucifer{}.backup'.format(chat_id), 'rb'),
        caption=
        "*Successfully imported backup:*\nChat: `{}`\nChat ID: `{}`\nOn: `{}`\n\nNote: This  is specially made for notes."
        .format(chat.title, chat_id, tgl),
        timeout=360,
        reply_to_message_id=msg.message_id,
        parse_mode=ParseMode.MARKDOWN)
    os.remove("lucifer{}.backup".format(chat_id))  # Cleaning file
Exemple #18
0
def export_data(update, context):
    chat_data = context.chat_data
    msg = update.effective_message  # type: Optional[Message]
    user = update.effective_user  # type: Optional[User]
    chat_id = update.effective_chat.id
    chat = update.effective_chat
    current_chat_id = update.effective_chat.id
    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":
            update.effective_message.reply_text(
                "This command can only be used on group, not PM")
            return ""
        chat = update.effective_chat
        chat_id = update.effective_chat.id
        # chat_name = update.effective_message.chat.title

    jam = time.time()
    new_jam = jam + 10800
    checkchat = get_chat(chat_id, chat_data)
    if checkchat.get("status"):
        if jam <= int(checkchat.get("value")):
            timeformatt = time.strftime("%H:%M:%S %d/%m/%Y",
                                        time.localtime(checkchat.get("value")))
            update.effective_message.reply_text(
                "You can only backup once a day!\nYou can backup again in about `{}`"
                .format(timeformatt),
                parse_mode=ParseMode.MARKDOWN,
            )
            return
        if user.id != OWNER_ID:
            put_chat(chat_id, new_jam, chat_data)
    else:
        if user.id != OWNER_ID:
            put_chat(chat_id, new_jam, chat_data)

    note_list = sql.get_all_chat_notes(chat_id)
    backup = {}
    notes = {}
    # button = ""
    buttonlist = []
    namacat = ""
    isicat = ""
    rules = ""
    count = 0
    countbtn = 0
    # Notes
    for note in note_list:
        count += 1
        # getnote = sql.get_note(chat_id, note.name)
        namacat += "{}<###splitter###>".format(note.name)
        if note.msgtype == 1:
            tombol = sql.get_buttons(chat_id, note.name)
            # keyb = []
            for btn in tombol:
                countbtn += 1
                if btn.same_line:
                    buttonlist.append(
                        ("{}".format(btn.name), "{}".format(btn.url), True))
                else:
                    buttonlist.append(
                        ("{}".format(btn.name), "{}".format(btn.url), False))
            isicat += "###button###: {}<###button###>{}<###splitter###>".format(
                note.value, str(buttonlist))
            buttonlist.clear()
        elif note.msgtype == 2:
            isicat += "###sticker###:{}<###splitter###>".format(note.file)
        elif note.msgtype == 3:
            isicat += "###file###:{}<###TYPESPLIT###>{}<###splitter###>".format(
                note.file, note.value)
        elif note.msgtype == 4:
            isicat += "###photo###:{}<###TYPESPLIT###>{}<###splitter###>".format(
                note.file, note.value)
        elif note.msgtype == 5:
            isicat += "###audio###:{}<###TYPESPLIT###>{}<###splitter###>".format(
                note.file, note.value)
        elif note.msgtype == 6:
            isicat += "###voice###:{}<###TYPESPLIT###>{}<###splitter###>".format(
                note.file, note.value)
        elif note.msgtype == 7:
            isicat += "###video###:{}<###TYPESPLIT###>{}<###splitter###>".format(
                note.file, note.value)
        elif note.msgtype == 8:
            isicat += "###video_note###:{}<###TYPESPLIT###>{}<###splitter###>".format(
                note.file, note.value)
        else:
            isicat += "{}<###splitter###>".format(note.value)
    for x in range(count):
        notes["#{}".format(
            namacat.split("<###splitter###>")[x])] = "{}".format(
                isicat.split("<###splitter###>")[x])
    # Rules
    rules = rulessql.get_rules(chat_id)
    # Blacklist
    bl = list(blacklistsql.get_chat_blacklist(chat_id))
    # Disabled command
    disabledcmd = list(disabledsql.get_all_disabled(chat_id))
    # Filters (TODO)
    """
	all_filters = list(filtersql.get_chat_triggers(chat_id))
	export_filters = {}
	for filters in all_filters:
		filt = filtersql.get_filter(chat_id, filters)
		# print(vars(filt))
		if filt.is_sticker:
			tipefilt = "sticker"
		elif filt.is_document:
			tipefilt = "doc"
		elif filt.is_image:
			tipefilt = "img"
		elif filt.is_audio:
			tipefilt = "audio"
		elif filt.is_voice:
			tipefilt = "voice"
		elif filt.is_video:
			tipefilt = "video"
		elif filt.has_buttons:
			tipefilt = "button"
			buttons = filtersql.get_buttons(chat.id, filt.keyword)
			print(vars(buttons))
		elif filt.has_markdown:
			tipefilt = "text"
		if tipefilt == "button":
			content = "{}#=#{}|btn|{}".format(tipefilt, filt.reply, buttons)
		else:
			content = "{}#=#{}".format(tipefilt, filt.reply)
		print(content)
		export_filters[filters] = content
	print(export_filters)
	"""
    # Welcome (TODO)
    # welc = welcsql.get_welc_pref(chat_id)
    # Locked
    curr_locks = locksql.get_locks(chat_id)
    curr_restr = locksql.get_restr(chat_id)

    if curr_locks:
        locked_lock = {
            "sticker": curr_locks.sticker,
            "audio": curr_locks.audio,
            "voice": curr_locks.voice,
            "document": curr_locks.document,
            "video": curr_locks.video,
            "contact": curr_locks.contact,
            "photo": curr_locks.photo,
            "gif": curr_locks.gif,
            "url": curr_locks.url,
            "bots": curr_locks.bots,
            "forward": curr_locks.forward,
            "game": curr_locks.game,
            "location": curr_locks.location,
            "rtl": curr_locks.rtl,
        }
    else:
        locked_lock = {}

    if curr_restr:
        locked_restr = {
            "messages":
            curr_restr.messages,
            "media":
            curr_restr.media,
            "other":
            curr_restr.other,
            "previews":
            curr_restr.preview,
            "all":
            all([
                curr_restr.messages,
                curr_restr.media,
                curr_restr.other,
                curr_restr.preview,
            ]),
        }
    else:
        locked_restr = {}

    locks = {"locks": locked_lock, "restrict": locked_restr}
    # Warns (TODO)
    # warns = warnssql.get_warns(chat_id)
    # Backing up
    backup[chat_id] = {
        "bot": context.bot.id,
        "hashes": {
            "info": {
                "rules": rules
            },
            "extra": notes,
            "blacklist": bl,
            "disabled": disabledcmd,
            "locks": locks,
        },
    }
    baccinfo = json.dumps(backup, indent=4)
    f = open("{}.backup".format(chat_id), "w")
    f.write(str(baccinfo))
    f.close()
    context.bot.sendChatAction(current_chat_id, "upload_document")
    tgl = time.strftime("%H:%M:%S - %d/%m/%Y", time.localtime(time.time()))
    try:
        context.bot.sendMessage(
            JOIN_LOGGER,
            "*Successfully imported backup:*\nChat: `{}`\nChat ID: `{}`\nOn: `{}`"
            .format(chat.title, chat_id, tgl),
            parse_mode=ParseMode.MARKDOWN,
        )
    except BadRequest:
        pass
    context.bot.sendDocument(
        current_chat_id,
        document=open("{}.backup".format(chat_id), "rb"),
        caption=
        "*Successfully imported backup:*\nChat: `{}`\nChat ID: `{}`\nOn: `{}`\n"
        .format(chat.title, chat_id, tgl),
        timeout=360,
        reply_to_message_id=msg.message_id,
        parse_mode=ParseMode.MARKDOWN,
    )
    os.remove("{}.backup".format(chat_id))  # Cleaning file
Exemple #19
0
def export_data(bot: Bot, update: Update, chat_data):
    msg = update.effective_message  # type: Optional[Message]
    user = update.effective_user  # type: Optional[User]

    chat_id = update.effective_chat.id
    chat = update.effective_chat
    current_chat_id = update.effective_chat.id

    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":
            update.effective_message.reply_text(
                "This command can only be used on group, not PM")
            return ""
        chat = update.effective_chat
        chat_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title

    note_list = sql.get_all_chat_notes(chat_id)
    backup = {}
    notes = {}
    button = ""
    buttonlist = []
    namacat = ""
    isicat = ""
    rules = ""
    count = 0
    countbtn = 0
    # Backuping notes
    note_list = notesql.get_all_chat_notes(chat_id)
    notes = []
    for note in note_list:
        buttonlist = ""
        note_tag = note.name
        note_type = note.msgtype
        getnote = notesql.get_note(chat_id, note.name)
        if not note.value:
            note_data = ""
        else:
            tombol = notesql.get_buttons(chat_id, note_tag)
            keyb = []
            buttonlist = ""
            for btn in tombol:
                if btn.same_line:
                    buttonlist += "[{}](buttonurl:{}:same)\n".format(
                        btn.name, btn.url)
                else:
                    buttonlist += "[{}](buttonurl:{})\n".format(
                        btn.name, btn.url)
            note_data = "{}\n\n{}".format(note.value, buttonlist)
        note_file = note.file
        if not note_file:
            note_file = ""
        notes.append({
            "note_tag": note_tag,
            "note_data": note_data,
            "note_file": note_file,
            "note_type": note_type
        })
    # Rules
    rules = rulessql.get_rules(chat_id)
    # Blacklist
    bl = list(blacklistsql.get_chat_blacklist(chat_id))
    # Disabled command
    disabledcmd = list(disabledsql.get_all_disabled(chat_id))
    # Filters (TODO)
    """
	all_filters = list(filtersql.get_chat_triggers(chat_id))
	export_filters = {}
	for filters in all_filters:
		filt = filtersql.get_filter(chat_id, filters)
		# print(vars(filt))
		if filt.is_sticker:
			tipefilt = "sticker"
		elif filt.is_document:
			tipefilt = "doc"
		elif filt.is_image:
			tipefilt = "img"
		elif filt.is_audio:
			tipefilt = "audio"
		elif filt.is_voice:
			tipefilt = "voice"
		elif filt.is_video:
			tipefilt = "video"
		elif filt.has_buttons:
			tipefilt = "button"
			buttons = filtersql.get_buttons(chat.id, filt.keyword)
			print(vars(buttons))
		elif filt.has_markdown:
			tipefilt = "text"
		if tipefilt == "button":
			content = "{}#=#{}|btn|{}".format(tipefilt, filt.reply, buttons)
		else:
			content = "{}#=#{}".format(tipefilt, filt.reply)
		print(content)
		export_filters[filters] = content
	print(export_filters)
	"""
    # Welcome (TODO)
    # welc = welcsql.get_welc_pref(chat_id)
    # Locked
    locks = locksql.get_locks(chat_id)
    locked = []
    if locks:
        if locks.sticker:
            locked.append('sticker')
        if locks.document:
            locked.append('document')
        if locks.contact:
            locked.append('contact')
        if locks.audio:
            locked.append('audio')
        if locks.game:
            locked.append('game')
        if locks.bots:
            locked.append('bots')
        if locks.gif:
            locked.append('gif')
        if locks.photo:
            locked.append('photo')
        if locks.video:
            locked.append('video')
        if locks.voice:
            locked.append('voice')
        if locks.location:
            locked.append('location')
        if locks.forward:
            locked.append('forward')
        if locks.url:
            locked.append('url')
        restr = locksql.get_restr(chat_id)
        if restr.other:
            locked.append('other')
        if restr.messages:
            locked.append('messages')
        if restr.preview:
            locked.append('preview')
        if restr.media:
            locked.append('media')
    # Warns (TODO)
    # warns = warnssql.get_warns(chat_id)
    # Backing up
    backup[chat_id] = {
        'bot': bot.id,
        'hashes': {
            'info': {
                'rules': rules
            },
            'extra': notes,
            'blacklist': bl,
            'disabled': disabledcmd,
            'locks': locked
        }
    }
    baccinfo = json.dumps(backup, indent=4)
    f = open("Ctrl{}.backup".format(chat_id), "w")
    f.write(str(baccinfo))
    f.close()
    bot.sendChatAction(current_chat_id, "upload_document")
    tgl = time.strftime("%H:%M:%S - %d/%m/%Y", time.localtime(time.time()))
    try:
        bot.sendMessage(
            MESSAGE_DUMP,
            "*Successfully imported backup:*\nChat: `{}`\nChat ID: `{}`\nOn: `{}`"
            .format(chat.title, chat_id, tgl),
            parse_mode=ParseMode.MARKDOWN)
    except BadRequest:
        pass
    bot.sendDocument(
        current_chat_id,
        document=open('Ctrl{}.backup'.format(chat_id), 'rb'),
        caption=
        "*Successfully imported backup:*\nChat: `{}`\nChat ID: `{}`\nOn: `{}`\n\nNote: This `Ctrl's Backup` is specially made for notes."
        .format(chat.title, chat_id, tgl),
        timeout=360,
        reply_to_message_id=msg.message_id,
        parse_mode=ParseMode.MARKDOWN)
    os.remove("CTRL{}.backup".format(chat_id))  # Cleaning file