Skip to content

Commit

Permalink
v3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Bibo-Joshi committed May 21, 2022
1 parent ffd9248 commit 339c8cc
Show file tree
Hide file tree
Showing 23 changed files with 441 additions and 414 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "monthly"
34 changes: 34 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: GitHub Pages
on:
push:
branches:
- pages # For testing
- master

jobs:
gh-pages:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Initialize submodules
run:
git submodule update --init --recursive

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'

- name: Install dependencies
run: |
python -W ignore -m pip install --upgrade pip
python -W ignore -m pip install -r requirements.txt
python -W ignore -m pip install -r docs/requirements-docs.txt
- name: Build Docs
run: sphinx-build docs/source docs/build/html

- name: Deploy
uses: JamesIves/[email protected]
with:
branch: gh-pages
folder: docs/build/html
29 changes: 0 additions & 29 deletions .gitlab-ci.yml

This file was deleted.

81 changes: 45 additions & 36 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,51 +1,60 @@
# Make sure that
# * the revs specified here match requirements-dev.txt
# * the additional_dependencies here match requirements.txt

ci:
autoupdate_schedule: monthly

default_language_version:
python: python3.7

repos:
- repo: https://github.com/psf/black
rev: 20.8b1
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
args:
- --diff
- --check
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
language: python
- repo: https://github.com/PyCQA/pylint
rev: v2.10.2
- id: flake8
- repo: https://github.com/PyCQA/pylint
rev: v2.13.8
hooks:
- id: pylint
- id: pylint
files: ^(main|bot/\w*).py$
args:
- --rcfile=setup.cfg
# run pylint across multiple cpu cores to speed it up-
- --jobs=0 # See https://pylint.pycqa.org/en/latest/user_guide/run.html?#parallel-execution to know more
additional_dependencies:
- python-telegram-bot>=13.7,<14.0
- Pillow==8.3.0
- PyHyphen==3.0.1
- pytz
- fuzzywuzzy==0.18.0
- git+https://gitlab.com/HirschHeissIch/[email protected]
language: python
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.910
- python-telegram-bot==20.0a0
- Pillow==9.1.1
- PyHyphen==3.0.1
- pytz
- thefuzz==0.19.0
- git+https://github.com/Bibo-Joshi/[email protected]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.950
hooks:
- id: mypy
- id: mypy
files: ^(main|bot/\w*).py$
language: python
additional_dependencies:
- python-telegram-bot>=13.7,<14.0
- Pillow==8.3.0
- PyHyphen==3.0.1
- pytz
- fuzzywuzzy==0.18.0
- git+https://gitlab.com/HirschHeissIch/ptbstats.git@v1.3.1
- repo: https://github.com/asottile/pyupgrade
rev: v2.25.0
- python-telegram-bot==20.0a0
- Pillow==9.1.1
- PyHyphen==3.0.1
- pytz
- thefuzz==0.19.0
- git+https://github.com/Bibo-Joshi/ptbstats.git@v2.0
- repo: https://github.com/asottile/pyupgrade
rev: v2.32.0
hooks:
- id: pyupgrade
files: ^(main|bot/\w*).py$
- id: pyupgrade
args:
- --py36-plus
- --py37-plus
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
name: isort
args:
- --diff
- --check
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
Changelog
=========

Version 3.0
===========
*Released 2022-05-22*

* Upgrade ``python-telegram-bot`` to v20.0a0 introducing ``asyncio``.
* Upgrade ``ptbstats`` to v2.0, which is not backwards compatible.

Version 2.2.1
=============
*Released 2021-09-18*
Expand Down
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ Twitter Status Bot
:target: https://t.me/TwitterStatusBot
:alt: Chat On Telegram

.. image:: https://results.pre-commit.ci/badge/github/Bibo-Joshi/twitter-status-bot/main.svg
:target: https://results.pre-commit.ci/latest/github/Bibo-Joshi/twitter-status-bot/main
:alt: pre-commit.ci status

»Twitter Status Bot« is a simple Telegram Bot that let's you create stickers looking like Tweets on the fly.
You can find it at `@TwitterStatusBot`_.
Inspired by this `sticker set`_ by `@AboutTheDot`_.
Expand Down
67 changes: 31 additions & 36 deletions bot/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,38 @@
"""Methods for simple commands."""
from typing import cast

from telegram import (
Update,
InlineKeyboardMarkup,
InlineKeyboardButton,
Message,
User,
ChatAction,
Sticker,
)
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Message, Sticker, Update, User
from telegram.constants import ChatAction

from bot.utils import get_sticker_photo_stream
from bot.constants import HOMEPAGE, LTR, RTL
from bot.twitter import HyphenationError
from bot.userdata import CCT, UserData
from bot.utils import get_sticker_photo_stream


def sticker_message(update: Update, context: CCT) -> None:
async def sticker_message(update: Update, context: CCT) -> None:
"""
Answers a text message by providing the requested sticker.
Args:
update: The Telegram update.
context: The callback context as provided by the dispatcher.
context: The callback context as provided by the application.
"""
msg = cast(Message, update.effective_message)
user = cast(User, update.effective_user)
context.bot.send_chat_action(user.id, ChatAction.UPLOAD_PHOTO)
stream = get_sticker_photo_stream(cast(str, msg.text), user, context)
sticker = cast(Sticker, msg.reply_sticker(stream).sticker)
context.application.create_task(context.bot.send_chat_action(user.id, ChatAction.UPLOAD_PHOTO))
stream = await get_sticker_photo_stream(cast(str, msg.text), user, context)
sticker = cast(Sticker, (await msg.reply_sticker(stream)).sticker)
cast(UserData, context.user_data).sticker_file_ids[sticker.file_unique_id] = sticker.file_id


def info(update: Update, context: CCT) -> None:
async def info(update: Update, context: CCT) -> None:
"""
Returns some info about the bot.
Args:
update: The Telegram update.
context: The callback context as provided by the dispatcher.
context: The callback context as provided by the application.
"""
if context.args:
text = str(HyphenationError())
Expand Down Expand Up @@ -74,19 +67,19 @@ def info(update: Update, context: CCT) -> None:
"News Channel 📣",
url="https://t.me/BotChangelogs",
),
InlineKeyboardButton("Inline Mode ✍️", switch_inline_query=''),
InlineKeyboardButton("Inline Mode ✍️", switch_inline_query=""),
]
)

cast(Message, update.effective_message).reply_text(text, reply_markup=keyboard)
await cast(Message, update.effective_message).reply_text(text, reply_markup=keyboard)


def toggle_store_stickers(update: Update, context: CCT) -> None:
async def toggle_store_stickers(update: Update, context: CCT) -> None:
"""Toggles whether or not to store stickers for the user.
Args:
update: The Telegram update.
context: The callback context as provided by the dispatcher.
context: The callback context as provided by the application.
"""
user_data = cast(UserData, context.user_data)
message = cast(Message, update.effective_message)
Expand All @@ -98,60 +91,62 @@ def toggle_store_stickers(update: Update, context: CCT) -> None:
text = "Sent stickers be stored. will from now."
user_data.store_stickers = True

message.reply_text(text)
await message.reply_text(text)


def toggle_text_direction(update: Update, context: CCT) -> None:
async def toggle_text_direction(update: Update, context: CCT) -> None:
"""Toggles whether the user wants to use left-to-right or right-to-left text.
Args:
update: The Telegram update.
context: The callback context as provided by the dispatcher.
context: The callback context as provided by the application.
"""
user_data = cast(UserData, context.user_data)
message = cast(Message, update.effective_message)

mapping = {LTR: RTL, RTL: LTR}
user_data.text_direction = mapping[user_data.text_direction]
description = 'left-to-right' if user_data.text_direction == LTR else 'right-to-left'
description = "left-to-right" if user_data.text_direction == LTR else "right-to-left"

message.reply_text(f'The sticker text will be set as {description} now.')
await message.reply_text(f"The sticker text will be set as {description} now.")


def show_fallback_picture(update: Update, context: CCT) -> None:
async def show_fallback_picture(update: Update, context: CCT) -> None:
"""Shows the users current fallback profile picture, if set.
Args:
update: The Telegram update.
context: The callback context as provided by the dispatcher.
context: The callback context as provided by the application.
"""
user_data = cast(UserData, context.user_data)
message = cast(Message, update.effective_message)
if not user_data.fallback_photo:
message.reply_text(
await message.reply_text(
"You don't have a fallback picture set. Use /set_fallback_picture to set one."
)
else:
message.reply_photo(
await message.reply_photo(
user_data.fallback_photo.file_id,
caption='This is your current fallback profile picture. You can delete it with '
'/delete_fallback_picture or set a new one with /set_fallback_picture.',
caption="This is your current fallback profile picture. You can delete it with "
"/delete_fallback_picture or set a new one with /set_fallback_picture.",
)


def delete_fallback_picture(update: Update, context: CCT) -> None:
async def delete_fallback_picture(update: Update, context: CCT) -> None:
"""Deletes the users current fallback profile picture, if set.
Args:
update: The Telegram update.
context: The callback context as provided by the dispatcher.
context: The callback context as provided by the application.
"""
user_data = cast(UserData, context.user_data)
message = cast(Message, update.effective_message)
if not user_data.fallback_photo:
message.reply_text(
await message.reply_text(
"You don't have a fallback picture set. Use /set_fallback_picture to set one."
)
else:
user_data.update_fallback_photo(None)
message.reply_text('Fallback picture deleted. Use /set_fallback_picture to set a new one.')
await message.reply_text(
"Fallback picture deleted. Use /set_fallback_picture to set a new one."
)
14 changes: 7 additions & 7 deletions bot/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
from configparser import ConfigParser
from pathlib import Path

from PIL import Image, ImageFont
from hyphen import Hyphenator
from PIL import Image, ImageFont

config = ConfigParser()
config.read("bot.ini")

# A little trick to get the corrects paths both at runtime and when building the docs
PATH_PREFIX = '../' if Path('../headers').is_dir() else ''
PATH_PREFIX = "../" if Path("../headers").is_dir() else ""

ADMIN_KEY: str = 'ADMIN_KEY'
ADMIN_KEY: str = "ADMIN_KEY"
""":obj:`str`: The admins chat id is stored under this key in ``bot_data``."""
STICKER_CHAT_ID_KEY: str = 'STICKER_CHAT_ID_KEY'
STICKER_CHAT_ID_KEY: str = "STICKER_CHAT_ID_KEY"
""":obj:`srt`: The name of the chat where stickers can be sent to get their file IDs is stored
under this key in ``bot_data``."""
REMOVE_KEYBOARD_KEY: str = 'REMOVE_KEYBOARD_KEY'
REMOVE_KEYBOARD_KEY: str = "REMOVE_KEYBOARD_KEY"
""":obj:`str`: Store a message object in under this key in ``chat_data`` to remove its reply
markup later on with :meth:`utils.remove_reply_markup`."""
HOMEPAGE: str = "https://hirschheissich.gitlab.io/twitter-status-bot/"
Expand Down Expand Up @@ -63,7 +63,7 @@
""":class:`PIL.ImageFont.Font`: Font to use for small text in the body."""
HYPHENATOR = Hyphenator("en_US")
""":class:`PyHyphen.Hyphenator`: A hyphenator to use to wrap text."""
LTR = 'ltr'
LTR = "ltr"
""":obj:`str`: Text direction left to right."""
RTL: str = 'rtl'
RTL: str = "rtl"
""":obj:`str`: Text direction right to let."""
Loading

0 comments on commit 339c8cc

Please sign in to comment.