# ╔╗╔┌─┐┬─┐┌─┐┬ ┬
# ║║║├┤ ├┬┘│ └┬┘
# ╝╚╝└─┘┴└─└─┘ ┴
# Code is licensed under CC-BY-NC-ND 4.0 unless otherwise specified.
# https://creativecommons.org/licenses/by-nc-nd/4.0/
# You CANNOT edit this file without direct permission from the author.
# You can redistribute this file without any changes.
# meta developer: @nercymods
# scope: hikka_min 1.6.2
import requests
from hikkatl.tl.types import Message
from .. import loader, utils
@loader.tds
class GitHubMod(loader.Module):
"""Module for fetching GitHub profile or repository information"""
strings = {
"name": "GitHubMod",
"profile_info": "GitHub Profile Info: ",
"repo_info": "GitHub Repository Info: ",
"invalid_link": (
"❌Invalid GitHub link."
" The correct link should start with https://github.com..."
),
"user_not_found": (
"❌User not found."
),
"repo_not_found": (
"❌Repository not"
" found."
),
}
@loader.command(en_doc=" - Fetch information about GitHub profile")
async def gitprof(self, message: Message):
""" - Fetch information about GitHub profile"""
if not (link := utils.get_args_raw(message)):
await utils.answer(message, self.strings["invalid_link"])
return
if link.startswith("https://github.com/"):
username = link.split("/")[3]
try:
response = await utils.run_sync(
requests.get, f"https://api.github.com/users/{username}"
)
response.raise_for_status()
user_data = response.json()
info_text = (
f"{self.strings['profile_info']}\n\n📦Link:"
f" {link}\n🌐Username:"
f" {user_data.get('login', 'N/A')}\n🌐Name:"
f" {user_data.get('name', 'N/A')}\n🖌Bio:"
f" {user_data.get('bio', 'N/A')}\n🪧Location:"
f" {user_data.get('location', 'N/A')}\n🔥Followers:"
f" {user_data.get('followers', 'N/A')}\n❤️Following:"
f" {user_data.get('following', 'N/A')}\n📗Public Repositories:"
f" {user_data.get('public_repos', 'N/A')}\n"
)
if avatar_url := user_data.get("avatar_url"):
await utils.answer_file(
message,
avatar_url,
info_text,
link_preview=False,
)
else:
await utils.answer(message, info_text)
except Exception:
await utils.answer(message, self.strings["user_not_found"])
@loader.command(ru_doc="Fetch information about GitHub repository")
async def gitrepo(self, message: Message):
"""Fetch information about GitHub repository"""
if not (link := utils.get_args_raw(message)):
await utils.answer(message, self.strings["invalid_link"])
return
if link.startswith("https://github.com/"):
parts = link.split("/")
if len(parts) >= 5:
username = parts[3]
repo_name = parts[4]
elif len(link.split("/")) == 2:
username, repo_name = link.split("/")
try:
response = await utils.run_sync(
requests.get, f"https://api.github.com/repos/{username}/{repo_name}"
)
response.raise_for_status()
repo_data = response.json()
info_text = (
f"{self.strings['repo_info']}\n\n📦Link:"
f" {link}\n📗Repository:"
f" {repo_data.get('name', 'N/A')}\n🖌Description:"
f" {repo_data.get('description', 'N/A')}\n🌐Language:"
f" {repo_data.get('language', 'N/A')}\n🔥Stars:"
f" {repo_data.get('stargazers_count', 'N/A')}\n↕️Forks:"
f" {repo_data.get('forks_count', 'N/A')}\n👀Watchers:"
f" {repo_data.get('watchers_count', 'N/A')}\n"
)
if avatar_url := repo_data.get("avatar_url"):
await utils.answer_file(
message,
avatar_url,
info_text,
link_preview=False,
)
else:
await utils.answer(message, info_text)
except Exception:
await utils.answer(message, self.strings["repo_not_found"])