1+ import aiohttp
2+
13import cog
4+ from utils .stores .config import REPO_URL
25
36
47class Handler (cog .Cog ):
58 def __init__ (self , bot : cog .Bot ):
69 super ().__init__ (bot )
10+ self ._githubCache = cog .types .AsyncLRUTTLCache (maxsize = 10 , ttl = 300 )
11+
12+ async def get_latest_commit (self ):
13+ async def _fetch ():
14+ try :
15+ async with aiohttp .ClientSession () as session :
16+ async with session .get (
17+ f"{ self .bot .config .GITHUB_API_URL } /commits?per_page=1" ,
18+ timeout = aiohttp .ClientTimeout (total = 10 ),
19+ ) as resp :
20+ if resp .status != 200 :
21+ return None
22+ data = await resp .json ()
23+ except Exception :
24+ return None
25+
26+ if not data or not isinstance (data , list ) or len (data ) == 0 :
27+ return None
28+ commit = data [0 ]
29+ sha = commit .get ("sha" , "" )[:7 ]
30+ committer = commit .get ("commit" , {}).get ("committer" , {})
31+ date = committer .get ("date" , "" )[:10 ]
32+ message = commit .get ("commit" , {}).get ("message" , "" ).split ("\n " )[0 ]
33+ return {"sha" : sha , "date" : date , "message" : message }
34+
35+ return await self ._githubCache .resolve ("latest_commit" , _fetch )
736
837 @cog .regMessage (cog .F .text == "/start" )
938 async def startcommand (self , message : cog .Message ):
@@ -15,12 +44,21 @@ async def startcommand(self, message: cog.Message):
1544
1645 @cog .regMessage (cog .F .text == "/about" )
1746 async def aboutcommand (self , message : cog .Message ):
18- await message .answer ("""About Fast Sticker Bot!
47+ commit = await self .get_latest_commit ()
48+ committed = ""
49+ if commit :
50+ committed += (
51+ f"\n <pre>Latest commit: <code>{ commit ['sha' ]} </code> ({ commit ['date' ]} )"
52+ f"\n Message: { commit ['message' ]} </pre>"
53+ )
54+
55+ output = f"""About this bot
1956
2057This bot created for simplier stickerpack creation using: already existing stickers, gifs, and media from your gallery.
2158This bot will convert your media to needed format for telegram to save it in your stickerpack.
22-
23- <a href="https://github.com/okiscape/faststicker-tgbot">Sources</a>""" )
59+ { committed }
60+ <a href="{ REPO_URL } ">Sources</a>"""
61+ await message .answer (output )
2462
2563 @cog .regMessage (cog .F .text == "/help" )
2664 async def helpcommand (self , message : cog .Message ):
0 commit comments