|
5 | 5 | # PLease read the GNU Affero General Public License in |
6 | 6 | # <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>. |
7 | 7 |
|
8 | | -import os |
| 8 | +import re |
| 9 | +from os import execl, remove |
9 | 10 |
|
| 11 | +import requests |
10 | 12 | from telegraph import Telegraph |
11 | 13 | from telegraph import upload_file as upl |
12 | 14 |
|
|
22 | 24 | TOKEN_FILE = "resources/auths/auth_token.txt" |
23 | 25 |
|
24 | 26 |
|
| 27 | +@callback("updatenow") |
| 28 | +@owner |
| 29 | +async def update(eve): |
| 30 | + repo = Repo() |
| 31 | + ac_br = repo.active_branch |
| 32 | + ups_rem = repo.remote("upstream") |
| 33 | + if Var.HEROKU_API: |
| 34 | + import heroku3 |
| 35 | + |
| 36 | + heroku = heroku3.from_key(Var.HEROKU_API) |
| 37 | + heroku_app = None |
| 38 | + heroku_applications = heroku.apps() |
| 39 | + for app in heroku_applications: |
| 40 | + if app.name == Var.HEROKU_APP_NAME: |
| 41 | + heroku_app = app |
| 42 | + if heroku_app is None: |
| 43 | + await eve.edit("`Invalid Heroku credentials for updating userbot dyno.`") |
| 44 | + repo.__del__() |
| 45 | + return |
| 46 | + await eve.edit( |
| 47 | + "`Userbot dyno build in progress, please wait for it to complete.`" |
| 48 | + ) |
| 49 | + ups_rem.fetch(ac_br) |
| 50 | + repo.git.reset("--hard", "FETCH_HEAD") |
| 51 | + heroku_git_url = heroku_app.git_url.replace( |
| 52 | + "https://", "https://api:" + Var.HEROKU_API + "@" |
| 53 | + ) |
| 54 | + if "heroku" in repo.remotes: |
| 55 | + remote = repo.remote("heroku") |
| 56 | + remote.set_url(heroku_git_url) |
| 57 | + else: |
| 58 | + remote = repo.create_remote("heroku", heroku_git_url) |
| 59 | + try: |
| 60 | + remote.push(refspec=f"HEAD:refs/heads/{ac_br}", force=True) |
| 61 | + except GitCommandError as error: |
| 62 | + await eve.edit(f"`Here is the error log:\n{error}`") |
| 63 | + repo.__del__() |
| 64 | + return |
| 65 | + await eve.edit("`Successfully Updated!\nRestarting, please wait...`") |
| 66 | + else: |
| 67 | + try: |
| 68 | + ups_rem.pull(ac_br) |
| 69 | + except GitCommandError: |
| 70 | + repo.git.reset("--hard", "FETCH_HEAD") |
| 71 | + await updateme_requirements() |
| 72 | + await eve.edit( |
| 73 | + "`Successfully Updated!\nBot is restarting... Wait for a second!`" |
| 74 | + ) |
| 75 | + execl(sys.executable, sys.executable, "-m", "pyUltroid") |
| 76 | + |
| 77 | + |
| 78 | +@callback("changes") |
| 79 | +@owner |
| 80 | +async def changes(okk): |
| 81 | + repo = Repo.init() |
| 82 | + ac_br = repo.active_branch |
| 83 | + changelog, tl_chnglog = await gen_chlog(repo, f"HEAD..upstream/{ac_br}") |
| 84 | + changelog_str = changelog + f"\n\nClick the below button to update!" |
| 85 | + tldr_str = tl_chnglog + f"\n\nClick the below button to update!" |
| 86 | + if len(changelog_str) > 1024: |
| 87 | + await okk.edit(get_string("upd_4")) |
| 88 | + file = open(f"ultroid_updates.txt", "w+") |
| 89 | + file.write(tldr_str) |
| 90 | + file.close() |
| 91 | + await okk.edit( |
| 92 | + get_string("upd_5"), |
| 93 | + file="ultroid_updates.txt", |
| 94 | + buttons=Button.inline("Update Now", data="updatenow"), |
| 95 | + ) |
| 96 | + remove(f"ultroid_updates.txt") |
| 97 | + return |
| 98 | + else: |
| 99 | + await okk.edit( |
| 100 | + changelog_str, |
| 101 | + buttons=Button.inline("Update Now", data="updatenow"), |
| 102 | + parse_mode="html", |
| 103 | + ) |
| 104 | + |
| 105 | + |
| 106 | +@callback(re.compile("pasta-(.*)")) |
| 107 | +@owner |
| 108 | +async def _(e): |
| 109 | + ok = e.data_match.group(1) |
| 110 | + hmm = open(ok) |
| 111 | + hmmm = hmm.read() |
| 112 | + hmm.close() |
| 113 | + key = ( |
| 114 | + requests.post("https://nekobin.com/api/documents", json={"content": hmmm}) |
| 115 | + .json() |
| 116 | + .get("result") |
| 117 | + .get("key") |
| 118 | + ) |
| 119 | + await e.edit( |
| 120 | + f"Pasted to Nekobin\n 👉[Link](https://nekobin.com/{key})\n 👉[Raw Link](https://nekobin.com/raw/{key})", |
| 121 | + buttons=Button.switch_inline( |
| 122 | + "Search Again..?", |
| 123 | + query="send ", |
| 124 | + same_peer=True, |
| 125 | + ), |
| 126 | + link_preview=False, |
| 127 | + ) |
| 128 | + |
| 129 | + |
25 | 130 | @callback("authorise") |
26 | 131 | @owner |
27 | 132 | async def _(e): |
@@ -54,7 +159,7 @@ async def _(e): |
54 | 159 | + "1. Open Google Drive App.\n" |
55 | 160 | + "2. Create Folder.\n" |
56 | 161 | + "3. Make that folder public.\n" |
57 | | - + "4. Copy link of that folder." |
| 162 | + + "4. Copy link of that folder.\n" |
58 | 163 | + "5. Send all characters which is after id= .", |
59 | 164 | ) |
60 | 165 | async with ultroid_bot.asst.conversation(e.sender_id) as conv: |
@@ -492,7 +597,7 @@ async def media(event): |
492 | 597 | try: |
493 | 598 | x = upl(media) |
494 | 599 | url = f"https://telegra.ph/{x[0]}" |
495 | | - os.remove(media) |
| 600 | + remove(media) |
496 | 601 | except BaseException: |
497 | 602 | return await conv.send_message( |
498 | 603 | "Terminated.", |
@@ -561,6 +666,11 @@ async def name(event): |
561 | 666 | buttons=get_back_button("pmcstm"), |
562 | 667 | ) |
563 | 668 | else: |
| 669 | + if len(themssg) > 4090: |
| 670 | + return await conv.send_message( |
| 671 | + "Message too long!\nGive a shorter message please!!", |
| 672 | + buttons=get_back_button("pmcstm"), |
| 673 | + ) |
564 | 674 | await setit(event, var, themssg) |
565 | 675 | await conv.send_message( |
566 | 676 | "{} changed to {}\n\nAfter Setting All Things Do restart".format( |
@@ -633,7 +743,7 @@ async def media(event): |
633 | 743 | try: |
634 | 744 | x = upl(media) |
635 | 745 | url = f"https://telegra.ph/{x[0]}" |
636 | | - os.remove(media) |
| 746 | + remove(media) |
637 | 747 | except BaseException: |
638 | 748 | return await conv.send_message( |
639 | 749 | "Terminated.", |
@@ -783,7 +893,7 @@ async def chbot(event): |
783 | 893 | buttons=[ |
784 | 894 | [Button.inline("Cʜᴀᴛ Bᴏᴛ Oɴ", data="onchbot")], |
785 | 895 | [Button.inline("Cʜᴀᴛ Bᴏᴛ Oғғ", data="ofchbot")], |
786 | | - [Button.inline("Bᴏᴛ Wᴇʟᴄᴏɴᴇ", data="bwel")], |
| 896 | + [Button.inline("Bᴏᴛ Wᴇʟᴄᴏᴍᴇ", data="bwel")], |
787 | 897 | [Button.inline("« Bᴀᴄᴋ", data="setter")], |
788 | 898 | ], |
789 | 899 | link_preview=False, |
|
0 commit comments