-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolves #28: Add change emojis command #30
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -311,6 +311,55 @@ def del_sticker(bot: Bot, update: Update): | |||||
msg.reply_text(responses.REMOVE_STICKER_HELP) | ||||||
|
||||||
|
||||||
def change_emojis(bot: Bot, update: Update): | ||||||
msg: Message = update.message | ||||||
msg_type = get_msg_type(msg) | ||||||
user_id = msg.from_user.id | ||||||
response = responses.ERROR_MSG | ||||||
splittext = shlex.split(msg.text) | ||||||
|
||||||
# remove sticker from pack | ||||||
try: | ||||||
if msg_type == MsgType.REP_STICKER: | ||||||
pack_name = msg.reply_to_message.sticker.set_name | ||||||
sticker_id = msg.reply_to_message.sticker.file_id | ||||||
|
||||||
if pack_name is None: | ||||||
msg.reply_text('Não é possível remover o sticker de um pack inexistente.') | ||||||
return | ||||||
|
||||||
if not repository().check_permission(user_id, pack_name): | ||||||
msg.reply_text(responses.NO_PERMISSION) | ||||||
return | ||||||
|
||||||
bot.delete_sticker_from_set(sticker_id) | ||||||
# add_sticker(bot, update) | ||||||
msg = update.message | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isso já é feito na primeira linha deste método. |
||||||
|
||||||
except Exception as exc: | ||||||
msg.reply_text("Changing Emojis: Falhou") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
logger.error( | ||||||
"Exception changing emojis for sticker in pack. User id %d Pack %s", user_id, pack_name, | ||||||
) | ||||||
logger.error(exc) | ||||||
|
||||||
# get emojis | ||||||
if len(splittext) > 1: | ||||||
emoji = splittext[1] | ||||||
else: | ||||||
emoji = DEFAULT_EMOJI | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eu acho que não faz muito sentido ter um emoji default para este comando. Se o usuário não informar nenhum emoji seria melhor apenas retornar uma mensagem de erro. |
||||||
|
||||||
if msg_type not in [MsgType.STICKER, MsgType.REP_STICKER]: | ||||||
update.message.reply_text("Message is not a reply to a sticker.") | ||||||
return | ||||||
Comment on lines
+352
to
+354
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aí, com as mudanças de cima isso já seria feito no início., então o There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Concordo. |
||||||
|
||||||
if insert_sticker_in_pack(bot, msg, user_id, pack_name, emoji): | ||||||
return | ||||||
|
||||||
# check for errors | ||||||
update.message.reply_text(response) | ||||||
|
||||||
|
||||||
def set_default_pack(bot: Bot, update: Update): | ||||||
msg: Message = update.message | ||||||
user_id = msg.from_user.id | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Faltou dizer o que acontece quando a mensagem não é um reply para um sticker. Nesse caso, daria para tratar isso antes de tudo:
Outra coisa é usar o responses para as mensagens de resposta do bot. Coloquei já na sugestão como seria o uso delas, só faltaria adicionar o
CHANGE_EMOJIS_HELP
e oPACK_DOES_NOT_EXIST
noresponses.py
.