Skip to content

Commit ddc3db1

Browse files
author
Swonit
committed
PyrogramBot
0 parents  commit ddc3db1

25 files changed

Lines changed: 1205 additions & 0 deletions

.gitignore

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
token.py
2+
*.raw
3+
images/
4+
# Byte-compiled / optimized / DLL files
5+
__pycache__/
6+
*.py[cod]
7+
*.png
8+
*.mp4
9+
*.webm
10+
*$py.class
11+
*.mp3
12+
.
13+
# C extensions
14+
*.so
15+
config.py
16+
# Distribution / packaging
17+
.Python
18+
build/
19+
develop-eggs/
20+
dist/
21+
downloads/
22+
eggs/
23+
.eggs/
24+
lib/
25+
lib64/
26+
parts/
27+
sdist/
28+
var/
29+
wheels/
30+
pip-wheel-metadata/
31+
share/python-wheels/
32+
*.egg-info/
33+
.installed.cfg
34+
*.egg
35+
MANIFEST
36+
37+
# PyInstaller
38+
# Usually these files are written by a python script from a template
39+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
40+
*.manifest
41+
*.spec
42+
43+
# Installer logs
44+
pip-log.txt
45+
pip-delete-this-directory.txt
46+
47+
# Unit test / coverage reports
48+
htmlcov/
49+
.tox/
50+
.nox/
51+
.coverage
52+
.coverage.*
53+
.cache
54+
nosetests.xml
55+
coverage.xml
56+
*.cover
57+
*.py,cover
58+
.hypothesis/
59+
.pytest_cache/
60+
61+
# Translations
62+
*.mo
63+
*.pot
64+
65+
# Django stuff:
66+
*.log
67+
local_settings.py
68+
db.sqlite3
69+
db.sqlite3-journal
70+
71+
# Flask stuff:
72+
instance/
73+
.webassets-cache
74+
75+
# Scrapy stuff:
76+
.scrapy
77+
78+
# Sphinx documentation
79+
docs/_build/
80+
81+
# PyBuilder
82+
target/
83+
84+
# Jupyter Notebook
85+
.ipynb_checkpoints
86+
87+
# IPython
88+
profile_default/
89+
ipython_config.py
90+
91+
# pyenv
92+
.python-version
93+
94+
# pipenv
95+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
96+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
97+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
98+
# install all needed dependencies.
99+
#Pipfile.lock
100+
101+
# celery beat schedule file
102+
celerybeat-schedule
103+
104+
# SageMath parsed files
105+
*.sage.py
106+
107+
# Environments
108+
.env
109+
.venv
110+
env/
111+
venv/
112+
ENV/
113+
env.bak/
114+
venv.bak/
115+
116+
# Spyder project settings
117+
.spyderproject
118+
.spyproject
119+
120+
# Rope project settings
121+
.ropeproject
122+
123+
# mkdocs documentation
124+
/site
125+
126+
# mypy
127+
.mypy_cache/
128+
.dmypy.json
129+
dmypy.json
130+
131+
# Pyre type checker
132+
.pyre/
133+
*.ini
134+
*.pyc
135+
*.session
136+
*.session-journal
137+
138+
# vim
139+
[._]*.sw[a-p]
140+
141+
#others
142+
neofetch.txt
143+
error.log
144+
permissions.json
145+
.vscode

Dockerfile.sample

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM ubuntu:latest
2+
3+
WORKDIR /usr/src/app
4+
RUN chmod 777 /usr/src/app
5+
RUN apt-get -qq update
6+
RUN DEBIAN_FRONTEND="noninteractive" apt-get -qq install python3 python3-pip software-properties-common
7+
8+
#Updating Libraries
9+
RUN pip3 install -U pip
10+
COPY requirements.txt .
11+
RUN pip3 install --no-cache-dir -U -r requirements.txt
12+
13+
#Copying All Source
14+
COPY . .
15+
16+
#Starting Bot
17+
CMD ["python3", "-m", "PyrogramBot"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 MaskedVirus | swatv3nub
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
worker: python3 -m PyrogramBot

PyrogramBot/__init__.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import logging
2+
import time
3+
import os
4+
import sys
5+
from pyrogram import Client, errors
6+
from .config import API_ID, API_HASH, BOT_TOKEN
7+
#from .config import MONGO_DB_URI
8+
9+
# Adding Mongo Example
10+
11+
# from motor.motor_asyncio import AsyncIOMotorClient as MongoClient
12+
13+
StartTime = time.time()
14+
logging.basicConfig(level=logging.INFO)
15+
16+
if sys.version_info[0] < 3 or sys.version_info[1] < 8:
17+
LOGGER.error(
18+
(
19+
"You MUST have a Python Version of at least 3.8!\n"
20+
"Multiple features depend on this. Aborting The Deploy!"
21+
)
22+
)
23+
quit(1)
24+
25+
app = Client("pyrogrambot", api_id=API_ID, api_hash=API_HASH, bot_token=BOT_TOKEN)
26+
27+
bot_start_time = time.time()
28+
29+
# mongodb = MongoClient(MONGO_DB_URI)
30+
# db = mongodb.pyrogrambot

PyrogramBot/__main__.py

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
from pyrogram import idle, Client
2+
3+
from pyrogrambot import app, filters
4+
from pyrogrambot.utils.misc import count_modules
5+
6+
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
7+
8+
import importlib
9+
import re
10+
11+
#Bot info
12+
13+
async def get_info(app):
14+
global BOT_ID, BOT_NAME, BOT_USERNAME, BOT_DC_ID
15+
getme = await app.get_me()
16+
BOT_ID = getme.id
17+
18+
if getme.last_name:
19+
BOT_NAME = getme.first_name + " " + getme.last_name
20+
else:
21+
BOT_NAME = getme.first_name
22+
BOT_USERNAME = getme.username
23+
BOT_DC_ID = getme.dc_id
24+
25+
#Help [Taken From WBB]
26+
27+
HELPABLE = {}
28+
29+
30+
async def start_bot():
31+
await app.start()
32+
await get_info(app)
33+
34+
for module in ALL_MODULES:
35+
imported_module = importlib.import_module("PyrogramBot.modules." + module)
36+
if (
37+
hasattr(imported_module, "__MODULE__")
38+
and imported_module.__MODULE__
39+
):
40+
imported_module.__MODULE__ = imported_module.__MODULE__
41+
if (
42+
hasattr(imported_module, "__HELP__")
43+
and imported_module.__HELP__
44+
):
45+
HELPABLE[
46+
imported_module.__MODULE__.lower()
47+
] = imported_module
48+
49+
bot_modules = ""
50+
j = 1
51+
for i in ALL_MODULES:
52+
if j == 4:
53+
bot_modules += "|{:<15}|\n".format(i)
54+
j = 0
55+
else:
56+
bot_modules += "|{:<15}".format(i)
57+
j += 1
58+
print(">>------------|•|-----------<<")
59+
print(f">>------|• {BOT_NAME} •|-----<<")
60+
print(">>------------|•|-----------<<")
61+
print(bot_modules)
62+
print("Bot is Up, Game ON!!")
63+
await idle()
64+
65+
66+
67+
68+
@app.on_message(filters.command("help"))
69+
async def help_command(_, message):
70+
if message.chat.type != "private":
71+
if len(message.command) >= 2 and message.command[1] == "help":
72+
text, keyboard = await help_parser(message)
73+
await message.reply(
74+
text, reply_markup=keyboard, disable_web_page_preview=True
75+
)
76+
return
77+
keyboard = InlineKeyboardMarkup(
78+
[
79+
[
80+
InlineKeyboardButton(
81+
text="Help",
82+
url=f"t.me/{BOT_USERNAME}?start=help",
83+
)
84+
]
85+
]
86+
)
87+
await message.reply("Contact me in PM.", reply_markup=keyboard)
88+
return
89+
text, keyboard = await help_parser(message)
90+
await message.reply_text(text, reply_markup=keyboard)
91+
92+
93+
async def help_parser(message, keyboard=None):
94+
if not keyboard:
95+
keyboard = InlineKeyboardMarkup(count_modules(0, HELPABLE, "help"))
96+
return (
97+
"Hi {first_name}, I am a bot".format(
98+
first_name=message.from_user.first_name,
99+
),
100+
keyboard,
101+
)
102+
103+
104+
@app.on_callback_query(filters.regex(r"help_(.*?)"))
105+
async def help_button(client, query):
106+
mod_match = re.match(r"help_module\((.+?)\)", query.data)
107+
prev_match = re.match(r"help_prev\((.+?)\)", query.data)
108+
next_match = re.match(r"help_next\((.+?)\)", query.data)
109+
back_match = re.match(r"help_back", query.data)
110+
create_match = re.match(r"help_create", query.data)
111+
112+
if mod_match:
113+
module = mod_match.group(1)
114+
text = (
115+
"{} **{}**:\n".format(
116+
"Here is the help for", HELPABLE[module].__MODULE__
117+
)
118+
+ HELPABLE[module].__HELP__
119+
)
120+
121+
await query.message.edit(
122+
text=text,
123+
reply_markup=InlineKeyboardMarkup(
124+
[[InlineKeyboardButton("back", callback_data="help_back")]]
125+
),
126+
disable_web_page_preview=True,
127+
)
128+
129+
elif prev_match:
130+
curr_page = int(prev_match.group(1))
131+
await query.message.edit(
132+
text="Hi {first_name}. I am bot".format(
133+
first_name=query.from_user.first_name,
134+
),
135+
reply_markup=InlineKeyboardMarkup(
136+
count_modules(curr_page - 1, HELPABLE, "help")
137+
),
138+
disable_web_page_preview=True,
139+
)
140+
141+
elif next_match:
142+
next_page = int(next_match.group(1))
143+
await query.message.edit(
144+
text="Hi {first_name}. I am a bot".format(
145+
first_name=query.from_user.first_name,
146+
),
147+
reply_markup=InlineKeyboardMarkup(
148+
count_modules(next_page + 1, HELPABLE, "help")
149+
),
150+
disable_web_page_preview=True,
151+
)
152+
153+
elif back_match:
154+
await query.message.edit(
155+
text="Hi {first_name}. I am a bot".format(
156+
first_name=query.from_user.first_name,
157+
),
158+
reply_markup=InlineKeyboardMarkup(
159+
count_modules(0, HELPABLE, "help")
160+
),
161+
disable_web_page_preview=True,
162+
)
163+
164+
elif create_match:
165+
text, keyboard = await help_parser(query)
166+
await query.message.edit(
167+
text=text, reply_markup=keyboard, disable_web_page_preview=True
168+
)
169+
170+
return await client.answer_callback_query(query.id)
171+
172+
173+
174+
if __name__ == "__main__":
175+
app.start()
176+
idle()

0 commit comments

Comments
 (0)