-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgit_pusher.py
executable file
·84 lines (68 loc) · 3.2 KB
/
git_pusher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# █ █ ▀ █▄▀ ▄▀█ █▀█ ▀
# █▀█ █ █ █ █▀█ █▀▄ █
# © Copyright 2022
# https://t.me/hikariatama
#
# 🔒 Licensed under the GNU AGPLv3
# 🌐 https://www.gnu.org/licenses/agpl-3.0.html
# meta pic: https://static.dan.tatar/git_pusher.png
# meta banner: https://mods.hikariatama.ru/badges/git_pusher.jpg
# meta developer: @hikarimods
# scope: hikka_only
# scope: hikka_min 1.2.10
import os
from random import choice
import requests
from telethon.tl.types import Message
from .. import loader, utils
@loader.tds
class GitPusherMod(loader.Module):
"""Easily push your repo from within the Telegram"""
strings = {
"name": "GitPusher",
"bad_dir": "🚫 <b>Invalid directory</b>",
"no_dir": "🚫 <b>Specify directory with </b><code>.setghdir</code>",
"dir_set": "🌳 <b>Updated git directory to</b> <code>{}</code>",
"terminal_required": "🚫 <b>Terminal module is required</b>",
}
strings_ru = {
"bad_dir": "🚫 <b>Неверная директория</b>",
"no_dir": "🚫 <b>Укажи директорию используя </b><code>.setghdir</code>",
"dir_set": "🌳 <b>Директория обновлена на</b> <code>{}</code>",
"terminal_required": "🚫 <b>Необходими модуль Terminal</b>",
"_cmd_doc_setghdir": "<path> - Установить директорию в качестве основной",
"_cmd_doc_push": "[commit message] - Закоммитить установленную директорию",
"_cls_doc": "Быстро коммить изменения в директории не выходя из Телеграм",
}
async def client_ready(self):
self.commits = (
await utils.run_sync(
requests.get,
"https://gist.github.com/hikariatama/b0a7001306ebcc74535992c13cd33f99/raw/7a5e2c0439d31c4fedf2530ffae650ae1cb9dd0c/commit_msgs.json",
)
).json()
async def setghdircmd(self, message: Message):
"""<path> - Set directory as upstream"""
args = utils.get_args_raw(message)
if not args or not os.path.isdir(args.strip()):
await utils.answer(message, self.strings("bad_dir"))
return
self.set("dir", args)
await utils.answer(message, self.strings("dir_set").format(args))
async def pushcmd(self, message: Message):
"""[commit message] - Push current upstream directory"""
if not self.get("dir"):
await utils.answer(message, self.strings("no_dir"))
return
if "terminal" not in self.allmodules.commands:
await utils.answer(message, self.strings("terminal_required"))
return
args = (utils.get_args_raw(message) or choice(self.commits)).replace('"', '\\"')
message = await utils.answer(
message,
(
f"<code>.terminal cd {utils.escape_html(self.get('dir'))} && git commit"
f' -am "{utils.escape_html(args)}" && git push</code>'
),
)
await self.allmodules.commands["terminal"](message)