Skip to content

Commit

Permalink
Add smart plugins. (#28)
Browse files Browse the repository at this point in the history
* plugins

* plugins

* add handlers attr for plugins

* finish smart-plugins

* auto load when run

* add filters at first

* add plugins example
  • Loading branch information
z44d authored Jul 14, 2024
1 parent 9200ea5 commit e5742c1
Show file tree
Hide file tree
Showing 5 changed files with 341 additions and 128 deletions.
8 changes: 8 additions & 0 deletions examples/smart_plugins/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import logging
from tgram import TgBot

logging.basicConfig(level=logging.DEBUG)

bot = TgBot("API_TOKEN_HERE", parse_mode="Markdown", plugins="./plugins")

bot.run_for_updates()
7 changes: 7 additions & 0 deletions examples/smart_plugins/plugins/callback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from tgram import TgBot, filters
from tgram.types import CallbackQuery


@TgBot.on_callback_query(filters.regex("^fine$"))
def callback(bot: TgBot, query: CallbackQuery) -> bool:
return query.answer("Good to know!", show_alert=True)
13 changes: 13 additions & 0 deletions examples/smart_plugins/plugins/start.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from tgram import TgBot, filters

from tgram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton


@TgBot.on_message(filters.command("start") & filters.private)
async def on_start_message(bot: TgBot, m: Message) -> Message:
return await m.reply_text(
f"Hi {m.from_user.mention}!, How are you today?",
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("I'm fine", callback_data="fine")]]
),
)
Loading

0 comments on commit e5742c1

Please sign in to comment.