예제 #1
0
def add_new_member(payload, web_client, *args, **kwargs):
    user_id = payload['user']
    if user_id != cfg.bot_info['user_id']:
        """case when new member was added"""
        web_client.chat_postMessage(**HelloMsg(user_id)())
        web_client.chat_postMessage(**ModuleMsg(user_id)())

        data_base = DataBase()
        data_base.add_user(**payload)
        data_base.end_work()
    else:
        """case when bot was added [need to specify correct bot_user_id if config.py]"""
        answer = web_client.conversations_members(channel=payload['channel'])
        print(f'join action return data: {answer}')

        if answer.get('members') is not None:
            data_base = DataBase()
            for member in answer['members']:
                if member != cfg.bot_info['user_id']:
                    web_client.chat_postMessage(**HelloMsg(member)())
                    web_client.chat_postMessage(**ModuleMsg(member)())

                    data_base.add_user(user=member)

            data_base.end_work()
예제 #2
0
def module_check(payload, web_client):
    module_number = int(re.findall(r'\d+', payload['actions'][0]['text']['text'])[-1])

    """add to payload -> to form dict -> to pass it to the DataBase method (with user data)"""
    sql_data = {'user': payload['user']['id'],
                'module': module_number}

    data_base = DataBase()
    data_base.update_module(**sql_data)
    data_base.end_work()

    web_client.chat_postMessage(**ThxMessage(payload['user']['id'])('modules', module_number))
    """response to the user with correct module selected"""
예제 #3
0
def task_done(payload, web_client, *args, **kwargs):
    lead_user = payload.get('item_user')

    check_user = payload.get('user')

    if check_user != lead_user:
        data_base = DataBase()
        data_base.update_points(user=lead_user)
        data_base.end_work()

        web_client.chat_postMessage(
            **AlertMessage(lead_user).success_message())
    else:
        web_client.chat_postMessage(**AlertMessage(check_user)())
예제 #4
0
def bot_tag(payload, web_client, *args, **kwargs):
    """get author user id [user if new thread or parent_user_id if old thread]"""
    author_user_id = payload.get('user', '') if payload.get('parent_user_id') is None \
                                             else payload.get('parent_user_id')
    """get randomly chosen user for answering with module > author_user_id.module"""
    data_base = DataBase()
    lead_user = data_base.get_lead_user(user=author_user_id)
    data_base.end_work()

    reply_data = {
        'thread_ts':
        payload.get('ts', '')
        if payload.get('thread_ts') is None else payload.get('thread_ts'),
        'lead_user':
        lead_user if lead_user is not None else '',
    }

    web_client.chat_postMessage(
        **(HelloMsg(payload.get('channel', '')).please_message(**reply_data)))