Skip to content

Commit

Permalink
Merge pull request #64 from ksdfg/py310
Browse files Browse the repository at this point in the history
Python 3.10 migration
  • Loading branch information
ksdfg authored Jan 2, 2022
2 parents c8de91b + 5741e91 commit 46d38ef
Show file tree
Hide file tree
Showing 9 changed files with 378 additions and 439 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@master
- uses: actions/setup-python@v2
with:
python-version: 3.8.3
- uses: actions/checkout@master
python-version: 3.10.1
- uses: actions/checkout@v2
- run: |
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
pip install $($HOME/.poetry/bin/poetry export --dev --without-hashes | grep black | cut -d';' -f1)
black --check .
curl -sSL https://install.python-poetry.org | python3 -
pip install $(poetry export --dev --without-hashes | grep black | cut -d';' -f1)
black --check --target-version py310 .
568 changes: 250 additions & 318 deletions poetry.lock

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ authors = ["ksdfg <ksdfg123@gmail.com>"]
license = "GPL-3.0"

[tool.poetry.dependencies]
python = "3.9.5"
python = "3.10.1"
bs4 = "^0.0.1"
dnspython = "^2.0.0"
emoji = "^0.6.0"
mongoengine = "^0.20.0"
Pillow = "^8.0.1"
python-decouple = "^3.3"
python-telegram-bot = "^13.0"
dnspython = "^2.1.0"
emoji = "^1.6.1"
mongoengine = "^0.23.1"
Pillow = "^8.4.0"
python-decouple = "^3.5"
python-telegram-bot = "^13.9"
spongemock = "^0.3.4"
zalgo-text = "^0.6"
hentai = "^3.2.5"
hentai = "^3.2.9"
telegraph = "^2.1.0"

[tool.poetry.dev-dependencies]
black = "^20.8b1"
black = "^21.12b0"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
20 changes: 9 additions & 11 deletions telebot/modules/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def get_datetime_form_args(args: List[str], username: str = "") -> Optional[date
:param username: username quoted in the message, if any
:return:
"""
until_date = None

# get all args other than the username
useful_args = []
Expand All @@ -104,16 +103,15 @@ def get_datetime_form_args(args: List[str], username: str = "") -> Optional[date
if useful_args:
# get datetime till when we have to mute user
time, unit = float(useful_args[0][:-1]), useful_args[0][-1]
if unit == "d":
until_date = datetime.now(tz=timezone("Asia/Kolkata")) + timedelta(days=time)
elif unit == "h":
until_date = datetime.now(tz=timezone("Asia/Kolkata")) + timedelta(hours=time)
elif unit == "m":
until_date = datetime.now(tz=timezone("Asia/Kolkata")) + timedelta(minutes=time)
else:
raise TimeFormatException

return until_date
match unit:
case "d":
return datetime.now(tz=timezone("Asia/Kolkata")) + timedelta(days=time)
case "h":
return datetime.now(tz=timezone("Asia/Kolkata")) + timedelta(hours=time)
case "m":
return datetime.now(tz=timezone("Asia/Kolkata")) + timedelta(minutes=time)
case _:
raise TimeFormatException


@bot_action("mute")
Expand Down
4 changes: 2 additions & 2 deletions telebot/modules/db/mute.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from typing import List, Union
from typing import List

from mongoengine import DynamicDocument, IntField, StringField, DateTimeField

Expand Down Expand Up @@ -61,7 +61,7 @@ def remove_muted_member(chat: int, user: int) -> bool:
return False


def fetch_muted_member(chat: int, username: str) -> Union[int, bool]:
def fetch_muted_member(chat: int, username: str) -> int | bool:
"""
Fetch user ID of muted member
:param chat: chat ID member is muted in
Expand Down
29 changes: 15 additions & 14 deletions telebot/modules/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,21 @@ def reply(update: Update, context: CallbackContext) -> None:
content, filter_type = get_filter(update.effective_chat.id, trigger)

# send reply according to type
if filter_type == "text":
msg.reply_markdown(content)
elif filter_type == "sticker":
msg.reply_sticker(content)
elif filter_type == "document":
msg.reply_document(content)
elif filter_type == "photo":
msg.reply_photo(content)
elif filter_type == "audio":
msg.reply_audio(content)
elif filter_type == "voice":
msg.reply_voice(content)
elif filter_type == "video":
msg.reply_video(content)
match filter_type:
case "text":
msg.reply_markdown(content)
case "sticker":
msg.reply_sticker(content)
case "document":
msg.reply_document(content)
case "photo":
msg.reply_photo(content)
case "audio":
msg.reply_audio(content)
case "voice":
msg.reply_voice(content)
case "video":
msg.reply_video(content)

break

Expand Down
29 changes: 15 additions & 14 deletions telebot/modules/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,21 @@ def fetch_note(update: Update, context: CallbackContext):
content, content_type = get_note(update.effective_chat.id, name)

# send reply according to type
if content_type == "text":
update.effective_message.reply_markdown(content)
elif content_type == "sticker":
update.effective_message.reply_sticker(content)
elif content_type == "document":
update.effective_message.reply_document(content)
elif content_type == "photo":
update.effective_message.reply_photo(content)
elif content_type == "audio":
update.effective_message.reply_audio(content)
elif content_type == "voice":
update.effective_message.reply_voice(content)
elif content_type == "video":
update.effective_message.reply_video(content)
match content_type:
case "text":
update.effective_message.reply_markdown(content)
case "sticker":
update.effective_message.reply_sticker(content)
case "document":
update.effective_message.reply_document(content)
case "photo":
update.effective_message.reply_photo(content)
case "audio":
update.effective_message.reply_audio(content)
case "voice":
update.effective_message.reply_voice(content)
case "video":
update.effective_message.reply_video(content)


@bot_action("notes")
Expand Down
134 changes: 71 additions & 63 deletions telebot/modules/stickers.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,20 @@ def _make_pack(
)

except TelegramError as e:
if e.message == "Sticker set name is already occupied":
msg.reply_markdown(f"Your pack can be found [here](t.me/addstickers/{pack_name})")

elif e.message == "Peer_id_invalid":
msg.reply_text(
"Contact me in PM first.",
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton(text="Start", url=f"t.me/{bot.username}")]]),
)
match e.message:
case "Sticker set name is already occupied":
msg.reply_markdown(f"Your pack can be found [here](t.me/addstickers/{pack_name})")

case "Peer_id_invalid":
msg.reply_text(
"Contact me in PM first.",
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton(text="Start", url=f"t.me/{bot.username}")]]
),
)

elif e.message == "Internal Server Error: created sticker set not found (500)":
msg.reply_markdown(f"Sticker pack successfully created. Get it [here](t.me/addstickers/{pack_name})")
case "Internal Server Error: created sticker set not found (500)":
msg.reply_markdown(f"Sticker pack successfully created. Get it [here](t.me/addstickers/{pack_name})")

return

Expand Down Expand Up @@ -288,20 +291,23 @@ def kang(update: Update, context: CallbackContext) -> None:
)

except TelegramError as e:
if e.message == "Stickerset_invalid":
_make_pack(msg, user, open(kang_sticker, "rb"), sticker.emoji, bot, pack_name, pack_num, is_animated)
match e.message:
case "Stickerset_invalid":
_make_pack(
msg, user, open(kang_sticker, "rb"), sticker.emoji, bot, pack_name, pack_num, is_animated
)

elif e.message == "Invalid sticker emojis":
msg.reply_text("Invalid emoji(s).")
case "Invalid sticker emojis":
msg.reply_text("Invalid emoji(s).")

elif e.message == "Stickers_too_much":
msg.reply_text("Meowtastic news! This loser just maxed out his pack size. Press F to pay respecc.")
case "Stickers_too_much":
msg.reply_text("Meowtastic news! This loser just maxed out his pack size. Press F to pay respecc.")

elif e.message == "Internal Server Error: sticker set not found (500)":
msg.reply_markdown(
f"Sticker successfully added to [{pack_title}](t.me/addstickers/{pack_name})"
+ f"\nEmoji is : {sticker.emoji}"
)
case "Internal Server Error: sticker set not found (500)":
msg.reply_markdown(
f"Sticker successfully added to [{pack_title}](t.me/addstickers/{pack_name})"
+ f"\nEmoji is : {sticker.emoji}"
)

elif msg.reply_to_message:
# future usage
Expand Down Expand Up @@ -353,30 +359,31 @@ def kang(update: Update, context: CallbackContext) -> None:
return

except TelegramError as e:
if e.message == "Stickerset_invalid":
_make_pack(msg, user, open(kang_sticker, "rb"), sticker_emoji, bot, pack_name, pack_num)

elif e.message == "Sticker_png_dimensions":
im.save(kang_sticker, "PNG")
bot.add_sticker_to_set(
user_id=user.id, name=pack_name, png_sticker=open(kang_sticker, "rb"), emojis=sticker_emoji
)
msg.reply_markdown(
f"Sticker successfully added to [{pack_title}](t.me/addstickers/{pack_name})"
+ f"\nEmoji is: {sticker_emoji}"
)
match e.message:
case "Stickerset_invalid":
_make_pack(msg, user, open(kang_sticker, "rb"), sticker_emoji, bot, pack_name, pack_num)

case "Sticker_png_dimensions":
im.save(kang_sticker, "PNG")
bot.add_sticker_to_set(
user_id=user.id, name=pack_name, png_sticker=open(kang_sticker, "rb"), emojis=sticker_emoji
)
msg.reply_markdown(
f"Sticker successfully added to [{pack_title}](t.me/addstickers/{pack_name})"
+ f"\nEmoji is: {sticker_emoji}"
)

elif e.message == "Invalid sticker emojis":
msg.reply_text("Invalid emoji(s).")
case "Invalid sticker emojis":
msg.reply_text("Invalid emoji(s).")

elif e.message == "Stickers_too_much":
msg.reply_text("Meowtastic news! This loser just maxed out his pack size. Press F to pay respecc.")
case "Stickers_too_much":
msg.reply_text("Meowtastic news! This loser just maxed out his pack size. Press F to pay respecc.")

elif e.message == "Internal Server Error: sticker set not found (500)":
msg.reply_markdown(
f"Sticker successfully added to [{pack_title}](t.me/addstickers/{pack_name})"
+ f"\nEmoji is : {sticker_emoji}"
)
case "Internal Server Error: sticker set not found (500)":
msg.reply_markdown(
f"Sticker successfully added to [{pack_title}](t.me/addstickers/{pack_name})"
+ f"\nEmoji is : {sticker_emoji}"
)

elif context.args:
# get the emoji to use as sticker and the emojis to set to said sticker
Expand Down Expand Up @@ -407,30 +414,31 @@ def kang(update: Update, context: CallbackContext) -> None:
return

except TelegramError as e:
if e.message == "Stickerset_invalid":
_make_pack(msg, user, open(kang_sticker, "rb"), sticker_emoji, bot, pack_name, pack_num)

elif e.message == "Sticker_png_dimensions":
im.save(kang_sticker, "PNG")
bot.add_sticker_to_set(
user_id=user.id, name=pack_name, png_sticker=open(kang_sticker, "rb"), emojis=sticker_emoji
)
msg.reply_markdown(
f"Sticker successfully added to [{pack_title}](t.me/addstickers/{pack_name})"
+ f"\nEmoji is : {sticker_emoji}"
)
match e.message:
case "Stickerset_invalid":
_make_pack(msg, user, open(kang_sticker, "rb"), sticker_emoji, bot, pack_name, pack_num)

case "Sticker_png_dimensions":
im.save(kang_sticker, "PNG")
bot.add_sticker_to_set(
user_id=user.id, name=pack_name, png_sticker=open(kang_sticker, "rb"), emojis=sticker_emoji
)
msg.reply_markdown(
f"Sticker successfully added to [{pack_title}](t.me/addstickers/{pack_name})"
+ f"\nEmoji is : {sticker_emoji}"
)

elif e.message == "Invalid sticker emojis":
msg.reply_text("Invalid emoji(s).")
case "Invalid sticker emojis":
msg.reply_text("Invalid emoji(s).")

elif e.message == "Stickers_too_much":
msg.reply_text("Meowtastic news! This loser just maxed out his pack size. Press F to pay respecc.")
case "Stickers_too_much":
msg.reply_text("Meowtastic news! This loser just maxed out his pack size. Press F to pay respecc.")

elif e.message == "Internal Server Error: sticker set not found (500)":
msg.reply_markdown(
f"Sticker successfully added to [{pack_title}](t.me/addstickers/{pack_name})"
+ f"\nEmoji is : {sticker_emoji}"
)
case "Internal Server Error: sticker set not found (500)":
msg.reply_markdown(
f"Sticker successfully added to [{pack_title}](t.me/addstickers/{pack_name})"
+ f"\nEmoji is : {sticker_emoji}"
)

else:
msg.reply_markdown("Please reply to a sticker, or image to kang it!")
Expand Down
3 changes: 1 addition & 2 deletions telebot/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from collections import Callable
from functools import wraps
from traceback import print_exc, format_exc
from typing import Tuple
from typing import Callable, Tuple

from emoji import emojize
from telegram import Update, Message, MessageEntity
Expand Down

0 comments on commit 46d38ef

Please sign in to comment.