Bladeren bron

Heroku Support (#60)

* Heroku Support

* Update README.md

* a

Co-authored-by: Akshay Rajput <thehamkercat@gmail.com>
Avijneyam - the unknowable 5 jaren geleden
bovenliggende
commit
39911574fc
6 gewijzigde bestanden met toevoegingen van 151 en 28 verwijderingen
  1. 18 0
      README.md
  2. 67 0
      app.json
  3. 2 0
      heroku.yml
  4. 30 13
      sample_config.py
  5. 13 0
      str_gen.py
  6. 21 15
      wbb/__init__.py

+ 18 - 0
README.md

@@ -26,6 +26,8 @@
 - Python >= 3.7
 - A [Telegram API key](https://docs.pyrogram.org/intro/setup#api-keys).
 - A [Telegram bot token](https://t.me/botfather).
+<!-- How to get MongoDB -->
+- A [MongoDB](https://telegra.ph/How-To-get-Mongodb-URI-04-06)
 
 
 ## Install Locally Or On A VPS
@@ -46,6 +48,22 @@ Edit **config.py** with your own values
 $ python3 -m wbb
 ```
 
+# Run On Heroku
+
+## Generating Pyrogram Session For Heroku
+
+```
+$ git clone https://github.com/TheHamkerCat/WilliamButcherBot
+
+$ cd WilliamButcherBot
+
+$ pip3 install -U -r requirements.txt
+
+$ python3 str_gen.py
+```
+
+[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/thehamkercat/WilliamButcherBot/)
+
 ## Features 
 
 * Group Management

+ 67 - 0
app.json

@@ -0,0 +1,67 @@
+{
+    "name": "WilliamButcherBot",
+    "description": "Telegram Group Management Bot Written In Python Using Pyrogram.",
+    "repository": "https://github.com/thehamkercat/WilliamButcherBot",
+    "logo": "https://upload.wikimedia.org/wikipedia/commons/c/c3/Python-logo-notext.svg",
+    "keywords": [
+    "python3",
+    "telegram",
+    "bot",
+    "youtube",
+    "telegram-bot",
+    "pyrogram"
+    ],
+    "stack": "container",
+    "env": {
+        "BOT_TOKEN": {
+            "description": "Obtain a Telegram bot token by contacting @BotFather",
+            "required": true
+        },
+        "API_ID": {
+            "description": "API_ID of your Telegram Account my.telegram.org/apps",
+            "required": true
+        },
+        "API_HASH": {
+            "description": "API_HASH of your Telegram Account my.telegram.org/apps",
+            "required": true
+        },
+        "SESSION_STRING": {
+            "description": "Need for Userbot Module So u can execute .sh & .l cmd",
+            "required": false
+        },
+        "MAIN_CHATS": {
+            "description": "These are the chats where main functions of bot will work, like music downloading etc.",
+            "required": true
+        },
+        "SUDO_USERS_ID": {
+            "description": "Sudo users have full access to everythin, don't trust anyone... ex:- 123456 654311 123456",
+            "required": true
+        },
+        "LOG_GROUP_ID": {
+            "description": "For logs channel to note down important bot level events, recommend to make this public. ex: '-123456'",
+            "required": true
+        },
+        "GBAN_LOG_GROUP_ID": {
+            "description": "gban logs. ex: '-123456'",
+            "required": true
+        },
+        "FERNET_ENCRYPTION_KEY": {
+            "description": "Don't change this value",
+            "value": "iKMq0WZMnJKjMQxZWKtv-cplMuF_LoyshXj0XbTGGWM=",
+            "required": true
+        },
+        "WELCOME_DELAY_KICK_SEC": {
+            "value": "300",
+            "required": true
+        },
+        "MONGO_DB_URI": {
+            "description": "Get From Here. https://telegra.ph/How-To-get-Mongodb-URI-04-06",
+            "required": true
+        },
+        "ARQ_API_BASE_URL": {
+            "description": "For Music Downloading And Many More Things... Don't change this value",
+            "value": "https://thearq.tech",
+            "required": true
+        }
+    }
+}

+ 2 - 0
heroku.yml

@@ -1,3 +1,5 @@
 build:
   docker:
     worker: Dockerfile
+run:
+   worker: python3 -m wbb

+ 30 - 13
sample_config.py

@@ -1,15 +1,32 @@
-BOT_TOKEN = "1455:AAE4qFS3nF-0Tn"
-API_ID = 69
-API_HASH = "e46b6c854d2bf580"
-PHONE_NUMBER = "+910000000000" # Need for Helper Userbot
-MAIN_CHATS = [-1001485393652]  # NOTE These are the chats where main functions of bot will work, like music downloading etc.
-SUDO_USERS_ID = [51635132416, 1342121354245, 23452465243] # Sudo users have full access to everythin, don't trust anyone
-LOG_GROUP_ID = -1001337393587
-GBAN_LOG_GROUP_ID = -1001401678112
-FERNET_ENCRYPTION_KEY = "iKMq0WZMnJKjMQxZWKtv-cplMuF_LoyshXj0XbTGGWM=" # Leave this as it is
-WELCOME_DELAY_KICK_SEC = 300
-MONGO_DB_URI = "mongodb+srv://username:password@cluster0.ksiis.mongodb.net/YourDataBaseName?retryWrites=true&w=majority"
+HEROKU = True  # NOTE Make it false if you're not deploying on heroku.
 
+if HEROKU:
+    from os import environ
+    BOT_TOKEN = environ.get("BOT_TOKEN", None)
+    API_ID = int(environ.get("API_ID", 6))
+    API_HASH = environ.get("API_HASH", "eb06d4abfb49dc3eeb1aeb98ae0f581e")
+    SESSION_STRING = environ.get("SESSION_STRING", None)
+    MAIN_CHATS = int(environ.get("GBAN_LOG_GROUP_ID", None))
+    SUDO_USERS_ID = list(int(x) for x in environ.get("SUDO_USERS_ID", "").split())
+    LOG_GROUP_ID = int(environ.get("LOG_GROUP_ID", None))
+    GBAN_LOG_GROUP_ID = int(environ.get("MAIN_CHATS", None))
+    FERNET_ENCRYPTION_KEY = environ.get("FERNET_ENCRYPTION_KEY", None)
+    WELCOME_DELAY_KICK_SEC = int(environ.get("WELCOME_DELAY_KICK_SEC", None))
+    MONGO_DB_URI = environ.get("MONGO_DB_URI", None)
+    ARQ_API_BASE_URL = environ.get("ARQ_API_BASE_URL", None)
 
-# NOTE Don't make changes below this line
-ARQ_API_BASE_URL = "http://thearq.tech"
+if not HEROKU:
+    BOT_TOKEN = "467677575:YZfaakjwd545dfg-N6JStihhuw5gQeZHntc"
+    API_ID = 123456
+    API_HASH = "dfxcgs5s12hdcxfgdfz"
+    PHONE_NUMBER = "+919425965543" # Need for Helper Userbot
+    MAIN_CHATS = [-100125431255]  # NOTE These are the chats where main functions of bot will work, like music downloading etc.
+    SUDO_USERS_ID = [4543744343, 543214651351] # Sudo users have full access to everythin, don't trust anyone
+    LOG_GROUP_ID = -100125431255
+    GBAN_LOG_GROUP_ID = -100125431255
+    FERNET_ENCRYPTION_KEY = "iKMq0WZMnJKjMQxZWKtv-cplMuF_LoyshXj0XbTGGWM=" # Leave this as it is
+    WELCOME_DELAY_KICK_SEC = 300
+    MONGO_DB_URI = "mongodb+srv://username:password@cluster0.ksiis.mongodb.net/YourDataBaseName?retryWrites=true&w=majority"
+
+    # NOTE Don't make changes below this line
+    ARQ_API_BASE_URL = "http://thearq.tech"

+ 13 - 0
str_gen.py

@@ -0,0 +1,13 @@
+from pyrogram import Client as c
+
+API_ID = input("\nEnter Your API_ID:\n > ")
+API_HASH = input("\nEnter Your API_HASH:\n > ")
+
+print("\n\n Enter Phone number when asked.\n\n")
+
+i = c(":memory:", api_id=API_ID, api_hash=API_HASH)
+
+with i:
+    ss = i.export_session_string()
+    print("\nHERE IS YOUR STRING SESSION, COPY IT, DON'T SHARE!!\n")
+    print(f"\n{ss}\n")

+ 21 - 15
wbb/__init__.py

@@ -1,15 +1,16 @@
-from config import (
-    BOT_TOKEN, API_ID, API_HASH, SUDO_USERS_ID, PHONE_NUMBER,
-    LOG_GROUP_ID, FERNET_ENCRYPTION_KEY, MONGO_DB_URI,
-    WELCOME_DELAY_KICK_SEC, ARQ_API_BASE_URL as ARQ_API,
-    MAIN_CHATS, GBAN_LOG_GROUP_ID
-)
 from pyrogram import Client
 from pyromod import listen
 from motor.motor_asyncio import AsyncIOMotorClient as MongoClient
 from Python_ARQ import ARQ
+from os import path
 import time
 
+is_config = path.exists('config.py')
+if is_config:
+    from config import *
+else:
+    from sample_config import *
+
 SUDOERS = SUDO_USERS_ID
 MAIN_CHATS = MAIN_CHATS
 GBAN_LOG_GROUP_ID = GBAN_LOG_GROUP_ID
@@ -22,13 +23,19 @@ bot_start_time = time.time()
 mongo_client = MongoClient(MONGO_DB_URI)
 db = mongo_client.wbb
 
-
-app2 = Client(
-    "userbot",
-    phone_number=PHONE_NUMBER,
-    api_id=API_ID,
-    api_hash=API_HASH
-)
+if not HEROKU:
+    app2 = Client(
+        "userbot",
+        phone_number=PHONE_NUMBER,
+        api_id=API_ID,
+        api_hash=API_HASH
+    )
+else:
+    app2 = Client(
+        SESSION_STRING,
+        api_id=API_ID,
+        api_hash=API_HASH
+    )
 
 app = Client(
     "wbb",
@@ -37,7 +44,6 @@ app = Client(
     api_hash=API_HASH
 )
 
-
 BOT_ID = 0
 BOT_NAME = ""
 BOT_USERNAME = ""
@@ -79,4 +85,4 @@ app2.start()
 get_info(app, app2)
 SUDOERS.append(USERBOT_ID)
 # ARQ client
-arq = ARQ(ARQ_API)
+arq = ARQ(ARQ_API_BASE_URL)