Beispiel #1
0
from telethon import custom, events
from garnet import FSMContext, MessageText
from garnet.router import Router
import logging
from const import CONSTANTS

logging.basicConfig(level=logging.ERROR)

user_router = Router(event=events.NewMessage())


@user_router.on(MessageText.commands('start'))
async def start_rout_hndlr(update: custom.Message, context: FSMContext):
    await update.reply(
        "__To Add This Bot To Your Channel Contact Me at @SwiftiesWorldBot__"
        "\n\n**Usage:**"
        "\n\tâž• Add this bot to the channel"
        "\n\n**Inspiration,**"
        "\n\tLike in blogs/sites, I will add a 'Click Here To Read More' at the bottom of posts. "
        "if user is interested in reading the full posts, they can read it by pressing 'Click Here To Read More' button"
        f"\n\n**Note**: "
        f"\n\t✅ Bot will only shrunk the posts if the post length is greater than {CONSTANTS.TRUNC+20}words",
        buttons=[[
            custom.Button.url(text="🤖 Contact Developer",
                              url='t.me/theswiftie13')
        ],
                 [
                     custom.Button.url(text="Join Channel",
                                       url='t.me/Taylorswift13fanpage')
                 ]])
Beispiel #2
0
# // genders buttons
buttons = (
    (custom.Button.text("Abuser", resize=True), ),
    (custom.Button.text("Dishwasher"), ),
    (custom.Button.text("Cat"), ),
)

# /*
#  * get configurations from environment variable
#  * look pomegranate.TelegramClient::Env for more
#  */
bot = TelegramClient.from_env().start_as_bot()


@bot.on(MessageText.commands("start"))
async def handler(update: custom.Message, context: FSMContext):
    await update.reply(f"Hello, please enter your name!")
    await context.set_state("stateName")


# // handle all /cancel's from any state if only state is not None
@bot.on(MessageText.commands("cancel"), state.every())
async def cancel_handler(update: custom.Message, context: FSMContext):
    await update.reply("Ok. Resetting!")
    await context.reset_state(with_data=True)


@bot.on(state.exact("stateName"))
async def name_handler(update: custom.Message, context: FSMContext):
    await context.set_data({"name": update.raw_text})
Beispiel #3
0
ATTEMPTS = 3
OWNER = "@uwinx"
PASSWORD1, PASSWORD2 = "OWO", "UWU"


async def reached_incorrect_pass_limit(*_, context: FSMContext) -> bool:
    return (await context.get_data() or {}).get("attempts", 0) >= ATTEMPTS


@bot.on(Filter(reached_incorrect_pass_limit, requires_context=True))
async def stop_propagation(*_):
    # block/kick whatever
    raise events.StopPropagation  # call StopPropagation as Handler registered first and blocking


@bot.on(~MessageText.between(PASSWORD1, PASSWORD2))
async def not_start_handler(_, context: FSMContext):
    attempts = (await context.get_data() or {}).get("attempts", 0)
    attempts += 1
    await context.update_data(attempts=attempts)
    await messages.reply(
        f"Password incorrect. Available: {ATTEMPTS - attempts}"
    )  # you can use contextvars magic here


@bot.on(MessageText.between(PASSWORD1, PASSWORD2))
async def correct_password(_, context: FSMContext):
    await messages.reply("Welcome!")
    await context.set_state("onStandBy")

Beispiel #4
0
# // genders in parallel universe buttons. just imagine 🤔
buttons = (
    (custom.Button.text("Abuser", resize=True), ),
    (custom.Button.text("Dishwasher"), ),
    (custom.Button.text("Cat"), ),
)

# /*
#  * get configurations from environment variable
#  * look garnet.TelegramClient::Env for more
#  */
bot = TelegramClient.from_env()


@bot.on(MessageText.commands("start"))
async def handler(update: custom.Message, context: FSMContext):
    await update.reply(f"Hello, please enter your name!")
    await context.set_state("stateName")


# // handle all /cancel's from any state if only state is not None
@bot.on(MessageText.commands("cancel"), CurrentState == any)
async def cancel_handler(update: custom.Message, context: FSMContext):
    await update.reply("Ok. Resetting!")
    await context.reset_state(with_data=True)


@bot.on(CurrentState == "stateName")
async def name_handler(update: custom.Message, context: FSMContext):
    await context.set_data({"name": update.raw_text})
Beispiel #5
0
PASSWORD1, PASSWORD2 = "OWO", "UWU"


async def is_reached_incorrect_pass_limit(event, context: FSMContext):
    if (await context.get_data() or {}).get("attempts", 0) >= 3:
        return True
    return False


@bot.on(Filter(is_reached_incorrect_pass_limit, requires_context=True))
async def stop_propagation(*event):
    # block/kick whatever
    raise events.StopPropagation


@bot.on(~MessageText.between(PASSWORD1, PASSWORD2))
async def not_start_handler(event, context: FSMContext):
    attempts = (await context.get_data() or {}).get("attempts", 0)
    attempts += 1
    await context.update_data(attempts=attempts)
    await event.reply(f"Password incorrect. Available: {3 - attempts}")


@bot.on(MessageText.between(PASSWORD1, PASSWORD2))
async def correct_password(event, context: FSMContext):
    await event.reply("Welcome!")
    await context.set_state("onStandBy")


@bot.on(state.exact("onStandBy") & MessageText.commands("cats", prefixes="./"))
async def menu(event):
from telethon import custom, events
from garnet import FSMContext, MessageText
from garnet.router import Router
import logging
from const import CONSTANTS

logging.basicConfig(level=logging.ERROR)

user_router = Router(event=events.NewMessage())


@user_router.on(MessageText.commands("start"))
async def start_rout_hndlr(update: custom.Message, context: FSMContext):
    await update.reply(
        "__Currently, bot is in beta version__"
        "\n\n**Usage:**"
        "\n\t➕ Add this bot to the channel (preferrably, a test channel)"
        "\n\n**Inspiration,**"
        "\n\tLike in blogs/sites, I will add a showmore button at the bottom of posts. "
        "if user is interested in reading the full posts, they can read it by pressing 'ShowMore' button"
        f"\n\n**Note**: "
        f"\n\t✅ Bot will only shrunk the posts if the post length is greater than {CONSTANTS.TRUNC+20}words",
        buttons=[
            [
                custom.Button.url(
                    text="🤖 Other Awesome bots", url="https://t.me/ys0seri0us_bots/2"
                )
            ],
            [
                custom.Button.url(text="🛠", url="https://t.me/PostAppender_Bot"),
                custom.Button.url(text="🔊", url="https://t.me/PostBroadcasterobot"),