Post

Talk Back Bot

بات حاظر جواب

به این بات یکی از متن های تعریف شده رو بفرستید تا جواب بده
و قابلیت یادگیری با استفاده از دستور مثل زیر رو داره:
/learn text reply

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from balethon import Client

bot = Client("TOKEN")

replies = {
    "hello": "Hi",
    "hi": "Hey!",
    "how are you": "Fine thanks! And You?",
    "bot": "Yes, how can I help you?",
    "haha": "What's so funny?",
    "bye": "Good bye!"
}


@bot.on_command()
async def start(*, message):
    texts = "\n".join(replies)
    await message.reply(
        f"Send one of the following texts to me and I will reply:\n{texts}"
    )


@bot.on_command()
async def learn(text, reply, *, message):
    replies[text] = reply

    await message.reply(
        f"I got it\nWhen someone says {text}, I say {reply}"
    )


@bot.on_message(lambda client, event: event.text in replies)
async def reply_to_text(message):
    await message.reply(replies[message.text])


bot.run()
This post is licensed under CC BY 4.0 by the author.