Skip to content

Commit

Permalink
Merge branch 'TgCatUB:beta' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxGuy312 authored Sep 29, 2023
2 parents f784c47 + 86cc94b commit 59ed6d2
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 113 deletions.
2 changes: 1 addition & 1 deletion docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* [📕 Config Vars](installation/variables/config-vars.md)
* [📕 Database Vars](installation/variables/database-vars.md)
* [📚 Guide](installation/guide/README.md)
* [📕 Chromium and Chrome driver Setup](installation/guide/chromium-and-chrome-driver-setup.md)
* [📕 Chromium/Chrome Setup](installation/guide/chromium-or-chrome-setup.md)

## Tutorials

Expand Down
5 changes: 1 addition & 4 deletions docs/installation/guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@

### _Some additonal set-up guides that might be helpful with your hosting:_



<table data-view="cards"><thead><tr><th></th><th data-type="select" data-multiple></th><th data-hidden data-card-cover data-type="files"></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><em><mark style="color:blue;"><strong>Install Chromium &#x26; Chrome driver</strong></mark></em></td><td></td><td><a href="../../.gitbook/assets/chromium_pokemon.jpg">chromium_pokemon.jpg</a></td><td><a href="chromium-and-chrome-driver-setup.md">chromium-and-chrome-driver-setup.md</a></td></tr></tbody></table>

<table data-view="cards"><thead><tr><th></th><th data-type="select" data-multiple></th><th data-hidden data-card-cover data-type="files"></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><em><mark style="color:blue;"><strong>Install Chromium or Google-Chrome</strong></mark></em></td><td></td><td><a href="../../.gitbook/assets/chromium_pokemon.jpg">chromium_pokemon.jpg</a></td><td><a href="chromium-or-chrome-setup.md">chromium-or-chrome-setup.md</a></td></tr></tbody></table>
98 changes: 0 additions & 98 deletions docs/installation/guide/chromium-and-chrome-driver-setup.md

This file was deleted.

101 changes: 101 additions & 0 deletions docs/installation/guide/chromium-or-chrome-setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# 📕 Chromium/Chrome Setup

{% hint style="info" %}
This setup is only required for the users who followed the SELF-HOST method for deploying Cat Userbot.

This is not required for Docker or Docker-Compose (recommended method) methods.
{% endhint %}

**Why should you do this setup?**

**Chromium / Chrome** binary is a mandatory requirement for many awesome plugins and commands like <mark style="color:green;">AI tools</mark>, <mark style="color:green;">Screenshot</mark>, <mark style="color:green;">Rayso</mark>, <mark style="color:green;">Rayso based logs</mark>, <mark style="color:green;">Carbon</mark>, etc.

Here we will show how to setup this for <mark style="color:red;">Debian</mark>, <mark style="color:orange;">Ubuntu</mark>, <mark style="color:blue;">Arch</mark>, <mark style="color:purple;">Fedora</mark> and their derivatives.

{% tabs %}
{% tab title="Chromium" %}
{% code title="For Debian" overflow="wrap" %}
```batch
sudo apt install chromium
```
{% endcode %}

{% code title="For Ubuntu" overflow="wrap" %}
```batch
sudo apt install chromium-browser
```
{% endcode %}

{% code title="For Arch" overflow="wrap" %}
```batch
sudo pacman -S chromium
```
{% endcode %}

{% code title="For Fedora" overflow="wrap" %}
```batch
sudo dnf install chromium
```
{% endcode %}

{% code title="Go to catuserbot directory and open the config.py " overflow="wrap" %}
```batch
nano config.py
```
{% endcode %}

{% code title="Add this one var in your config" overflow="wrap" %}
```batch
CHROME_BIN = "/usr/bin/chromium"
```
{% endcode %}

Now to save use <mark style="color:red;">Ctrl+O</mark> and press <mark style="color:red;">Enter</mark> , then use <mark style="color:red;">Ctrl+X</mark> to exit.
{% endtab %}

{% tab title="Chrome" %}
{% code title="For Debian and Ubuntu" %}
```batch
sudo wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - && \
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" | sudo tee /etc/apt/sources.list.d/google.list && \
sudo apt-get update -y && \
sudo apt-get install -y google-chrome-stable xvfb libxi6 libgconf-2-4 default-jdk && \
sudo chmod +x /usr/bin/google-chrome
```
{% endcode %}

{% code title="For Arch, you can use any AUR helper, here we" overflow="wrap" %}
```batch
sudo yay -S google-chrome
```
{% endcode %}

{% code title="For Fedora" overflow="wrap" %}
```batch
sudo dnf install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
```
{% endcode %}

{% code title="Go to catuserbot directory and open the config.py" overflow="wrap" %}
```batch
nano config.py
```
{% endcode %}

{% code title="Add this one var in your config" overflow="wrap" %}
```batch
CHROME_BIN = "/usr/bin/google-chrome"
```
{% endcode %}

Now to save use <mark style="color:red;">Ctrl+O</mark> and press <mark style="color:red;">Enter</mark> , then use <mark style="color:red;">Ctrl+X</mark> to exit.
{% endtab %}
{% endtabs %}

{% content-ref url="./" %}
[.](./)
{% endcontent-ref %}

{% content-ref url="../hosting/self-host.md" %}
[self-host.md](../hosting/self-host.md)
{% endcontent-ref %}
2 changes: 1 addition & 1 deletion docs/installation/hosting/self-host.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ git clone https://github.com/TgCatUB/catuserbot && cd catuserbot && mv exampleco

### _**Setup Chromium & its driver**_ <a href="#setup-chromium" id="setup-chromium"></a>

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th data-type="select" data-multiple></th><th data-hidden data-card-cover data-type="files"></th><th data-hidden data-card-target data-type="content-ref"></th><th data-hidden data-type="content-ref"></th></tr></thead><tbody><tr><td><em><mark style="color:blue;"><strong>Install Chromium &#x26; Chrome driver</strong></mark></em></td><td></td><td><a href="../../.gitbook/assets/chromium_pokemon.jpg">chromium_pokemon.jpg</a></td><td><a href="../guide/chromium-and-chrome-driver-setup.md">chromium-and-chrome-driver-setup.md</a></td><td><a href="../guide/chromium-and-chrome-driver-setup.md#ubuntu">#ubuntu</a></td></tr></tbody></table>
<table data-card-size="large" data-view="cards"><thead><tr><th></th><th data-type="select" data-multiple></th><th data-hidden data-card-cover data-type="files"></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><em><mark style="color:blue;"><strong>Install Chromium or Google-Chrome</strong></mark></em></td><td></td><td><a href="../../.gitbook/assets/chromium_pokemon.jpg">chromium_pokemon.jpg</a></td><td><a href="../guide/chromium-or-chrome-setup.md#chromium">#chromium</a></td></tr></tbody></table>

### _**Edit the config.py with your config values**_ <a href="#edit-config" id="edit-config"></a>

Expand Down
51 changes: 42 additions & 9 deletions userbot/plugins/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
from telethon.utils import get_extension

from ..Config import Config
from ..helpers.utils import _catutils
from . import catub, edit_delete, edit_or_reply, progress
from .upload import UPLOAD_, upload

thumb_image_path = os.path.join(Config.TMP_DOWNLOAD_DIRECTORY, "thumb_image.jpg")
plugin_category = "misc"
Expand All @@ -36,6 +38,13 @@ def zipdir(dirName):
return filePaths


async def upload_unpacked(event, text_event, path):
await edit_or_reply(text_event, "`Uploading file .....`")
UPLOAD_.uploaded = 0
await upload(path, event, text_event)
await _catutils.runcmd(f"rm -rf {path}")


@catub.cat_cmd(
pattern="zip(?:\s|$)([\s\S]*)",
command=("zip", plugin_category),
Expand Down Expand Up @@ -125,15 +134,22 @@ async def tar_file(event):
info={
"header": "To unpack the given zip file",
"description": "Reply to a zip file or provide zip file path with command to unzip the given file",
"flags": {"u": "Upload files after unpacking."},
"usage": [
"{tr}unzip <reply/file path>",
"{tr}unzip -u <reply/file path>",
],
},
)
async def zip_file(event): # sourcery no-metrics
# sourcery skip: low-code-quality
"To unpack the zip file"
if input_str := event.pattern_match.group(1):
upload_flag = False
input_str = event.pattern_match.group(1)
if input_str and "-u" in input_str:
upload_flag = True
input_str = input_str.replace("-u", "").strip()
if input_str:
path = Path(input_str)
if os.path.exists(path):
start = datetime.now()
Expand All @@ -151,9 +167,12 @@ async def zip_file(event): # sourcery no-metrics
zip_ref.extractall(destination)
end = datetime.now()
ms = (end - start).seconds
await mone.edit(
f"unzipped and stored to `{destination}` \n**Time Taken :** `{ms} seconds`"
await edit_or_reply(
mone,
f"unzipped and stored to `{destination}` \n**Time Taken :** `{ms} seconds`",
)
if upload_flag:
await upload_unpacked(event, mone, destination)
else:
await edit_delete(event, f"I can't find that path `{input_str}`", 10)
elif event.reply_to_msg_id:
Expand Down Expand Up @@ -183,7 +202,7 @@ async def zip_file(event): # sourcery no-metrics
dl.close()
except Exception as e:
return await edit_delete(mone, f"**Error:**\n__{e}__")
await mone.edit("`Download finished Unpacking now`")
await edit_or_reply(mone, "`Download finished Unpacking now`")
destination = os.path.join(
Config.TMP_DOWNLOAD_DIRECTORY,
os.path.splitext(os.path.basename(filename))[0],
Expand All @@ -192,13 +211,16 @@ async def zip_file(event): # sourcery no-metrics
zip_ref.extractall(destination)
end = datetime.now()
ms = (end - start).seconds
await mone.edit(
f"unzipped and stored to `{destination}` \n**Time Taken :** `{ms} seconds`"
await edit_or_reply(
mone,
f"unzipped and stored to `{destination}` \n**Time Taken :** `{ms} seconds`",
)
os.remove(filename)
if upload_flag:
await upload_unpacked(event, mone, destination)
else:
await edit_delete(
mone,
event,
"`Either reply to the zipfile or provide path of zip file along with command`",
)

Expand All @@ -209,15 +231,22 @@ async def zip_file(event): # sourcery no-metrics
info={
"header": "To unpack the given tar file",
"description": "Reply to a tar file or provide tar file path with command to unpack the given tar file",
"flags": {"u": "Upload files after unpacking."},
"usage": [
"{tr}untar <reply/file path>",
"{tr}untar -u <reply/file path>",
],
},
)
async def untar_file(event): # sourcery no-metrics
# sourcery skip: low-code-quality
"To unpack the tar file"
if input_str := event.pattern_match.group(1):
upload_flag = False
input_str = event.pattern_match.group(1)
if input_str and "-u" in input_str:
upload_flag = True
input_str = input_str.replace("-u", "").strip()
if input_str:
path = Path(input_str)
if os.path.exists(path):
start = datetime.now()
Expand All @@ -242,6 +271,8 @@ async def untar_file(event): # sourcery no-metrics
f"**Time Taken :** `{ms} seconds`\
\nUnpacked the input path `{input_str}` and stored to `{destination}`"
)
if upload_flag:
await upload_unpacked(event, mone, destination)
else:
await edit_delete(event, f"I can't find that path `{input_str}`", 10)
elif event.reply_to_msg_id:
Expand Down Expand Up @@ -287,8 +318,10 @@ async def untar_file(event): # sourcery no-metrics
\nUnpacked the replied file and stored to `{destination}`"
)
os.remove(filename)
if upload_flag:
await upload_unpacked(event, mone, destination)
else:
await edit_delete(
mone,
event,
"`Either reply to the tarfile or provide path of tarfile along with command`",
)

0 comments on commit 59ed6d2

Please sign in to comment.