Skip to main content

Python module based on https://core.telegram.org/bots/api

Project description

Install :

pip install shitgram==0.1.dev6

How to use?

  • Config your bot :

from shitgram import Bot, types

API_TOKEN = "API_TOKEN_HERE"

bot = Bot(API_TOKEN)
  • Add handlers to recive updates from telegram:

  • Any update from telegram:
@bot.onUpdate
async def on_updates(bot: Bot, update: types.Update):
    print(update)
  • message and edited_message:
@bot.onMessage()
async def on_message(bot: Bot, message: types.Message):
    print(message)

@bot.onEditedMessage()
async def on_edited_message(bot: Bot, message: types.Message):
    print(message)

# Custom filter
def filter_admin(message: types.Message):
    admins = [123456789, 987654321]
    return bool(message.from_user.id in admins)

@bot.onMessage(func=filter_admin)
@bot.onEditedMessage(func=filter_admin)
async def on_custom_filter(bot: Bot, message: types.Message):
    print(message)

# Echo Bot
@bot.onMessage(func=lambda m: m.text)
async def echo(bot: Bot, message: types.Message):
    return await bot.sendMessage(
        message.chat.id,
        message.text,
        entities=message.entities
    )
  • Callback Queries ( No CallbackQuery Methods currently )
@bot.onCallbackQuery()
async def on_callback_query(bot: Bot, callback_query: types.CallbackQuery):
    return await bot.sendMessage(
        callback_query.message.chat.id,
        callback_query.data
    )
  • Inline Queries ( No InlineQuery Methods currently )
@bot.onInlineQuery()
async def on_inline_query(bot: Bot, inline_query: types.InlineQuery):
    print(inline_query)
  • Start the bot:

import asyncio
import logging

logging.basicConfig(level=logging.INFO)

asyncio.run(bot.start_polling())

# add allowed updates:
asyncio.run(bot.start_polling(allowed_updates=["message"]))
  • Start multiple bots:

import asyncio
import logging

from shitgram import run_multiple_bots, Bot, types, enums

logging.basicConfig(level=logging.INFO)

bot_1 = Bot("API_TOKEN_1")
bot_2 = Bot("API_TOKEN_2")

@bot_1.onMessage()
@bot_2.onMessage()
async  def on_message(bot: Bot, message: types.Message):
    return await bot.sendMessage(
        message.chat.id,
        (await bot.getMe()).mention.markdown,
        parse_mode=enums.ParseMode.MARKDOWN
    )

asyncio.run(run_multiple_bots([bot_1, bot_2]))

LICENSE :

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shitgram-0.1.dev6.tar.gz (24.6 kB view details)

Uploaded Source

Built Distribution

shitgram-0.1.dev6-py3-none-any.whl (47.7 kB view details)

Uploaded Python 3

File details

Details for the file shitgram-0.1.dev6.tar.gz.

File metadata

  • Download URL: shitgram-0.1.dev6.tar.gz
  • Upload date:
  • Size: 24.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for shitgram-0.1.dev6.tar.gz
Algorithm Hash digest
SHA256 a96680d60aba545f438df99c1b97a80335231e75ab422fde5ec2d2ba2aa4a480
MD5 c160cf55f5fcdb6fa25a8b16041583ac
BLAKE2b-256 42297ec88291c14271220985c945d9d6c0077c52c5e5d7d4b3c6196f4ea405d2

See more details on using hashes here.

File details

Details for the file shitgram-0.1.dev6-py3-none-any.whl.

File metadata

  • Download URL: shitgram-0.1.dev6-py3-none-any.whl
  • Upload date:
  • Size: 47.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for shitgram-0.1.dev6-py3-none-any.whl
Algorithm Hash digest
SHA256 a3533ee00a5905c30e5fa94c62e530b1fcf738ffcfb94ecea878f2930c399e3d
MD5 51469fe2b198df8575b99ee8dc988ca3
BLAKE2b-256 7c2d2a26e5848207ffb824ae357310ff65caf77697aec8126141c0172904cbf0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page