Пример #1
0
async def get_events():

    # Create a temporary event to compare to
    the_time = time.gmtime()

    the_date = "{month}/{day}/{year}".format(month = the_time.tm_mon, day = the_time.tm_mday,
                                        year = the_time.tm_year)
    the_time = "{hour}:{min}".format(hour = the_time.tm_hour, min = the_time.tm_min)

    curr_time = EventInfo(the_date, the_time, "")

    # Store events to be removed later
    to_remove = []

    # Loop through the most recents events to check if the task time has come
    for event in control_events.closest:

        # The event and the current time should be equal
        if curr_time.equal_events(event):

            alert = find_channel(client.guilds, event.group)
            
            # Try to send a reminder to the announcements channel
            await alert.send("REMINDER FOR THE FOLLOWING EVENT!")
            await alert.send(event.description)

            to_remove.append(event)

    # Remove all events that have now been used up
    for item in to_remove:
        control_events.closest.remove(item)

    # Grab events if the closest list is now empty
    if len(control_events.closest) == 0:
        control_events.grab_recent()
Пример #2
0
def message_edit(token, message_id, message):
    '''
    Function edits message with new message given
    '''
    u_id = get_u_id(token)

    channel_id = find_channel(message_id)

    owner = user_is_owner(u_id, channel_id)
    creator = message_creator(u_id, message_id)
    permission_id = permission(u_id)

    #checking if user has authorization to edit message
    if not creator and not owner and permission_id == 2:
        raise AccessError("user is not authorised to remove message")

    #checking if new message is empty strin
    no_message = False
    if message == "":
        no_message = True

    for channel in channels:
        for chan_messages in channel['messages']:
            if chan_messages['message_id'] == message_id:
                #removing message if empty string
                if no_message:
                    channel['messages'].remove(chan_messages)
                #chaning old message to new message
                else:
                    chan_messages['message'] = message

    return {}
Пример #3
0
def message_remove(token, message_id):
    '''
    Funtion remove message from channel given message and token
    '''
    u_id = get_u_id(token)

    channel_id = find_channel(message_id)

    m_id = message_exists(message_id)
    owner = user_is_owner(u_id, channel_id)
    creator = message_creator(u_id, message_id)
    permission_id = permission(u_id)

    #raising error if message doesnt exist
    if not m_id:
        raise InputError("Invalid message ID")
    #checking if user has authorization to remove message
    if not creator and not owner and permission_id == 2:
        raise AccessError("user is not authorised to remove message")
    #removing message from channel
    for channel in channels:
        for chan_messages in channel['messages']:
            if chan_messages['message_id'] == message_id:
                channel['messages'].remove(chan_messages)
                return {}
    return {}
Пример #4
0
def msg_remove(token, msg_id):
    global data
    remover = user_from_token(token)
    found_msg = find_msg(msg_id)
    # find the channel where the message belongs to
    msg_channel = find_channel(found_msg.in_channel)
    if found_msg.sender != remover.u_id:
        raise AccessError(
            description=
            'You do not have the permission to delete this message as you are not the sender!'
        )
    elif not check_channel_owner(msg_channel, remover.u_id):
        raise AccessError(
            description=
            'You do not have the permission as you are not the owner or admin of this channel!'
        )
    # no exception raised, then remove the message
    msg_channel.messages.remove(found_msg)
    return {}
Пример #5
0
def msg_send(token, msg, chan_id):
    global data
    sending_time = datetime.now().replace(tzinfo=timezone.utc).timestamp()
    sender = user_from_token(token)
    current_channel = find_channel(chan_id)
    if len(msg) > 1000:
        raise ValueError(description='Message is more than 1000 words!')
    elif check_channel_member(current_channel, sender.u_id) == False:
        raise AccessError(
            description=
            'You have not joined this channel yet, please join first!')
    else:
        # generate an unique id
        data['message_count'] += 1
        msg_id = data['message_count']
        # no exceptions raised, then add(send) the message to the current channel
        current_channel.messages.insert(
            0, Mesg(sender.u_id, sending_time, msg, msg_id, chan_id, False))
    return {'message_id': msg_id}
Пример #6
0
def msg_unpin(token, msg_id):
    global data
    unpinner = user_from_token(token)
    found_msg = find_msg(msg_id)
    msg_channel = find_channel(found_msg.in_channel)
    if check_channel_member(msg_channel, unpinner.u_id) == False:
        raise AccessError(
            description=
            'You can not unpin the message as you are not a member of the channel'
        )
    elif found_msg.is_pinned == False:
        raise ValueError(description='The message is already unpinned!')
    elif not check_slackr_admin(unpinner):
        raise ValueError(
            description=
            'You can not unpin the message as you are not an Admin of the channel'
        )
    # unpin the message if no exceptions raised
    found_msg.is_pinned = False
    return {}
Пример #7
0
def msg_edit(token, msg_id, new_msg):
    global data
    editor = user_from_token(token)
    found_msg = find_msg(msg_id)
    msg_channel = find_channel(found_msg.in_channel)
    # iter3 update: if the new msg is empty, delete the message
    if new_msg == '':
        msg_remove(token, msg_id)
    elif len(new_msg) > 1000:
        raise ValueError(description='Message is more than 1000 words!')
    elif found_msg.sender != editor.u_id:
        raise AccessError(
            description=
            'You do not have the permission to edit this message as you are not the sender!'
        )
    elif not check_channel_owner(msg_channel, editor.u_id):
        raise AccessError(
            description=
            'You do not have the permission as you are not the owner or admin of this channel or Slackr!'
        )
    # edit the message if no exceptions raiseds
    found_msg.message = new_msg
    return {}
Пример #8
0
def message_unpin(token, message_id):
    '''
    Given a message within a channel, remove its mark as unpinned
    '''
    u_id = get_u_id(token)

    channel_id = find_channel(message_id)
    message = find_message(channel_id, message_id)

    m_id = message_exists(message_id)
    auth_user = user_in_channel(u_id, channel_id)

    # Input errors for invalid / already unpinned messages
    if not m_id:
        raise InputError("Invalid message ID")
    if not message['is_pinned']:
        raise InputError("Message is already unpinned")
    # Access error for non-owners / unauthorised users
    if not auth_user:
        raise AccessError("User is not a member of the channel")

    message['is_pinned'] = False

    return {}
Пример #9
0
def message_pin(token, message_id):
    '''
    Given a message within a channel, mark it as "pinned" to be given special display treatment by the frontend
    '''
    u_id = get_u_id(token)

    channel_id = find_channel(message_id)
    message = find_message(channel_id, message_id)

    m_id = message_exists(message_id)
    auth_user = user_in_channel(u_id, channel_id)

    # Input errors for invalid / already pinned messages
    if not m_id:
        raise InputError("Invalid message ID")
    if message['is_pinned']:
        raise InputError("Message is already pinned")
    # Access error for non-owners / unauthorised users
    if not auth_user:
        raise AccessError("User is not a member of the channel")

    message['is_pinned'] = True

    return {}