Skip to content

Commit 40303a5

Browse files
committed
feat(version display): added version display into /about
1 parent 321743c commit 40303a5

2 files changed

Lines changed: 45 additions & 3 deletions

File tree

cogs/start.py

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,38 @@
1+
import aiohttp
2+
13
import cog
4+
from utils.stores.config import REPO_URL
25

36

47
class 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"\nMessage: {commit['message']}</pre>"
53+
)
54+
55+
output = f"""About this bot
1956
2057
This bot created for simplier stickerpack creation using: already existing stickers, gifs, and media from your gallery.
2158
This 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):

utils/stores/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
defaults = DefaultBotProperties(parse_mode="HTML", link_preview_is_disabled=True)
1111
databasePath = "utils/base.db"
1212

13+
REPO = "okiscape/faststicker-tgbot"
14+
REPO_URL = f"https://github.com/{REPO}"
15+
GITHUB_API_URL = f"https://api.github.com/repos/{REPO}"
16+
1317
defaultTimezone = pytz.timezone("Europe/Moscow")
1418

1519
logIgnoreTypes = ["preload"]

0 commit comments

Comments
 (0)