Пример #1
0
def handle_member_join(request, event, destination):
    cdata = ChannelManager.get_channel_token(
        Platform.LINE, LineApiUtils.get_channel_id(event), auto_register=True)
    joined_names = []

    for user in event.joined.members:
        uid = user.user_id

        udata_result = RootUserManager.get_root_data_onplat(Platform.LINE, uid)

        if udata_result.success and cdata:
            ProfileManager.register_new_default_async(cdata.id,
                                                      udata_result.model.id)

            uname = RootUserManager.get_root_data_uname(
                udata_result.model.get_oid(), cdata).user_name
            if uname:
                joined_names.append(uname)

    LINE.temp_apply_format(event_dest_fmt,
                           logging.INFO,
                           "LINE Join Group.",
                           extra={
                               ExtraKey.Event: event,
                               ExtraKey.Destination: destination
                           })

    LineApiWrapper.reply_text(
        event.reply_token,
        _("{} joined the group.").format(" & ".join(joined_names)))
Пример #2
0
def handle_msg_main(request, event, destination):
    LINE.temp_apply_format(event_dest_fmt, logging.INFO, "Message event",
                           extra={ExtraKey.Event: event, ExtraKey.Destination: destination})

    if isinstance(event.message, TextMessage):
        msg_type = MessageType.TEXT
    elif isinstance(event.message, ImageMessage):
        msg_type = MessageType.IMAGE
    elif isinstance(event.message, VideoMessage):
        msg_type = MessageType.VIDEO
    elif isinstance(event.message, AudioMessage):
        msg_type = MessageType.AUDIO
    elif isinstance(event.message, LocationMessage):
        msg_type = MessageType.LOCATION
    elif isinstance(event.message, StickerMessage):
        msg_type = MessageType.LINE_STICKER
    elif isinstance(event.message, FileMessage):
        msg_type = MessageType.FILE
    else:
        msg_type = MessageType.UNKNOWN

    fn = fn_dict.get(msg_type)

    try:
        if fn:
            fn(request, event, destination)
        else:
            handle_msg_default(request, event, destination)
    except Exception as e:
        handle_error(e, f"Error occurred in handle_msg_main. Handle function: {fn.__qualname__}", event, destination)
Пример #3
0
def handle_unfollow(request, event, destination):
    LINE.temp_apply_format(event_dest_fmt,
                           logging.INFO,
                           "Bot been unfollowed.",
                           extra={
                               ExtraKey.Event: event,
                               ExtraKey.Destination: destination
                           })
Пример #4
0
def handle_msg_default(request, event, destination):
    LINE.temp_apply_format(event_dest_fmt,
                           logging.INFO,
                           "Unhandled LINE message event.",
                           extra={
                               ExtraKey.Event: event,
                               ExtraKey.Destination: destination
                           })
Пример #5
0
def handle_join(request, event, destination):
    ChannelManager.register(Platform.LINE, LineApiUtils.get_channel_id(event))
    LINE.temp_apply_format(event_dest_fmt,
                           logging.INFO,
                           "Bot joined a group.",
                           extra={
                               ExtraKey.Event: event,
                               ExtraKey.Destination: destination
                           })
Пример #6
0
def handle_member_main(request, event, destination):
    if isinstance(event, MemberJoinedEvent):
        handle_member_join(request, event, destination)
    elif isinstance(event, MemberLeftEvent):
        handle_member_left(request, event, destination)
    else:
        LINE.temp_apply_format(event_dest_fmt,
                               logging.INFO,
                               "Unhandled LINE member event.",
                               extra={
                                   ExtraKey.Event: event,
                                   ExtraKey.Destination: destination
                               })
Пример #7
0
def handle_self_main(request, event, destination):
    if isinstance(event, FollowEvent):
        handle_follow(request, event, destination)
    elif isinstance(event, UnfollowEvent):
        handle_unfollow(request, event, destination)
    elif isinstance(event, JoinEvent):
        handle_join(request, event, destination)
    elif isinstance(event, LeaveEvent):
        handle_leave(request, event, destination)
    else:
        LINE.temp_apply_format(event_dest_fmt,
                               logging.INFO,
                               "Unahndled bot self event.",
                               extra={
                                   ExtraKey.Event: event,
                                   ExtraKey.Destination: destination
                               })
Пример #8
0
def handle_member_left(request, event, destination):
    for user in event.left.members:
        uid = user.user_id

        udata_result = RootUserManager.get_root_data_onplat(Platform.LINE, uid)
        cdata = ChannelManager.get_channel_token(
            Platform.LINE,
            LineApiUtils.get_channel_id(event),
            auto_register=True)

        if udata_result.success and cdata:
            ProfileManager.mark_unavailable_async(cdata.id,
                                                  udata_result.model.id)

    LINE.temp_apply_format(event_dest_fmt,
                           logging.INFO,
                           "LINE Left Group.",
                           extra={
                               ExtraKey.Event: event,
                               ExtraKey.Destination: destination
                           })