def add_feed_entry(feed, update):
     entry = feed.add_entry()
     entry.title(
         f"MIUI {update.version} {update.method} update for {update.fullname}"
     )
     entry.link(href=update.link, rel='alternate')
     try:
         entry.pubDate(
             datetime.combine(update.date,
                              datetime.min.time(),
                              tzinfo=timezone.utc))
     except TypeError:
         entry.pubDate(
             datetime.combine(datetime.today(),
                              datetime.min.time(),
                              tzinfo=timezone.utc))
     description = f"<p<b>New {update.branch} {update.method} update available!</b></p>\n" \
                   f"<p><b>Device:</b> {update.fullname}</p>\n" \
                   f"<p><b>Codename:</b> {update.codename.split('_')[0]}</p>\n" \
                   f"<p><b>Version:</b> {update.version} | {update.android}</p>\n" \
                   f"<p><b>Size:</b> {naturalsize(update.size)}</p>\n" \
                   f"<p><b>MD5:</b> {update.md5}</p>\n" \
                   f"<p><b>Changelog:</b><br>" + '<br>'.join(update.changelog.splitlines()) + \
                   f"</p>\n<p><b>Download:</b> <a href='{update.link}'>Here</a></p>"
     if update.method == "Recovery":
         incremental = get_incremental(update.version)
         if incremental:
             description += f"<p><b>Incremental Update:</b> <a href='{incremental.link}'>Here</a></p>"
     entry.description(description)
     return feed
    def generate_message(self, update: Update) -> str:
        """
        Generate an update message from and `Update` object
        :param update: an Update object that contains update's information from official website
        :return: A string containing the update's message
        """
        short_codename = update.codename.split('_')[0]
        # incremental update
        incremental = None
        if update.method == "Recovery":
            incremental = get_incremental(update.version)

        return self.update_template.substitute(
            type=f"{update.branch} {update.method}",
            device=get_full_name(update.codename),
            codename=short_codename,
            version=update.version,
            android=update.android,
            date=update.date,
            zip_size=naturalsize(update.size),
            md5_hash=update.md5 if update.md5 else "Unknown",
            link=update.link,
            incremental_link=f'[URL="{incremental.link}"]Here[/URL]' if incremental else "Unavailable",
            changelog=update.changelog
        )
Beispiel #3
0
 def generate_message(self, update: Update) -> (str, InlineKeyboardMarkup):
     """
     Generate an update message from and `Update` object
     :param update: an Update object that contains update's information from official website
     :return: A string containing the update's message
      and inline keyboard that has download link'
     """
     short_codename = update.codename.split('_')[0]
     message: str = f"New update available!"
     if update.method == "Fastboot":
         message += '\n'
     else:
         if self.source == "website":
             message += " (on the official website)\n"
         elif self.source == "updater":
             message += " (via OTA)\n"
         else:
             message += "\n"
     message += f"*Device*: {get_full_name(update.codename)}\n" \
                f"*Codename*: #{short_codename}\n" \
                f"*Type*: {update.branch} {update.method}\n" \
                f"*Version*: `{update.version} | {update.android}`\n" \
                f"*Size*: {naturalsize(update.size)}\n"
     if update.md5:
         message += f"*MD5*: `{update.md5}`\n"
     if update.changelog != "Bug fixes and system optimizations.":
         if len(update.changelog) + len(message) > 4000:
             branch = quote(update.branch.lower())
             message += f"*Changelog*: [Here]({website}/miui/{short_codename}/" \
                        f"{branch}/{update.version}/)\n"
         else:
             message += f"*Changelog*:\n`{update.changelog.replace('[', '(').replace(']', ')')}`\n"
     message += "\n@MIUIUpdatesTracker | @XiaomiFirmwareUpdater"
     button: InlineKeyboardButton = InlineKeyboardButton(
         "Full ROM", update.link)
     # bot subscribe
     subscribe_command = str(b64encode(
         bytes(f"/subscribe miui {short_codename}", encoding='utf-8')),
                             encoding='utf-8')
     more_buttons = [
         InlineKeyboardButton("Latest", f"{website}/miui/{short_codename}"),
         InlineKeyboardButton("Archive",
                              f"{website}/archive/miui/{short_codename}"),
         InlineKeyboardButton(
             "Subscribe",
             f"https://t.me/XiaomiGeeksBot?start={subscribe_command}")
     ]
     # incremental update
     if update.method == "Recovery":
         incremental = get_incremental(update.version)
         if incremental:
             incremental_button: InlineKeyboardButton = InlineKeyboardButton(
                 "Incremental", incremental.link)
             return message, InlineKeyboardMarkup(
                 [[button, incremental_button], more_buttons])
     return message, InlineKeyboardMarkup([[button], more_buttons])
 async def send_message(self, update: Update):
     """
     Generates and sends a Discord message
     """
     short_codename = update.codename.split('_')[0]
     message = f"**Device**: {get_full_name(update.codename)}\n" \
               f"**Codename**: `{short_codename}`\n" \
               f"**Version**: `{update.version} | {update.android}`\n" \
               f"**Size**: {naturalsize(update.size)}\n"
     if update.md5:
         message += f"**MD5**: `{update.md5}`\n"
     if update.changelog != "Bug fixes and system optimizations.":
         if len(update.changelog) + len(message) > 2000:
             branch = quote(update.branch.lower())
             message += f"**Changelog**: {website}/miui/{short_codename}/" \
                        f"{branch}/{update.version}/\n"
         else:
             message += f"**Changelog**:\n`{update.changelog}`\n"
     embed = Embed(
         title=f"New {update.branch} {update.method} update available!",
         color=Colour.orange(),
         description=message)
     embed.add_field(name="Full ROM",
                     value=f'[Download]({update.link})',
                     inline=True)
     if update.method == "Recovery":
         incremental = get_incremental(update.version)
         if incremental:
             embed.add_field(name="Incremental",
                             value=f'[Download]({incremental.link})',
                             inline=True)
     embed.add_field(name="Latest",
                     value=f'[Here]({website}/miui/{short_codename})',
                     inline=True)
     embed.add_field(
         name="Archive",
         value=f'[Here]({website}/archive/miui/{short_codename})',
         inline=True)
     device = get_device_name(update.codename).lower()
     for name, channel in self.channels.items():
         if device.startswith(name):
             await channel.send(embed=embed)
             return
     await self.channels['other_phones'].send(embed=embed)
 def generate_post(update: Update) -> (str, str):
     short_codename = update.codename.split('_')[0]
     link = f"{website}/miui/{short_codename}"
     message: str = f"New {update.branch} {update.method} update available for " \
                    f"{get_full_name(update.codename)} ({short_codename})!\n\n"
     message += f"Version: {update.version} | {update.android}\n" \
                f"Size: {naturalsize(update.size)}\n"
     if update.md5:
         message += f"MD5: {update.md5}\n"
     message += f"\nFull Update: {update.link}\n"
     # incremental update
     if update.method == "Recovery":
         incremental = get_incremental(update.version)
         if incremental:
             message += f"\nIncremental Update: {incremental.link}\n"
     if update.changelog != "Bug fixes and system optimizations.":
         message += f"\nChangelog:\n{update.changelog}\n"
     message += f"\n#MIUI_Updates #Xiaomi #MIUI #{get_device_name(update.codename).replace(' ', '')}"
     if update.version.startswith("V"):
         message += f" #MIUI{update.version.split('V')[1].split('.')[0]}"
     message += f" #Android{update.android.split('.')[0]}"
     return message, link