Skip to content

Commit

Permalink
treewide: using more type hint
Browse files Browse the repository at this point in the history
  • Loading branch information
HitaloM committed May 20, 2021
1 parent 337b2ee commit c65c5be
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 29 deletions.
2 changes: 1 addition & 1 deletion eduu/__main__.py
Expand Up @@ -26,7 +26,7 @@
)


async def main():
async def main() -> None:
await client.start()

# Saving commit number
Expand Down
11 changes: 6 additions & 5 deletions eduu/config.py.example
@@ -1,9 +1,10 @@
from typing import List
from typing import List, Optional

# Bot token from Bot Father
TOKEN: str = "YOUR_TOKEN_HERE"

# Your API ID and Hash from https://my.telegram.org/apps
# Your API ID and API HASH
# Get it from https://my.telegram.org/apps
API_ID: int = 123123
API_HASH: str = ""

Expand All @@ -14,7 +15,7 @@ log_chat: int = 123456789
# Sudoers and super sudoers
super_sudoers: List[int] = [123456789]
sudoers: List[int] = [987654321]
sudoers += super_sudoers
sudoers.append(super_sudoers)

# Prefixes for commands
# e.g: /command and !command
Expand All @@ -23,5 +24,5 @@ prefix: List[str] = ["/", "!"]
# List of disabled plugins
disabled_plugins: List[str] = []

# API keys
TENOR_API_KEY: str = ""
# API Keys (Optional)
TENOR_API_KEY: Optional[str] = ""
4 changes: 3 additions & 1 deletion eduu/database/__init__.py
@@ -1,6 +1,8 @@
# SPDX-License-Identifier: MIT
# Copyright (c) 2018-2021 Amano Team

from typing import List

from .database_handler import db, dbc

_all__ = ["db", "dbc"]
__all__: List[str] = ["db", "dbc"]
6 changes: 2 additions & 4 deletions eduu/plugins/admin.py
Expand Up @@ -2,14 +2,15 @@
# Copyright (c) 2018-2021 Amano Team

import asyncio
from typing import Optional
from typing import List, Optional

from pyrogram import Client, filters
from pyrogram.types import ChatPermissions, Message, User

from eduu.config import prefix
from eduu.database import db, dbc
from eduu.utils import commands, require_admin, time_extract
from eduu.utils.consts import admin_status
from eduu.utils.localization import use_chat_lang


Expand All @@ -25,9 +26,6 @@ async def get_reason_text(c: Client, m: Message) -> Message:
return reason


admin_status = ["creator", "administrator"]


def check_if_antichannelpin(chat_id):
dbc.execute("SELECT antichannelpin FROM groups WHERE chat_id = ?", (chat_id,))
res = dbc.fetchone()[0]
Expand Down
3 changes: 2 additions & 1 deletion eduu/plugins/chats.py
Expand Up @@ -6,7 +6,8 @@

from eduu.utils import add_chat, chat_exists

# This is the first plugin run to guarantee that the actual chat is initialized in the DB.
# This is the first plugin run to guarantee
# that the actual chat is initialized in the DB.


@Client.on_message(group=-1)
Expand Down
4 changes: 1 addition & 3 deletions eduu/plugins/misc.py
Expand Up @@ -11,11 +11,9 @@

from eduu.config import log_chat, prefix
from eduu.utils import button_parser, commands
from eduu.utils.consts import http
from eduu.utils.consts import admin_status, http
from eduu.utils.localization import use_chat_lang

admin_status = ["creator", "administrator"]


@Client.on_message(filters.command("mark", prefix))
@use_chat_lang()
Expand Down
3 changes: 2 additions & 1 deletion eduu/plugins/sudos.py
Expand Up @@ -9,6 +9,7 @@
import sys
import traceback
from contextlib import redirect_stdout
from typing import Union

import speedtest
from meval import meval
Expand All @@ -20,7 +21,7 @@
from eduu.utils import set_restarted, sudofilter
from eduu.utils.localization import use_chat_lang

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


@Client.on_message(filters.command("sudos", prefix) & sudofilter)
Expand Down
3 changes: 1 addition & 2 deletions eduu/plugins/warns.py
Expand Up @@ -9,6 +9,7 @@
from eduu.config import prefix
from eduu.database import db, dbc
from eduu.utils import commands, require_admin
from eduu.utils.consts import admin_status
from eduu.utils.localization import use_chat_lang

from .admin import get_target_user
Expand Down Expand Up @@ -45,8 +46,6 @@ def set_warn_action(chat_id: int, action: Optional[str]):
count INTEGER)"""
)

admin_status = ["creator", "administrator"]


def get_warns(chat_id, user_id):
dbc.execute(
Expand Down
4 changes: 3 additions & 1 deletion eduu/utils/__init__.py
@@ -1,6 +1,8 @@
# SPDX-License-Identifier: MIT
# Copyright (c) 2018-2021 Amano Team

from typing import List

from .utils import (
EMOJI_PATTERN,
add_chat,
Expand All @@ -23,7 +25,7 @@
time_extract,
)

__all__ = [
__all__: List[str] = [
"commands",
"shell_exec",
"deEmojify",
Expand Down
20 changes: 12 additions & 8 deletions eduu/utils/consts.py
@@ -1,20 +1,24 @@
# SPDX-License-Identifier: MIT
# Copyright (c) 2018-2021 Amano Team

from typing import List

import httpx

group_types = ("group", "supergroup")
group_types: List[str] = ("group", "supergroup")

admin_status: List[str] = ["creator", "administrator"]

timeout = httpx.Timeout(40, pool=None)

http = httpx.AsyncClient(http2=True, timeout=timeout)


class Permissions:
can_be_edited = "can_be_edited"
delete_messages = "can_delete_messages"
restrict_members = "can_restrict_members"
promote_members = "can_promote_members"
change_info = "can_change_info"
invite_users = "can_invite_users"
pin_messages = "can_pin_messages"
can_be_edited: str = "can_be_edited"
delete_messages: str = "can_delete_messages"
restrict_members: str = "can_restrict_members"
promote_members: str = "can_promote_members"
change_info: str = "can_change_info"
invite_users: str = "can_invite_users"
pin_messages: str = "can_pin_messages"
4 changes: 2 additions & 2 deletions eduu/utils/localization.py
Expand Up @@ -13,7 +13,7 @@
from eduu.database import db, dbc
from eduu.utils.consts import group_types

enabled_locales = [
enabled_locales: List[str] = [
"ar-SA", # Arabic
"ckb-IR", # Sorani (Kurdish)
"de-DE", # German
Expand All @@ -39,7 +39,7 @@
"zh-CN", # Chinese (Simplified)
]

default_language = "en-GB"
default_language: str = "en-GB"


def set_db_lang(chat_id: int, chat_type: str, lang_code: str):
Expand Down

0 comments on commit c65c5be

Please sign in to comment.