Skip to content

Commit

Permalink
3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
alissonlauffer committed Oct 30, 2023
1 parent 5ba039b commit 3944a6a
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 33 deletions.
5 changes: 2 additions & 3 deletions eduu/database/admins.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: MIT
# Copyright (c) 2018-2023 Amano LLC

from typing import Optional

from .core import database

Expand All @@ -17,7 +16,7 @@ async def check_if_del_service(chat_id: int) -> bool:
return row[0]


async def toggle_del_service(chat_id: int, mode: Optional[bool]) -> None:
async def toggle_del_service(chat_id: int, mode: bool | None) -> None:
await conn.execute(
"UPDATE groups SET delservicemsgs = ? WHERE chat_id = ?", (mode, chat_id)
)
Expand All @@ -33,7 +32,7 @@ async def check_if_antichannelpin(chat_id: int) -> bool:
return row[0]


async def toggle_antichannelpin(chat_id: int, mode: Optional[bool]) -> None:
async def toggle_antichannelpin(chat_id: int, mode: bool | None) -> None:
await conn.execute(
"UPDATE groups SET antichannelpin = ? WHERE chat_id = ?", (mode, chat_id)
)
Expand Down
5 changes: 2 additions & 3 deletions eduu/database/warns.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
# SPDX-License-Identifier: MIT
# Copyright (c) 2018-2023 Amano LLC

from typing import Optional

from .core import database

conn = database.get_conn()


async def get_warn_action(chat_id: int) -> tuple[Optional[str], bool]:
async def get_warn_action(chat_id: int) -> tuple[str | None, bool]:
cursor = await conn.execute(
"SELECT warn_action FROM groups WHERE chat_id = (?)", (chat_id,)
)
res = (await cursor.fetchone())[0]
return "ban" if res is None else res


async def set_warn_action(chat_id: int, action: Optional[str]):
async def set_warn_action(chat_id: int, action: str | None):
await conn.execute(
"UPDATE groups SET warn_action = ? WHERE chat_id = ?", (action, chat_id)
)
Expand Down
5 changes: 2 additions & 3 deletions eduu/database/welcome.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
# SPDX-License-Identifier: MIT
# Copyright (c) 2018-2023 Amano LLC

from typing import Optional

from .core import database

conn = database.get_conn()


async def get_welcome(chat_id: int) -> tuple[Optional[str], bool]:
async def get_welcome(chat_id: int) -> tuple[str | None, bool]:
cursor = await conn.execute(
"SELECT welcome, welcome_enabled FROM groups WHERE chat_id = (?)", (chat_id,)
)
return await cursor.fetchone()


async def set_welcome(chat_id: int, welcome: Optional[str]):
async def set_welcome(chat_id: int, welcome: str | None):
await conn.execute(
"UPDATE groups SET welcome = ? WHERE chat_id = ?", (welcome, chat_id)
)
Expand Down
3 changes: 1 addition & 2 deletions eduu/plugins/langs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Copyright (c) 2018-2023 Amano LLC

from itertools import zip_longest
from typing import Union

from pyrogram import Client, filters
from pyrogram.enums import ChatType
Expand Down Expand Up @@ -39,7 +38,7 @@ def gen_langs_kb():
)
@require_admin(allow_in_private=True)
@use_chat_lang
async def chlang(c: Client, m: Union[CallbackQuery, Message], strings):
async def chlang(c: Client, m: CallbackQuery | Message, strings):
keyboard = InlineKeyboardMarkup(
inline_keyboard=[
*gen_langs_kb(),
Expand Down
5 changes: 2 additions & 3 deletions eduu/plugins/start.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: MIT
# Copyright (c) 2018-2023 Amano LLC

from typing import Union

from pyrogram import Client, filters
from pyrogram.types import (
Expand All @@ -21,7 +20,7 @@
@Client.on_message(filters.command("start", PREFIXES) & filters.private, group=2)
@Client.on_callback_query(filters.regex("^start_back$"))
@use_chat_lang
async def start_pvt(c: Client, m: Union[Message, CallbackQuery], strings):
async def start_pvt(c: Client, m: Message | CallbackQuery, strings):
if isinstance(m, CallbackQuery):
msg = m.message
send = msg.edit_text
Expand Down Expand Up @@ -49,7 +48,7 @@ async def start_pvt(c: Client, m: Union[Message, CallbackQuery], strings):

@Client.on_message(filters.command("start", PREFIXES) & filters.group, group=2)
@use_chat_lang
async def start_grp(c: Client, m: Union[Message, CallbackQuery], strings):
async def start_grp(c: Client, m: Message | CallbackQuery, strings):
keyboard = InlineKeyboardMarkup(
inline_keyboard=[
[
Expand Down
3 changes: 1 addition & 2 deletions eduu/plugins/sudos.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import traceback
from contextlib import redirect_stdout, suppress
from sqlite3 import IntegrityError, OperationalError
from typing import Union

import humanfriendly
import speedtest
Expand All @@ -28,7 +27,7 @@
from eduu.utils.localization import use_chat_lang
from eduu.utils.utils import shell_exec

prefix: Union[list, str] = "!"
prefix: list | str = "!"

conn = database.get_conn()

Expand Down
3 changes: 1 addition & 2 deletions eduu/plugins/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Copyright (c) 2018-2023 Amano LLC

import re
from typing import Union

from pyrogram import Client, filters
from pyrogram.types import (
Expand Down Expand Up @@ -85,7 +84,7 @@ def get_status_emoji(status_code: int) -> str:
@Client.on_message(filters.command(["clima", "weather"], PREFIXES))
@Client.on_inline_query(filters.regex(r"^(clima|weather) .+", re.I))
@use_chat_lang
async def weather(c: Client, m: Union[InlineQuery, Message], strings):
async def weather(c: Client, m: InlineQuery | Message, strings):
text = m.text if isinstance(m, Message) else m.query
if len(text.split(maxsplit=1)) == 1:
if isinstance(m, Message):
Expand Down
6 changes: 3 additions & 3 deletions eduu/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# Copyright (c) 2018-2023 Amano LLC

import asyncio
from collections.abc import Callable
from functools import partial, wraps
from typing import Callable, Optional, Union

from pyrogram import Client, StopPropagation
from pyrogram.enums import ChatType
Expand All @@ -30,7 +30,7 @@ async def run(*args, loop=None, executor=None, **kwargs):


def require_admin(
permissions: Optional[ChatPrivileges] = None,
permissions: ChatPrivileges | None = None,
allow_in_private: bool = False,
complain_missing_perms: bool = True,
):
Expand All @@ -55,7 +55,7 @@ def require_admin(
def decorator(func):
@wraps(func)
async def wrapper(
client: Client, message: Union[CallbackQuery, Message], *args, **kwargs
client: Client, message: CallbackQuery | Message, *args, **kwargs
):
lang = await get_lang(message)
strings = partial(
Expand Down
6 changes: 3 additions & 3 deletions eduu/utils/localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Copyright (c) 2018-2023 Amano LLC

import json
from collections.abc import Callable
from functools import partial
from pathlib import Path
from typing import Callable, Optional, Union

from pyrogram.enums import ChatType
from pyrogram.types import CallbackQuery, InlineQuery, Message
Expand Down Expand Up @@ -67,7 +67,7 @@ def get_locale_string(
language: str,
default_context: str,
key: str,
context: Optional[str] = None,
context: str | None = None,
) -> str:
if context:
default_context = context
Expand All @@ -78,7 +78,7 @@ def get_locale_string(
return res


async def get_lang(message: Union[CallbackQuery, Message, InlineQuery]) -> str:
async def get_lang(message: CallbackQuery | (Message | InlineQuery)) -> str:
if isinstance(message, CallbackQuery):
chat = message.message.chat if message.message else message.from_user
chat_type = message.message.chat.type if message.message else ChatType.PRIVATE
Expand Down
15 changes: 7 additions & 8 deletions eduu/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from functools import partial
from pathlib import Path
from string import Formatter
from typing import Optional, Union

import httpx
from pyrogram import Client, emoji, filters
Expand Down Expand Up @@ -52,8 +51,8 @@ def pretty_size(size_bytes):


async def check_perms(
message: Union[CallbackQuery, Message],
permissions: Optional[ChatPrivileges] = None,
message: CallbackQuery | Message,
permissions: ChatPrivileges | None = None,
complain_missing_perms: bool = True,
strings=None,
) -> bool:
Expand Down Expand Up @@ -94,7 +93,7 @@ async def check_perms(
sudofilter = filters.user(SUDOERS)


async def extract_time(m: Message, t: str) -> Optional[datetime]:
async def extract_time(m: Message, t: str) -> datetime | None:
if t[-1] in ["m", "h", "d"]:
unit = t[-1]
num = t[:-1]
Expand Down Expand Up @@ -227,7 +226,7 @@ def add_command(
self,
command: str,
category: str,
aliases: Optional[list] = None,
aliases: list | None = None,
):
context = get_caller_context()

Expand All @@ -244,7 +243,7 @@ def add_command(
}
)

def get_commands_message(self, strings, category: Optional[str] = None):
def get_commands_message(self, strings, category: str | None = None):
# TODO: Add pagination support.
if category is None:
cmds_list = []
Expand Down Expand Up @@ -273,7 +272,7 @@ def __init__(self):
def add_command(
self,
command: str,
aliases: Optional[list] = None,
aliases: list | None = None,
):
context = get_caller_context()

Expand All @@ -288,7 +287,7 @@ def add_command(
}
)

def search_commands(self, query: Optional[str] = None):
def search_commands(self, query: str | None = None):
return [
cmd
for cmd in sorted(self.commands, key=lambda k: k["command"])
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ homepage = "https://github.com/AmanoTeam/EduuRobot"

[tool.ruff]
src = ["."]
target-version = "py39"
target-version = "py310"
select = [
"I", # isort
"E", # pycodestyle
Expand Down

0 comments on commit 3944a6a

Please sign in to comment.