Skip to content
This repository was archived by the owner on May 30, 2023. It is now read-only.

Commit def1b0d

Browse files
author
Divkix
committed
Initial Commit
0 parents  commit def1b0d

17 files changed

+459
-0
lines changed

.dockerignore

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Python Dockerignore
2+
__pycache__
3+
*.pyc
4+
*.pyo
5+
*.pyd
6+
.Python
7+
env
8+
pip-log.txt
9+
pip-delete-this-directory.txt
10+
.tox
11+
.coverage
12+
.coverage.*
13+
.cache
14+
nosetests.xml
15+
coverage.xml
16+
*.cover
17+
*.log

.gitignore

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

.gitpod.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
tasks:
2+
- before: export PIP_USER=false
3+
command: >
4+
git pull &&
5+
make dev-install

.pre-commit-config.yaml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v3.4.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: debug-statements
8+
- id: requirements-txt-fixer
9+
- id: check-merge-conflict
10+
11+
- repo: https://github.com/psf/black
12+
rev: 20.8b1
13+
hooks:
14+
- id: black
15+
language_version: python3
16+
17+
- repo: https://github.com/asottile/add-trailing-comma
18+
rev: v2.1.0
19+
hooks:
20+
- id: add-trailing-comma
21+
args: [--py36-plus]
22+
23+
- repo: https://github.com/asottile/pyupgrade
24+
rev: v2.10.0
25+
hooks:
26+
- id: pyupgrade
27+
args: [--py36-plus]
28+
29+
- repo: https://github.com/pycqa/isort
30+
rev: 5.7.0
31+
hooks:
32+
- id: isort
33+
args: ["--profile", "black", "--filter-files"]

Dockerfile

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM python:3.9.1-slim-buster
2+
3+
# Don't use cached python packages
4+
ENV PIP_NO_CACHE_DIR 1
5+
6+
# Add new fast source
7+
RUN sed -i.bak 's/us-west-2\.ec2\.//' /etc/apt/sources.list
8+
9+
# Installing Required Packages
10+
RUN apt update && \
11+
apt upgrade -y && \
12+
apt install --no-install-recommends -y \
13+
bash \
14+
python3-dev \
15+
python3-lxml \
16+
gcc \
17+
clang \
18+
make \
19+
git \
20+
neofetch
21+
22+
# Enter Workplace
23+
WORKDIR /app/
24+
25+
# Copy folder
26+
COPY . .
27+
28+
# Install dependencies
29+
RUN make install
30+
31+
# Run the bots
32+
CMD ["make", "run"]

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Divkix
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.

Makefile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
test:
2+
@pre-commit run --all-files
3+
4+
install:
5+
@python3 -m pip install --upgrade pip setuptools
6+
@python3 -m pip install --upgrade -r requirements.txt
7+
8+
dev-install:
9+
@python3 -m pip install --upgrade pip setuptools
10+
@python3 -m pip install --upgrade -r requirements-dev.txt
11+
@sleep 5
12+
@pre-commit
13+
14+
run:
15+
@python3 -m pyrobot

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# PyroBot Template
2+
3+
It's just my personal template for required to run all my telegram bots.
4+
5+
[![Join us on Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white)](https://t.me/DivideProjects)

pyrobot/__init__.py

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"""Initialise the directory."""
2+
3+
from datetime import datetime
4+
from logging import INFO, WARNING, FileHandler, StreamHandler, basicConfig, getLogger
5+
from os import environ, mkdir, path
6+
from sys import exit as sysexit
7+
from sys import stdout, version_info
8+
9+
LOG_DATETIME = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
10+
LOGDIR = f"{__name__}/logs"
11+
12+
# Make Logs directory if it does not exixts
13+
if not path.isdir(LOGDIR):
14+
mkdir(LOGDIR)
15+
16+
LOGFILE = f"{LOGDIR}/{__name__}_{LOG_DATETIME}.txt"
17+
18+
file_handler = FileHandler(filename=LOGFILE)
19+
stdout_handler = StreamHandler(stdout)
20+
21+
basicConfig(
22+
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
23+
level=INFO,
24+
handlers=[file_handler, stdout_handler],
25+
)
26+
27+
getLogger("pyrogram").setLevel(WARNING)
28+
LOGGER = getLogger(__name__)
29+
30+
# if version < 3.6, stop bot.
31+
if version_info[0] < 3 or version_info[1] < 7:
32+
LOGGER.error(
33+
(
34+
"You MUST have a Python Version of at least 3.7!\n"
35+
"Multiple features depend on this. Bot quitting."
36+
),
37+
)
38+
sysexit(1) # Quit the Script
39+
40+
# the secret configuration specific things
41+
try:
42+
if environ.get("ENV"):
43+
from .vars import Config
44+
else:
45+
from .vars import Development as Config
46+
except BaseException as ef:
47+
LOGGER.error(ef) # Print Error
48+
sysexit(1)
49+
50+
51+
TOKEN = Config.TOKEN
52+
APP_ID = Config.APP_ID
53+
API_HASH = Config.API_HASH
54+
TOKEN = Config.TOKEN
55+
APP_ID = Config.APP_ID
56+
API_HASH = Config.API_HASH
57+
OWNER_ID = Config.OWNER_ID
58+
PREFIX_HANDLER = Config.PREFIX_HANDLER
59+
WORKERS = Config.WORKERS

pyrobot/__main__.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""Run the bot."""
2+
3+
from .bot_class import PyroBot
4+
5+
if __name__ == "__main__":
6+
PyroBot.run()

pyrobot/bot_class.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from os import makedirs, path
2+
3+
from pyrogram import Client
4+
5+
from . import API_HASH, APP_ID, LOGGER, MESSAGE_DUMP, NO_LOAD, TOKEN, WORKERS
6+
7+
# Check if MESSAGE_DUMP is correct
8+
if MESSAGE_DUMP == -100 or not str(MESSAGE_DUMP).startswith("-100"):
9+
raise Exception(
10+
"Please enter a vaild Supergroup ID, A Supergroup ID starts with -100",
11+
)
12+
13+
14+
class PyroBot(Client):
15+
"""Starts the Pyrogram Client on the Bot Token when we do 'python3 -m alita'"""
16+
17+
def __init__(self):
18+
name = self.__class__.__name__.lower()
19+
20+
# Make a temporary direcory for storing session file
21+
SESSION_DIR = f"{name}/SESSION"
22+
if not path.isdir(SESSION_DIR):
23+
makedirs(SESSION_DIR)
24+
25+
super().__init__(
26+
name,
27+
plugins=dict(root=f"{name}/plugins"),
28+
workdir=SESSION_DIR,
29+
api_id=APP_ID,
30+
api_hash=API_HASH,
31+
bot_token=TOKEN,
32+
workers=WORKERS,
33+
)
34+
35+
async def start(self):
36+
"""Start the bot."""
37+
await super().start()
38+
LOGGER.info("Bot Started Successfully!")
39+
40+
async def stop(self):
41+
"""Stop the bot and send a message to MESSAGE_DUMP telling that the bot has stopped."""
42+
LOGGER.info("Uploading logs before stopping...!")
43+
await super().stop()
44+
LOGGER.info("Bot Stopped.\nkthxbye!")

pyrobot/plugins/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Initialise the directory."""

0 commit comments

Comments
 (0)