Skip to main content

newmod

A monkeypatcher add-on for Newgram

Introduction

newmod is a compilation of utils i developed for extend my personal use of Newgram. Then i started to use it and more bots and now i published it to make it easier to be installed in new projects. It works together with newgram, this is not a fork nor modded version. It does monkey patching to add features to Newgram classes.

IMPORTANT: you should have installed asyncio newgram.

Usage

Import newmod at least one time in your script, so you'll be able to use modified newgram in all files of the same proccess. Example:

# config.py
import newmod.listen
from newgram import Client

app = Client('my_session')
# any other .py
from config import app
# no need to import newmod again, newgram is already monkeypatched globally (at the same proccess)

I separated the patches between packages to allow you to import only what you want. The __init__.py of each package does the monkeypatch automatically as soon as they are imported (except for newmod.helpers, which provides classes and functions that should be explicitely imported).

newmod.listen

Just import it, it will automatically do the monkeypatch and you'll get these new methods:

  • await newgram.Client.listen(chat_id, filters=None, timeout=30) Awaits for a new message in the specified chat and returns it You can pass Update Filters to the filters parameter just like you do for the update handlers. e.g. filters=filters.photo & filters.bot

  • await newgram.Client.ask(text, chat_id, filters=None, timeout=30) Same of .listen() above, but sends a message before awaiting You can pass custom parameters to its send_message() call. Check the example below.

  • The bound methods Chat.listen, User.listen, Chat.ask and User.ask

Example:

from newmod import listen # or import newmod.listen
from newgram import Client
client = Client(...)
...
    answer = await client.ask(chat_id, '*Send me your name:*', parse_mode='Markdown')
    await client.send_message(chat_id, f'Your name is: {answer.text}')    

newmod.filters

Import it and the following Update Filters will be monkeypatched to newgram.filters:

  • filters.dice A dice message.

This project may include snippets of Newgram code

Licensed under the terms of the GNU Lesser General Public License v3 or later (LGPLv3+)

Release files for newmod 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for newmod 0.0.3
File Size Uploaded
newmod-0.0.3.tar.gz 20.5 kB Details

Release files / newmod-0.0.3.tar.gz

Download URL newmod-0.0.3.tar.gz
Size 20.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0ef11888f85dc8fde3467d2d4b84dd6bff0e630c6d79853d2cdc65088996a9ee
BLAKE2b-256 checksum
How to use checksums
8e8a5164a61576b4a5ca4f990f28897931dd6ea72c7f3edc84b0b39568b50580
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.7

Release history Release notifications | RSS feed

This release

0.0.3 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page