Skip to content

Commit

Permalink
Add publish workflow (#17)
Browse files Browse the repository at this point in the history
* Rename web page preview param on editMessageText method

* Add placeholder parameter to ForceReply type (#12)

* Add get_photo on Message type (#16)

* Prevent get_chat_state on TelegramUser from returning a tuple (#13)

Previously, it would return a tuple where the first item was the state object, the second one was whether or not the state existed before. Now it doesn't return the second item and only returns the state.

* Add publish workflow

Co-authored-by: Arman MZD <[email protected]>
Co-authored-by: ABOLFAZLVALIKHANI <[email protected]>
  • Loading branch information
3 people authored Aug 7, 2022
1 parent 6712ad2 commit e29a5c5
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 10 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Publish to PyPI.org
on:
release:
types: [published]
jobs:
pypi:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- run: python3 -m pip install --upgrade build && python3 -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ __pycache__/
.AppleDouble
.LSOverride
site/
release
release*
.vscode
db.sqlite3

Expand Down
2 changes: 1 addition & 1 deletion django_tgbot/bot_api_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def answerCallbackQuery(self, callback_query_id, text=None, show_alert=None, url
return self.request_and_result(create_params_from_args(locals()), bool)

def editMessageText(self, text, chat_id=None, message_id=None, inline_message_id=None, parse_mode=None,
disable_webpage_preview=None,
disable_web_page_preview=None,
reply_markup: Union[
None, InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] = None) -> Message:

Expand Down
7 changes: 6 additions & 1 deletion django_tgbot/management/commands/createtgbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ def handle(self, *args, **options):
return

with open(os.path.join(dst, 'credentials.py'), 'w') as f:
f.write("# Do not remove these 2 lines:\nBOT_TOKEN = '{}'\nAPP_NAME = '{}'\n".format(bot_token, bot_username))
creds_help_text_lines = [
"# Do not remove these 2 lines:",
f"BOT_TOKEN = '{bot_token}' # You should consider using env variables or a secret manager for this.",
f"APP_NAME = '{bot_username}'"
]
f.write('\n'.join(creds_help_text_lines))

with open(os.path.join(dst, '__init__.py'), 'w') as f:
f.write(
Expand Down
4 changes: 2 additions & 2 deletions django_tgbot/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ class AbstractTelegramUser(models.Model):
username = models.CharField(max_length=128, null=True, blank=True)

def get_chat_state(self, chat: AbstractTelegramChat):
state = AbstractTelegramState.objects.get_or_create(
state, _ = AbstractTelegramState.objects.get_or_create(
telegram_user__telegram_id=self.telegram_id,
telegram_chat__telegram_id=chat.telegram_id
)
return state

def get_private_chat_state(self):
state = AbstractTelegramState.objects.get_or_create(
state, _ = AbstractTelegramState.objects.get_or_create(
telegram_user__telegram_id=self.telegram_id,
telegram_chat__telegram_id=self.telegram_id
)
Expand Down
3 changes: 2 additions & 1 deletion django_tgbot/types/forcereply.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
class ForceReply(BasicType):
fields = {
'force_reply': BasicType.bool_interpreter,
'input_field_placeholder': str,
'selective': BasicType.bool_interpreter
}

def __init__(self, obj=None):
super(ForceReply, self).__init__(obj)

@classmethod
def a(cls, force_reply: bool, selective: Optional[bool] = None):
def a(cls, force_reply: bool, input_field_placeholder: Optional[str] = None, selective: Optional[bool] = None):
return super().a(**locals())
4 changes: 4 additions & 0 deletions django_tgbot/types/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ def get_caption(self) -> Optional[str]:

def get_reply_markup(self):
return getattr(self, 'reply_markup', None)


def get_photo(self):
return getattr(self, 'photo', None)


# Placed here to avoid import cycles
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[build-system]
requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = django-tgbot
version = 1.4.9.2
version = 1.0.0
description = A Django app for creating Telegram bots.
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
3 changes: 0 additions & 3 deletions setup.py

This file was deleted.

0 comments on commit e29a5c5

Please sign in to comment.