# Path: tg_bot/modules/helper_funcs/string_handling.py
# def button_markdown_parser(txt: str, entities: Dict[MessageEntity, str] = None, offset: int = 0) -> (str, List):
#     markdown_note = markdown_parser(txt, entities, offset)
#     prev = 0
#     note_data = ""
#     buttons = []
#     for match in BTN_URL_REGEX.finditer(markdown_note):
#         # Check if btnurl is escaped
#         n_escapes = 0
#         to_check = match.start(1) - 1
#         while to_check > 0 and markdown_note[to_check] == "\\":
#             n_escapes += 1
#             to_check -= 1
# 
#         # if even, not escaped -> create button
#         if n_escapes % 2 == 0:
#             # create a thruple with button label, url, and newline status
#             buttons.append((match.group(2), match.group(3), bool(match.group(4))))
#             note_data += markdown_note[prev:match.start(1)]
#             prev = match.end(1)
#         # if odd, escaped -> move along
#         else:
#             note_data += markdown_note[prev:to_check]
#             prev = match.start(1) - 1
#     else:
#         note_data += markdown_note[prev:]
# 
#     return note_data, buttons


from enum import IntEnum, unique
from telegram import Message
from tg_bot.modules.helper_funcs.string_handling import button_markdown_parser




@unique
class Types(IntEnum):
    TEXT = 0
    BUTTON_TEXT = 1
    STICKER = 2
    DOCUMENT = 3
    PHOTO = 4
    AUDIO = 5
    VOICE = 6
    VIDEO = 7


def get_note_type(msg: Message):
    data_type = None
    content = None
    text = ""
    raw_text = msg.text or msg.caption
    args = raw_text.split(None, 2)  # use python's maxsplit to separate cmd and args
    note_name = args[1]

    buttons = []
    # determine what the contents of the filter are - text, image, sticker, etc
    if len(args) >= 3:
        offset = len(args[2]) - len(raw_text)  # set correct offset relative to command + notename

# Path: tg_bot/modules/helper_funcs/string_handling.py
# def button_markdown_parser(txt: str, entities: Dict[MessageEntity, str] = None, offset: int = 0) -> (str, List):
#     markdown_note = markdown_parser(txt, entities, offset)
#     prev = 0
#     note_data = ""
#     buttons = []
#     for match in BTN_URL_REGEX.finditer(markdown_note):
#         # Check if btnurl is escaped
#         n_escapes = 0
#         to_check = match.start(1) - 1
#         while to_check > 0 and markdown_note[to_check] == "\\":
#             n_escapes += 1
#             to_check -= 1
# 
#         # if even, not escaped -> create button
#         if n_escapes % 2 == 0:
#             # create a thruple with button label, url, and newline status
#             buttons.append((match.group(2), match.group(3), bool(match.group(4))))
#             note_data += markdown_note[prev:match.start(1)]
#             prev = match.end(1)
#         # if odd, escaped -> move along
#         else:
#             note_data += markdown_note[prev:to_check]
#             prev = match.start(1) - 1
#     else:
#         note_data += markdown_note[prev:]
# 
#     return note_data, buttons


# Path: tg_bot/modules/helper_funcs/msg_types.py
from enum import IntEnum, unique
from telegram import Message
from tg_bot.modules.helper_funcs.string_handling import button_markdown_parser





@unique
class Types(IntEnum):
    TEXT = 0
    BUTTON_TEXT = 1
    STICKER = 2
    DOCUMENT = 3
    PHOTO = 4
    AUDIO = 5
    VOICE = 6
    VIDEO = 7


def get_note_type(msg: Message):
    data_type = None
    content = None
    text = ""
    raw_text = msg.text or msg.caption
    args = raw_text.split(None, 2)  # use python's maxsplit to separate cmd and args
    note_name = args[1]

    buttons = []
    # determine what the contents of the filter are - text, image, sticker, etc
    if len(args) >= 3:
        offset = len(args[2]) - len(raw_text)  # set correct offset relative to command + notename

        text, buttons = button_markdown_parser(args[2], entities=msg.parse_entities() or msg.parse_caption_entities(),