def get_pull_requests(type):
    github_configs = config_loader.load_configs().get("github")
    github_secrets = secret_loader.load_secrets().get("github")

    response_json = []
    headers = {"Authorization": github_secrets.get("github_token")}
    for repo in github_configs.get("github_repos"):
        url_string = github_configs.get("base_url") + github_configs.get(
            "github_org") + "/" + repo + github_configs.get("tail_url")
        resp = requests.get(url_string, headers=headers, verify=False)
        repo_pulls = resp.json()
        for repo_pull in repo_pulls:
            temp_json = {
                "title": repo_pull['title'],
                "user": repo_pull['user']['login'],
                "repo": repo,
                "url": repo_pull['html_url'],
                "approved": get_pull_request_status(github_secrets.get("github_token"), repo_pull['url'])
            }

            if type == "approved" and temp_json.get("approved"):
                response_json.append(temp_json)
            elif type == "open" and not temp_json.get("approved"):
                response_json.append(temp_json)
            else:
                response_json.append(temp_json)

    return response_json
def yafnag_rest_call(first_letter, number_of_names):
    yafnag_configs = config_loader.load_configs().get("yafnag")

    data = [
        ('pmin', yafnag_configs.get("min_character_count")),
        ('pmax', yafnag_configs.get("max_character_count")),
        ('qte', number_of_names),
        ('first', first_letter),
        ('oks', ''),
        ('lg', 'e'),
        ('_', ''),
    ]

    response_json = requests.post(yafnag_configs.get("base_url"),
                                  data=data).json()
    names = parse_yafnag_response(response_json)
    return names
import random

from utterances import cached_responses
from utterances import hidden_gems
from utterances import known_utterances

from external_services import bathroombuddy_integration
from configs import config_loader

configs = config_loader.load_configs()


def known_utterance_handler(slack_client, message, channel):
    if "lyrics" in message:
        message_string = bathroombuddy_integration.song_lyrics(message)
        slack_client.api_call("chat.postMessage",
                              channel=channel,
                              text=message_string)
        return

    for entry in known_utterances.utterance_types:
        if entry.get("utterance") in message:
            message_string = get_utterance_response(message, entry.get("type"))
            slack_client.api_call("chat.postMessage",
                                  channel=channel,
                                  text=message_string)
            return


def get_utterance_response(message, utterance_type):
    if utterance_type == "help":
Esempio n. 4
0
from slackeventsapi import SlackEventAdapter
from slackclient import SlackClient
from flask import Flask, jsonify
import re

from configs import config_loader
from secrets import secret_loader

from utterances import hidden_gems
from utterances import known_utterances
from utterances import utterance_handler

app = Flask(__name__)

bathroom_buddy_slack_secrets = secret_loader.load_secrets().get("slack")
bathroom_buddy_configs = config_loader.load_configs()

slack_events_adapter = SlackEventAdapter(
    bathroom_buddy_slack_secrets.get("slack_signing_secret"), "/slack/events",
    app)
slack_client = SlackClient(bathroom_buddy_slack_secrets.get("slack_bot_token"))


@app.route("/alive")
def alive():
    return jsonify({"health": "Bathroom Buddy is ALIIIIIIVE."})


@app.route("/configs")
def configs():
    return jsonify(bathroom_buddy_configs)