mirror of
https://github.com/miloszowi/everyone-mention-telegram-bot.git
synced 2025-05-20 17:24:06 +00:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
44ecc307e3 | ||
|
fca6dd6f80 | ||
|
eeb9fe5c3a | ||
|
12a1c08866 | ||
|
e44f4b75a5 | ||
|
e242584974 | ||
|
878091deae |
@ -1,6 +1,12 @@
|
|||||||
# Change Log
|
# Change Log
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## [0.3.2] - 28.02.2023
|
||||||
|
### Changed
|
||||||
|
- fixed bug with missing '+' in replier
|
||||||
|
## [0.3.1] - 28.02.2023
|
||||||
|
### Changed
|
||||||
|
- fixed markdown replier to respect restricted characters provided in the [api docs](https://core.telegram.org/bots/api#markdownv2-style)
|
||||||
## [0.3.0] - 12.11.2021
|
## [0.3.0] - 12.11.2021
|
||||||
### Added
|
### Added
|
||||||
- Dynamic mentioning by `@` character
|
- Dynamic mentioning by `@` character
|
||||||
|
@ -23,6 +23,9 @@ class DynamicMentionHandler(AbstractHandler):
|
|||||||
self.chat_repository = ChatRepository()
|
self.chat_repository = ChatRepository()
|
||||||
|
|
||||||
def handle(self, update: Update, context: CallbackContext) -> None:
|
def handle(self, update: Update, context: CallbackContext) -> None:
|
||||||
|
if hasattr(update, 'message_reaction'):
|
||||||
|
return
|
||||||
|
|
||||||
users = self.chat_repository.get_users_for_group(self.inbound)
|
users = self.chat_repository.get_users_for_group(self.inbound)
|
||||||
|
|
||||||
Replier.markdown(update, MessageBuilder.mention_message(users))
|
Replier.markdown(update, MessageBuilder.mention_message(users))
|
||||||
|
@ -38,7 +38,7 @@ class InboundMessage:
|
|||||||
GroupNameValidator.validate(group_name)
|
GroupNameValidator.validate(group_name)
|
||||||
|
|
||||||
# done upon resolving a message handler action
|
# done upon resolving a message handler action
|
||||||
if '@' in message_content:
|
if '@' in message_content and '@everyone_mention_bot' not in message_content:
|
||||||
searched_message_part = [part for part in message_content.split(' ') if '@' in part][0]
|
searched_message_part = [part for part in message_content.split(' ') if '@' in part][0]
|
||||||
group_name = re.sub(r'\W+', '', searched_message_part).lower()
|
group_name = re.sub(r'\W+', '', searched_message_part).lower()
|
||||||
|
|
||||||
|
@ -8,24 +8,30 @@ from logger import Logger
|
|||||||
|
|
||||||
|
|
||||||
class Replier:
|
class Replier:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def interpolate(content: str, inbound_message: InboundMessage):
|
def interpolate(content: str, inbound_message: InboundMessage):
|
||||||
return content.format(
|
formatted = content.format(
|
||||||
mention_markdown(inbound_message.user_id, inbound_message.username),
|
mention_markdown(inbound_message.user_id, inbound_message.username),
|
||||||
inbound_message.group_name
|
inbound_message.group_name
|
||||||
)
|
)
|
||||||
|
|
||||||
|
telegramRestrictionCharacters = ['_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!']
|
||||||
|
|
||||||
|
for character in telegramRestrictionCharacters:
|
||||||
|
formatted.replace(character, r'\{character}')
|
||||||
|
|
||||||
|
return formatted
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def markdown(update: Update, message: str, reply_markup: Optional[InlineKeyboardMarkup] = None) -> None:
|
def markdown(update: Update, message: str, reply_markup: Optional[InlineKeyboardMarkup] = None) -> None:
|
||||||
try:
|
try:
|
||||||
update.effective_message.reply_markdown_v2(message, reply_markup=reply_markup)
|
update.effective_message.reply_markdown_v2(message, reply_markup=reply_markup)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
Logger.error(str(err))
|
Logger.error("replier.markdown error: " + str(err))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def html(update: Update, html: str, reply_markup: Optional[InlineKeyboardMarkup] = None) -> None:
|
def html(update: Update, html: str, reply_markup: Optional[InlineKeyboardMarkup] = None) -> None:
|
||||||
try:
|
try:
|
||||||
update.effective_message.reply_html(html, reply_markup=reply_markup, disable_web_page_preview=True)
|
update.effective_message.reply_html(html, reply_markup=reply_markup, disable_web_page_preview=True)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
Logger.error(str(err))
|
Logger.error("replier.html error: " + str(err))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user