Git Product home page Git Product logo

userbot's People

Contributors

dependabot[bot] avatar evgfilim1 avatar krau5 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

userbot's Issues

Allow running commands from drafts

This will require wrapping the original message class from Pyrogram into something that will behave almost the same but will support drafts.

Handling requires registering RawUpdateHandler like this:

client.add_handler(
RawUpdateHandler(partial(react2ban_raw_reaction_handler, storage=storage)),
group=1,
)

Usage:
async def react2ban_raw_reaction_handler(
client: Client,
update: base.Update,
users: dict[int, types.User],
_: dict[int, types.Chat | types.Channel],
*,
storage: Storage,
) -> None:
if not isinstance(update, types.UpdateMessageReactions):
raise ContinuePropagation() # don't consume an update here, it's not for this handler

UpdateDraftMessage will be received when something is saved as a draft:
https://docs.pyrogram.org/telegram/types/update-draft-message#pyrogram.raw.types.UpdateDraftMessage

Implementing this may open new abilities like silent execution without having to edit sources, looped execution, etc.

Runtime hooks (triggers)

.rhadd <reply> <key> <text...> — adds a runtime trigger <key> on <text> that sends <reply>

.rhs — list all runtime triggers

.rhdel <key> — removes a runtime trigger

Bot stats

.stats — show some stats for the bot and the user

Example output:

⚙ Uptime: 1h2m3s
⭐️ Doesn't have premium
💬 Total chats: 1000
💬 Unread: 2
📥 Archived chats: 50
👤 Private chats: 400
👥 Groups: 400
📢 Channels: 200
🎞 Saved GIFs: 300
📑 Saved stickers: 200
🕒 Archived stickers: 300
...

Take appropriate icons from https://t.me/addemoji/IconsInTg for premium users
image

`prefix` isn't honored in some places

  • When looking for .help command:
    if args := command.args:
    for h in self._handlers:
    for cmd in h.commands:
    match cmd:
    case re.Pattern() as pattern:
    matches = pattern.fullmatch(args) is not None
    case str():
    matches = cmd == args
    case _:
    raise AssertionError(f"Unexpected command type: {type(cmd)}")
    if matches:
    usage = h.format_usage(full=True)
    return _("<b>Help for {args}:</b>\n{usage}").format(
    args=html.escape(args),
    usage=html.escape(usage),
    )
  • When checking command conflicts while registering:
    for handler in self._handlers:
    for cmd in handler.commands:
    if cmd in commands:
    raise ValueError(f"Duplicate command: {cmd}")

Clear service messages for a period

.clearsvcs [period] — Clear service messages for a period.

period can be a timedelta (e.g. "1d3h") or a time string (e.g. "12:30" or "2022-12-31_23:59").
If period is not specified, assume "1d"

userbot/userbot/utils.py

Lines 109 to 117 in 4bfb02f

def parse_timespec(now: datetime, timespec: str) -> datetime:
"""Parse a time specification and return target datetime.
The time specification is a string of the form:
– HH:MM
– YYYY-MM-DD_HH:MM
– N[smhdwy]
– N[smhdwy]N[smhdwy]...
"""

Message edits may be skipped by clients

Some clients have a bug when they for some reason don't update a message edited by userbot. Adding a small (~0.1–0.25s) delay would help, I guess.

Chat:
Not edited message
Admin log:
Admin log with edit event

Search docs

.pydoc <query> — Search Python documentation

.tbapidoc <query> — Search Telegram Bot API documentation

Ban until specific date

Same behavior as in .remind and .remindme

userbot/userbot/utils.py

Lines 109 to 117 in 4bfb02f

def parse_timespec(now: datetime, timespec: str) -> datetime:
"""Parse a time specification and return target datetime.
The time specification is a string of the form:
– HH:MM
– YYYY-MM-DD_HH:MM
– N[smhdwy]
– N[smhdwy]N[smhdwy]...
"""

Integrate mypy

Start here

diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml
index 833fcde..77cf54c 100644
--- a/.github/workflows/lint.yaml
+++ b/.github/workflows/lint.yaml
@@ -45,6 +45,7 @@ jobs:
         run: |
           isort --check --diff userbot
           black --check --diff userbot
+          mypy userbot
 
       - name: Check message catalog template is up-to-date
         run: python potctl.py --diff
diff --git a/dev-requirements.txt b/dev-requirements.txt
index 390cec5..41f7d7e 100644
--- a/dev-requirements.txt
+++ b/dev-requirements.txt
@@ -1,3 +1,5 @@
 Babel~=2.10.3
 black~=22.10.0
 isort~=5.10.1
+mypy~=0.982
+types-aiofiles~=22.1.0
diff --git a/pyproject.toml b/pyproject.toml
index bcb9333..e1c88f9 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -7,3 +7,52 @@ line_length = 100
 py_version = '310'  # (2022-10-28) isort 5.10.1 doesn't support 3.11
 profile = 'black'
 known_first_party = ['userbot']
+
+[tool.mypy]
+# Config file
+warn_unused_configs = true
+
+# Import discovery
+namespace_packages = true
+
+# Platform configuration
+python_version = "3.11"
+
+# Disallow dynamic typing
+#disallow_any_explicit = true
+disallow_any_generics = true
+disallow_subclassing_any = true
+
+# Untyped definitions and calls
+disallow_untyped_calls = true
+disallow_untyped_defs = true
+disallow_incomplete_defs = true
+check_untyped_defs = true
+disallow_untyped_decorators = true
+
+# None and Optional handling
+no_implicit_optional = true
+
+# Configuring warnings
+warn_redundant_casts = true
+warn_unused_ignores = true
+warn_return_any = true
+warn_unreachable = true
+
+# Miscellaneous strictness flags
+local_partial_types = true
+# Pyrogram doesn't explicitly export some attributes, so this has to be disabled
+no_implicit_reexport = false
+strict_equality = true
+strict = true
+
+# Configuring error messages
+show_error_context = true
+show_column_numbers = true
+show_error_codes = true
+pretty = true
+
+# Advanced options
+plugins = [
+]
+warn_incomplete_stub = true

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.