Skip to content

Commit

Permalink
Release v0.4.0
Browse files Browse the repository at this point in the history
Took 48 minutes
  • Loading branch information
ShivangKakkar committed Mar 15, 2022
1 parent 68c6da5 commit f51c075
Show file tree
Hide file tree
Showing 16 changed files with 152 additions and 58 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ MANIFEST
*.egg-info

# Local
tests/
/test.py
/*.env
.log
/info.txt
examples/

# Docs
docs/_build
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version: 2
build:
os: ubuntu-20.04
tools:
python: "3.9"
python: "3.10"

sphinx:
configuration: docs/source/conf.py
Expand Down
5 changes: 3 additions & 2 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
sphinx~=4.4.0
pystark # needed for autodoc
sphinx-rtd-theme~=1.0.0
sphinx-copybutton~=0.4.0
sphinx-toolbox~=2.16.1
sphinx-copybutton>=0.5.0
sphinx-toolbox>=2.18.0
sphinx-notfound-page
3 changes: 2 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
"sphinx_toolbox.confval",
"sphinx.ext.napoleon",
"sphinx.ext.autodoc",
"notfound.extension",
# 'sphinx_search.extension',
# "sphinx_rtd_dark_mode",
# "notfound.extension",
# "sphinx_toolbox.github",
# "sphinx_toolbox.sidebar_links",
# "myst_parser"
]

rst_epilog = f"""
.. |version| replace:: {__version__}
.. |code_version| replace:: ``{__version__}``
Expand Down
12 changes: 12 additions & 0 deletions docs/source/meta/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ Latest Version - |code_version|

------------------

.. confval:: v0.4.0

- BugFixes and improvements in SQL helper functions.
- Make Database related dependencies optional and automated.
- Class Database instead of functions
- Rollback at exceptions
- Raw SQL for getting all rows as it usually depends on python class instead of data in table
- Raise TableNotFound if doesn't exist instead of returning None
- Rename `pystark.databases.postgres` to `pystark.databased.sql` in favour of other sql databases.
- Allow other type of Database URls
- Add attributes like `session`, `base`, `engine` to Database.

.. confval:: v0.3.0

- Additions
Expand Down
4 changes: 2 additions & 2 deletions docs/source/start/customization.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Customization
=========================
=============

There are a lot of customization options in PyStark to customize the behavior of your bot.

Expand All @@ -15,7 +15,7 @@ Change the default messages

PyStark comes with in-built plugins like ``start`` and ``help``. But what if you want to have different messages than the in-built ones? They are easily customizable.

After you have finished generating a boilerplate, you will see a file named ``data.py``. You can change it's values to change the default messages.
After you have finished generating a boilerplate, you will see a file named ``settings.py``. You can change it's values to change the default messages.

**Special Keywords** - You may want to mention user or bot in ``start`` or ``help`` messages. You can use special keywords to do that. They will be replaced at runtime and will be different for all users.

Expand Down
85 changes: 85 additions & 0 deletions frozen-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
alabaster==0.7.12
apeye==1.2.0
autodocsumm==0.2.7
Babel==2.9.1
beautifulsoup4==4.10.0
bleach==4.1.0
CacheControl==0.12.10
certifi==2021.10.8
charset-normalizer==2.0.12
click==8.0.4
colorama==0.4.4
consolekit==1.3.2
cssutils==2.4.0
Deprecated==1.2.13
deprecation==2.1.0
deprecation-alias==0.3.1
dict2css==0.3.0
docutils==0.16
domdf-python-tools==3.2.2.post1
greenlet==1.1.2
html5lib==1.1
idna==3.3
imagesize==1.3.0
importlib-metadata==4.11.3
Jinja2==3.0.3
keyring==23.5.0
lockfile==0.12.2
MarkupSafe==2.1.0
mistletoe==0.8.2
msgpack==1.0.3
natsort==8.1.0
nest-asyncio==1.5.4
packaging==21.3
pkginfo==1.8.2
platformdirs==2.5.1
psycopg2==2.9.3
pyaes==1.6.1
pyasn1==0.4.8
Pygments==2.11.2
pyparsing==3.0.7
Pyrogram==1.4.8
pyromod==1.5
PySocks==1.7.1
PyStark==0.1.82
python-dotenv==0.19.2
pytz==2021.3
pywin32-ctypes==0.2.0
readme-renderer==34.0
redis==4.1.4
requests==2.27.1
requests-toolbelt==0.9.1
rfc3986==2.0.0
rsa==4.8
ruamel.yaml==0.17.21
ruamel.yaml.clib==0.2.6
six==1.16.0
snowballstemmer==2.2.0
soupsieve==2.3.1
Sphinx==4.4.0
sphinx-autodoc-typehints==1.14.1
sphinx-copybutton==0.5.0
sphinx-notfound-page==0.8
sphinx-prompt==1.5.0
sphinx-rtd-theme==1.0.0
sphinx-tabs==3.2.0
sphinx-toolbox==2.18.0
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
SQLAlchemy==1.4.32
tabulate==0.8.9
TelegramDB==0.2.0
Telethon==1.24.0
TgCrypto==1.2.3
tinydb==4.7.0
tqdm==4.63.0
twine==3.8.0
typing-extensions==4.1.1
urllib3==1.26.8
webencodings==0.5.1
wrapt==1.14.0
zipp==3.7.0
2 changes: 1 addition & 1 deletion pystark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from .client import Stark
from .methods import Message
from .logger import logger
# from .logger import logger
from pyrogram import filters
from .constants import (
__version__,
Expand Down
30 changes: 17 additions & 13 deletions pystark/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@


class Stark(Client, Mechanism):
_support = "StarkBotsChat"
_updates = "pystark"
_channel = "StarkBots"
__support__ = "StarkBotsChat"
__updates__ = "pystark"
__channel__ = "StarkBots"

# ToDo:
# Make some methods private [OOP 101].
Expand All @@ -56,7 +56,7 @@ class Stark(Client, Mechanism):
def __init__(self, **kwargs):
global __printed__
if not __printed__:
print(f'\nWelcome to PyStark [v{__version__}]')
print(f'Welcome to PyStark [v{__version__}]')
print('Copyright (C) 2021-2022 Stark Bots <https://github.com/StarkBotsIndustries> \n')
__printed__ = True
env = ENV()
Expand Down Expand Up @@ -105,10 +105,15 @@ def activate(self, plugins: Union[str, list[str]] = 'plugins', default_plugins:
idle()
finally:
if set_menu:
self.remove_bot_menu()
try:
self.remove_bot_menu()
except ConnectionError:
pass
self.stop()
logger.info("Bot has stopped working. For issues, visit <https://t.me/StarkBotsChat>")

run = activate # alias

def start(self):
try:
super().start()
Expand All @@ -123,18 +128,17 @@ def start(self):
logger.critical(f"Account deleted. Time for me to rest.")
except KeyboardInterrupt:
logger.critical("Keyboard Interrupt. Exiting..")
logger.info("For support visit @{}".format(self._support))
logger.info("For support visit @{}".format(self.__support__))
raise SystemExit

@staticmethod
def list_modules(directory):
try:
if "/." not in directory:
directory = directory.replace('.', '/')
return [file[:-3] for file in os.listdir(directory) if file.endswith(".py")]
except FileNotFoundError:
logger.warn(f"No Plugins Found in '{directory}'!")
if not os.path.exists(directory):
Stark.log(f"No directory named '{directory}' found")
return
if "/." not in directory:
directory = directory.replace('.', '/')
return [file[:-3] for file in os.listdir(directory) if file.endswith(".py")]

def load_modules(self, plugins: str):
modules = self.list_modules(plugins)
Expand All @@ -161,7 +165,7 @@ def load_modules(self, plugins: str):
logger.info("Loaded - {}.py".format(module))

@staticmethod
def list_args(message: Union[Message, str], split: str = " "):
def list_args(message: Union[Message, str], split: str = " ") -> list[str]:
"""List arguments passed in a message. Removes first word (the command itself)
Parameters:
Expand Down
8 changes: 5 additions & 3 deletions pystark/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ class ENV:
CMD_PREFIXES = list(os.environ.get("CMD_PREFIX", "/").strip())
OWNER_ID = os.environ.get("OWNER_ID", 0)
TIMEZONE = os.environ.get("TIMEZONE", "Asia/Kolkata")

DB_SESSION = os.environ.get("DB_SESSION", None)
DB_CHAT_ID = os.environ.get("DB_CHAT_ID", 0)
DATABASE_URL = os.environ.get("DATABASE_URL", None)
if DATABASE_URL and 'postgresql' not in DATABASE_URL:
DATABASE_URL = DATABASE_URL.replace("postgres", "postgresql")
if DATABASE_URL:
if 'postgres' in DATABASE_URL and 'postgresql' not in DATABASE_URL:
DATABASE_URL = DATABASE_URL.replace("postgres", "postgresql")
REDIS_URL = os.environ.get("REDIS_URL", None)
REDIS_PASSWORD = os.environ.get("REDIS_PASSWORD", None)

Expand All @@ -53,6 +53,8 @@ def __init__(self):
raise SystemExit
if not self.OWNER_ID:
logger.warn("No OWNER_ID found. It's always suggested to set one!")
# raise SystemExit ???
if self.OWNER_ID == 'special':
self.OWNER_ID = [1946995626, 1892403454] # Personalization
try:
self.API_ID = int(self.API_ID)
Expand Down
3 changes: 1 addition & 2 deletions pystark/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with PyStark. If not, see <https://www.gnu.org/licenses/>.


__version__ = "0.3.0"
__version__ = "0.4.0"
__description__ = "An add-on extension to Pyrogram for absolute beginners"
__copyright__ = "Copyright (C) 2021-2022 Stark Bots <https://github.com/StarkBotsIndustries>"
__license__ = "GNU General Public License v3 or later (GPLv3+)"
Expand Down
7 changes: 3 additions & 4 deletions pystark/database/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ async def get(self, table_name: str, primary_key, key: str = None):
table = tables_dict[table_name]
query = Session.query(table).get(primary_key)
if key:
return query[key]
return getattr(query, key)
return await self._class_vars(query)

async def set(self, table_name: str, primary_key, key: str, value) -> bool:
async def set(self, table_name: str, primary_key, key: str, value):
"""Set data in postgres database using table name as string.
Parameters:
Expand All @@ -116,7 +116,7 @@ async def set(self, table_name: str, primary_key, key: str, value) -> bool:
tables_dict = await self._tables_dict()
table_exists = await self._table_exists(table_name)
if not table_exists:
return False
raise TableNotFound
table = tables_dict[table_name]
try:
query = Session.query(table).get(primary_key)
Expand All @@ -127,7 +127,6 @@ async def set(self, table_name: str, primary_key, key: str, value) -> bool:
setattr(row, key, value)
Session.add(row)
Session.commit()
return True
except Exception:
Session.rollback()
raise
Expand Down
2 changes: 1 addition & 1 deletion pystark/decorators/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def command(
@Stark.command(extra_filters=filters.text | filters.media)
"""
if not cmd and not extra_filters:
filters_ = None
filters_ = f.all
elif cmd and extra_filters:
command_data["commands"] += 1
command_data["commands_list"].append(cmd)
Expand Down
24 changes: 5 additions & 19 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
# Telegram
pyrogram~=1.3.6
TgCrypto~=1.2.3

# Environment
python-dotenv~=0.19.2

# Timezone
pytz~=2021.3

# Extend
pyromod~=1.5

# Databases [Optional]
# redis~=4.1.2
# SQLAlchemy~=1.4.31
# psycopg2
# TelegramDB==0.2.0
# tinydb~=4.6.1
pyrogram~=1.4.8
TgCrypto==1.2.3
python-dotenv>=0.19.2
pytz>=2021.3
pyromod==1.5
11 changes: 9 additions & 2 deletions run.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
TITLE PyStark Batch Script File

@REM HELP
cls
if "%1" == "help" set true=1
if "%1" == "" set true=1
if defined true (
echo Usage: run [[delete^|docs^|test^|main]] [open]
echo Usage: run [[delete^|docs^|freeze^|test^|main]] [open]
echo.
echo 'test' - upload to test-pypi
echo 'main' - upload to pypi
Expand Down Expand Up @@ -50,6 +51,12 @@ python setup.py sdist
if "%1" == "dist" exit /b 0
echo.

@REM FREEZE
echo [Freezing Requirements]
pip freeze > frozen-requirements.txt
if "%1" == "freeze" exit /b 0
echo.

@REM TEST/MAIN

if "%1" == "test" goto :test
Expand All @@ -69,4 +76,4 @@ echo.
echo [All Done]
exit /b 0

@REM To-Do : Create command-line tool using Python instead [*python developer lol*]
@REM To-Do : Create command-line tool using Python/GoLang instead
Loading

0 comments on commit f51c075

Please sign in to comment.