|
| 1 | +# Modules |
| 2 | +import discord |
| 3 | +from requests import get |
| 4 | + |
| 5 | +from assets.prism import Tools |
| 6 | +from discord.ext import commands |
| 7 | + |
| 8 | +# Main Command Class |
| 9 | +class Update(commands.Cog): |
| 10 | + |
| 11 | + def __init__(self, bot): |
| 12 | + self.bot = bot |
| 13 | + self.desc = "Grabs the latest commit to Prism" |
| 14 | + self.usage = "update" |
| 15 | + |
| 16 | + self.url = "https://api.github.com/repos/ii-Python/Prism/commits" |
| 17 | + |
| 18 | + @commands.command() |
| 19 | + async def update(self, ctx): |
| 20 | + |
| 21 | + m = await ctx.send(embed = discord.Embed(title = "Fetching commits..", color = 0x126bf1)) |
| 22 | + |
| 23 | + try: |
| 24 | + |
| 25 | + r = get(self.url).json() |
| 26 | + |
| 27 | + try: |
| 28 | + |
| 29 | + await m.delete() |
| 30 | + |
| 31 | + except: |
| 32 | + |
| 33 | + pass |
| 34 | + |
| 35 | + except: |
| 36 | + |
| 37 | + return await ctx.send(embed = Tools.error("Sorry, something went wrong while fetching update.")) |
| 38 | + |
| 39 | + commit = r[0]["commit"] |
| 40 | + |
| 41 | + date = commit["committer"]["date"].split("T")[0] |
| 42 | + |
| 43 | + verification = f":white_check_mark:" if commit["verification"]["verified"] else ":x:" |
| 44 | + |
| 45 | + if commit["verification"]["signature"]: |
| 46 | + |
| 47 | + verification += f" ({commit['verification']['signature']})" |
| 48 | + |
| 49 | + embed = discord.Embed(title = commit["message"], url = "https://github.com/ii-Python/Prism/commit/" + commit["url"].split("/")[-1], color = 0x126bf1) |
| 50 | + |
| 51 | + embed.add_field(name = "Pushed by", value = commit["committer"]["name"], inline = False) |
| 52 | + |
| 53 | + embed.add_field(name = "Push verified", value = verification, inline = False) |
| 54 | + |
| 55 | + embed.add_field(name = "Pushed on", value = date, inline = False) |
| 56 | + |
| 57 | + embed.set_author(name = " | Update", icon_url = self.bot.user.avatar_url) |
| 58 | + |
| 59 | + embed.set_footer(text = f" | Requested by {ctx.author}.", icon_url = ctx.author.avatar_url) |
| 60 | + |
| 61 | + return await ctx.send(embed = embed) |
| 62 | + |
| 63 | +# Link to bot |
| 64 | +def setup(bot): |
| 65 | + bot.add_cog(Update(bot)) |
0 commit comments