Example #1
0
def onboarding(user, channel=None):
    """
    Onboards a new user or a existing user that hasn't been onboarded yet.
    """

    # Check if user is in the database
    if utils.query_user_exists(user):
        return

    # Retrieve admin status from slack
    user_info = client.users_info(user=user)
    is_admin = user_info["user"]["is_admin"]
    is_owner = user_info["user"]["is_owner"]

    # Add user to the database
    utils.add_new_user(user, is_admin=is_admin, is_owner=is_owner)

    # Retrieve channel
    if channel is None:
        channel = client.conversations_open(users=[user])["channel"]["id"]

    # Post the message in the channel
    client.chat_postMessage(channel=channel,
                            text='IMPORTANT: CSESoc Slack Onboarding!!',
                            blocks=blocks.onboarding(user))
Example #2
0
def trivia_modal(trigger_id, user):
    user_info = client.users_info(user=user)['user']
    user_name = user_info['profile']['display_name_normalized'] if (
        user_info['profile']['display_name_normalized'] != ""
    ) else user_info['profile']['real_name_normalized']
    return client.views_open(trigger_id=trigger_id,
                             view=globalTriviaModal(user_name,
                                                    user))['view']['id']
Example #3
0
def trivia_leaderboard(channel, players):
    for player in players:
        player_info = client.users_info(user=player['player'])['user']
        player['name'] = player_info['profile']['display_name_normalized'] if (
            player_info['profile']['display_name_normalized'] != ""
        ) else player_info['profile']['real_name_normalized']
    client.chat_postMessage(channel=channel,
                            text="Trivia is over!",
                            blocks=triviaBoard(players))
Example #4
0
def reply_im(user, channel, message):
    if message.lower() not in greetings:
        return
    user_info = client.users_info(user=user)['user']
    user_name = user_info['profile']['display_name_normalized'] if (
        user_info['profile']['display_name_normalized'] != ""
    ) else user_info['profile']['real_name_normalized']
    message = f"Hi {user_name}, it's me slackbot!"
    client.chat_postMessage(channel=channel,
                            text=message,
                            blocks=imBlock(user_name))
Example #5
0
def reply_mention(user, channel):
    user_info = client.users_info(user=user)['user']
    user_name = user_info['profile']['display_name_normalized'] if (
        user_info['profile']['display_name_normalized'] != ""
    ) else user_info['profile']['real_name_normalized']
    channel_info = client.conversations_info(channel=channel)['channel']
    channel_name = channel_info['name']
    message = f"Hi {user_name}, it's me slackbot!"
    client.chat_postMessage(channel=channel,
                            text=message,
                            blocks=mentionBlock(
                                user_name,
                                channel_name,
                                is_channel=channel_info['is_channel']))
Example #6
0
def trivia_response_notify(user, channel, player, response):
    player_info = client.users_info(user=player)['user']
    player_name = player_info['profile']['display_name_normalized'] if (
        player_info['profile']['display_name_normalized'] != ""
    ) else player_info['profile']['real_name_normalized']
    if response:
        client.chat_postEphemeral(
            user=user,
            channel=channel,
            text=f"{player_name} accepted your trivia invite")
    else:
        client.chat_postEphemeral(
            user=user,
            channel=channel,
            text=f"{player_name} rejected your trivia invite")
Example #7
0
def karma_message(channel_id):
    toppers = utils.get_top_karma()
    # display name, profile picture, karma count
    leaders = []
    for user in toppers:
        player_info = client.users_info(user=user.id)['user']
        player_name = player_info['profile']['display_name_normalized'] if (
            player_info['profile']['display_name_normalized'] != ""
        ) else player_info['profile']['real_name_normalized']
        leaders.append({
            'name': player_name,
            'karma': user.karma,
            'pfp': player_info['profile']['image_72']
        })
    client.chat_postMessage(channel=channel_id,
                            text="Karma boards",
                            blocks=karmaBoard(leaders))
Example #8
0
def help_modal(trigger_id, user):
    user_info = client.users_info(user=user)['user']
    user_name = user_info['profile']['display_name_normalized'] if (
        user_info['profile']['display_name_normalized'] != ""
    ) else user_info['profile']['real_name_normalized']
    client.views_open(trigger_id=trigger_id, view=helpModal(user_name))