-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathexample_02.py
176 lines (145 loc) · 5.24 KB
/
example_02.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import os
from swibots import (
BotApp,
BotCommand,
BotContext,
CallbackQueryEvent,
CommandEvent,
InlineMarkup,
InlineKeyboardButton,
regexp,
CommunityUpdatedEvent,
MessageEvent,
Message,
)
import logging
from dotenv import load_dotenv
env_file = os.path.join(os.path.dirname(__file__), "..", "..", ".env")
load_dotenv(env_file)
TOKEN = os.getenv("TOKEN")
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
app = BotApp(
TOKEN, "A cool bot with annotations and everything you could possibly want :)"
).set_bot_commands(
[
BotCommand("echo", "Echoes the message", True),
BotCommand("buttons", "Shows buttons", True),
BotCommand("buttonfull", "Shows buttons", True),
BotCommand("Back", "Shows buttons", True),
]
)
app = BotApp(
TOKEN, "A cool bot with annotations and everything you could possibly want :)"
).Bot_command(
[
BotCommand("echo", "Echoes the message", True),
BotCommand("buttons", "Shows buttons", True),
BotCommand("buttonfull", "Shows buttons", True),
BotCommand("Back", "Shows buttons", True),
]
)
@app.on_command("buttons")
async def buttons_handler(ctx: BotContext[CommandEvent]):
inline_keyboard = [
[
InlineKeyboardButton(text="Optioniablek", callback_data="option53"),
InlineKeyboardButton(text="Unitedstates", callback_data="option03"),
],
[
InlineKeyboardButton(text="Go Back on Press", callback_data="option543"),
],
[
InlineKeyboardButton(
text="Go Back on Press for more Movies haha", callback_data="option543"
),
],
]
inline_markup = InlineMarkup(
inline_keyboard=inline_keyboard,
)
await ctx.event.message.reply_text(
f"Please select an option:", inline_markup=inline_markup
)
@app.on_command("test")
async def test_handler(ctx: BotContext[CommandEvent]):
m = "Test command received"
await ctx.event.message.reply_text(m)
@app.on_command("buttonfull")
async def buttons_handler(ctx: BotContext[CommandEvent]):
message = f"Please select an option:"
inline_keyboard1 = [
[
InlineKeyboardButton(text="Option 1111", callback_data="option1"),
InlineKeyboardButton(text="Option 1112", callback_data="option2"),
InlineKeyboardButton(text="Option 1115", callback_data="option5"),
],
[
InlineKeyboardButton(text="Option 18", callback_data="option18"),
InlineKeyboardButton(text="Option 19", callback_data="option19"),
InlineKeyboardButton(text="Option 20", callback_data="option20"),
],
[
InlineKeyboardButton(text="Optioniablek", callback_data="option53"),
InlineKeyboardButton(text="Unitedstates", callback_data="option03"),
],
[
InlineKeyboardButton(text="Go Back on Press", callback_data="option543"),
],
[
InlineKeyboardButton(
text="Go Back on Press for more Movies haha", callback_data="option543"
),
],
]
inline_markup = InlineMarkup(
inline_keyboard=inline_keyboard1,
)
await ctx.event.message.reply_text(message, inline_markup=inline_markup)
@app.on_command("echo")
async def buttons_handler(ctx: BotContext[CommandEvent]):
message = f"Please select an option:"
inline_keyboard2 = [
[
InlineKeyboardButton(text="Option 1", callback_data="option1"),
InlineKeyboardButton(text="Option 2", callback_data="option2"),
],
[
InlineKeyboardButton(text="Option 3", callback_data="option3"),
InlineKeyboardButton(text="Option 4", callback_data="option4"),
InlineKeyboardButton(text="Option 5", callback_data="option5"),
InlineKeyboardButton(text="Option 6", callback_data="option6"),
],
]
inline_markup = InlineMarkup(
inline_keyboard=inline_keyboard2,
)
await ctx.event.message.reply_text(message, inline_markup=inline_markup)
@app.on_callback_query()
async def query_callback_handler(ctx: BotContext[CallbackQueryEvent]):
message = f"Thank you! I received your callback: {ctx.event.callback_data}"
inline_keyboard3 = [
[
InlineKeyboardButton(text="Option 1", callback_data="option1"),
InlineKeyboardButton(text="Option 2", callback_data="option2"),
],
[
InlineKeyboardButton(text="Back to Home", callback_data="back"),
],
]
inline_markup = InlineMarkup(
inline_keyboard=inline_keyboard3,
)
await ctx.event.message.reply_text(message, inline_markup=inline_markup)
@app.on_callback_query(regexp(r"back"))
async def callback_query_handler(ctx: BotContext[CallbackQueryEvent]):
await ctx.event.message.edit_text("thanks selected!")
@app.on_message()
async def message_handler(ctx: BotContext[MessageEvent]):
await ctx.event.message.reply_text(
f"Thank you! I received your message: {ctx.event.message.message}"
)
@app.on_community_update()
async def community_update_handler(ctx: BotContext[CommunityUpdatedEvent]):
print(ctx.event.community_id + " was updated")
app.run()