-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdecoratorbot.py
52 lines (37 loc) · 1.26 KB
/
decoratorbot.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import logging
import os
from dotenv import load_dotenv
from swibots import (
BotApp,
RegisterCommand,
BotContext,
MessageEvent,
CallbackQueryEvent,
)
env_file = os.path.join(os.path.dirname(__file__), "..", "..", ".env")
load_dotenv(env_file)
TOKEN = os.getenv("TOKEN")
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# initialize the app and register commands
app = BotApp(
TOKEN, "A cool bot with annotations and everything you could possibly want :)"
).register_command(
[
RegisterCommand("test", "Test command", True),
RegisterCommand("echo", "Echoes the message", True),
RegisterCommand("buttons", "Shows buttons", True),
]
)
@app.on_message()
async def message_handler(ctx: BotContext[MessageEvent]):
m = await ctx.prepare_response_message(ctx.event.message)
m.message = f"Thank you! I received your message: {ctx.event.message.message}"
await ctx.send_message(m)
@app.on_callback_query()
async def query_callback_handler(ctx: BotContext[CallbackQueryEvent]):
m = await ctx.prepare_response_message(ctx.event.message)
m.message = f"Thank you! I received your callback: {ctx.event.callback_data}"
m.inline_markup = None
await ctx.edit_message(m)
app.run()