-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommand.py
More file actions
49 lines (39 loc) · 1.98 KB
/
Copy pathcommand.py
File metadata and controls
49 lines (39 loc) · 1.98 KB
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
from telegram import Update
from telegram.constants import ParseMode
from telegram.ext import ContextTypes
import const
from admin import admin
from poem import Poem
class Command:
@staticmethod
async def general_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
"""Handles simple commands.
A simple command is a command that requires no processing, and we just send the desired response to the user.
"""
response = Command.get_general_commands_response(update.message.text[1:])
await context.bot.send_message(chat_id=update.effective_chat.id, text=response, parse_mode=ParseMode.HTML)
@staticmethod
def get_general_commands_response(command: str):
"""Retrieves the desired general command response from the const file."""
command_upper = command.upper()
if command_upper in const.__all__:
return getattr(const, command_upper)
else:
return const.INVALID_COMMAND
@staticmethod
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
"""Handles the start command.
Displays the welcome message to the user. If it is the first time the user is using the bot, we save the user
information. If the command contains a number as its parameter, we also display the poem related to that number.
"""
user_id = update.message.from_user.id
await context.bot.send_message(chat_id=update.effective_chat.id, text=const.START)
if context.args and len(context.args) == 1 and context.args[0].isnumeric():
poem_id = int(context.args[0])
await Poem.get_poem_by_id(poem_id, user_id, context, update.effective_message.id)
@staticmethod
@admin
async def sendtoall(update: Update, context: ContextTypes.DEFAULT_TYPE):
"""Sends the broadcast introduction message to the admin user."""
await context.bot.send_message(update.effective_chat.id, text=const.SEND_YOUR_MESSAGE)
return 0