<commit_before>from pymessenger.bot import Bot
from pymessenger import Element, Button

import utils
import requests


def get_user_from_profile_id(profile_id):
    string = "-" + str(profile_id)
    chat_id = utils.get_redis(string)
    cuser = utils.get_redis(chat_id)
    return cuser


class user():

    def __init__(self, user_json, user_id):

        self.first_name = user_json["first_name"]
        self.last_name = user_json["last_name"]
        self.profile_pic = user_json["profile_pic"]
        self.gender = user_json["gender"]
        self.id = user_id
        self.profile_id = ""
        self.in_chat = False
        self.looking_for_chat = False
        self.on_edge = False
        self.messages_left = 20
        self.showed_id = False
        self.needs_api_update = False

    def get_friendlist(self):

        req_string = ("https://graph.facebook.com/v2.8/me/friends?access_token="
                      + self.api_key)
        raw_list = requests.get(req_string).json()
        user_list = raw_list["data"]

        return user_list

    def set_api_key(self, code):

        raw_data = requests.get("https://graph.facebook.com/v2.8/oauth/" +
                                "access_token?client_id=" +
                                utils.config["fb_client_id"] +
                                "&redirect_uri=" + utils.config["website"] +
                                "/fb_callback?id=" + self.id + "&client_secret="
                                + utils.config["fb_client_secret"] + "&code=" +
                                code).json()

        access_token = raw_data["access_token"]

        self.api_key = access_token

        req_string = ("https://graph.facebook.com/v2.8/me?" +
                      "fields=id,name&access_token=" + self.api_key)

        self.profile_id = requests.get(req_string).json()["id"]
        utils.set_redis("-" + str(self.profile_id), self.id)

    def is_different(self, other_user):
        different = False
        if self.first_name != other_user.first_name:
            different = True
            self.first_name = other_user.first_name

        if self.last_name != other_user.last_name:
            different = True
            self.last_name = other_user.last_name

        if self.profile_pic != other_user.profile_pic:
            different = True
            self.profile_pic = other_user.profile_pic

        if self.gender != other_user.gender:
            different = True
            self.gender = other_user.gender

        return different

    def set_looking_for_chat(self):
        self.looking_for_chat = True
        utils.set_redis(self.id, self)

    def search_for_chat(self):
        friendlist = self.get_friendlist()

        for raw_friend in friendlist:

            cuser = get_user_from_profile_id(raw_friend["id"])

            if cuser != None and cuser.looking_for_chat:
                cuser.looking_for_chat = False
                cuser.in_chat = True
                cuser.in_chat_with = self.id
                utils.set_redis(cuser.id, cuser)

                self.looking_for_chat = False
                self.in_chat = True
                self.in_chat_with = cuser.id
                utils.set_redis(self.id, self)
                return cuser.id

        return False


def intro_message(bot, cuser):

    permission_url = ("https://www.facebook.com/v2.8/dialog/oauth?client_id=" +
                      utils.config["fb_client_id"] + "&scope=user_friends" +
                      "&response_type=code&redirect_uri=" +
                      utils.config["website"] + "/fb_callback?id=" + cuser.id)
    elements = []
    element = Element(title="Please give 20messages access to your friend list",
                      image_url=(
                          "https://20messages.com/images/access_card.png"),
                      subtitle="(We will never post as you)",
                      item_url=permission_url)
    elements.append(element)
    bot.send_generic_message(cuser.id, elements)
    bot.send_text_message(cuser.id, "Hello, welcome to 20messages!")
    bot.send_text_message(
        cuser.id, ("We let you talk with a random Facebook friend anonymously for" +
                   " 20 messages. Then you both vote to share your profile " +
                   "with each other. It only gets shared if both people agree" +
                   " to share it."))

    bot.send_text_message(cuser.id, "Please click the link above 🔝")


def after_registering(cuser):
    bot = Bot(utils.config["page_access_token"])

    bot.send_text_message(cuser.id, "You are now registered!")
    send_starting_gate(bot, cuser)<commit_msg>Cleaned up welcome message<commit_after>from pymessenger.bot import Bot
from pymessenger import Element, Button

import utils
import requests


def get_user_from_profile_id(profile_id):
    string = "-" + str(profile_id)
    chat_id = utils.get_redis(string)
    cuser = utils.get_redis(chat_id)
    return cuser


class user():

    def __init__(self, user_json, user_id):

        self.first_name = user_json["first_name"]
        self.last_name = user_json["last_name"]
        self.profile_pic = user_json["profile_pic"]
        self.gender = user_json["gender"]
        self.id = user_id
        self.profile_id = ""
        self.in_chat = False
        self.looking_for_chat = False
        self.on_edge = False
        self.messages_left = 20
        self.showed_id = False
        self.needs_api_update = False

    def get_friendlist(self):

        req_string = ("https://graph.facebook.com/v2.8/me/friends?access_token="
                      + self.api_key)
        raw_list = requests.get(req_string).json()
        user_list = raw_list["data"]

        return user_list

    def set_api_key(self, code):

        raw_data = requests.get("https://graph.facebook.com/v2.8/oauth/" +
                                "access_token?client_id=" +
                                utils.config["fb_client_id"] +
                                "&redirect_uri=" + utils.config["website"] +
                                "/fb_callback?id=" + self.id + "&client_secret="
                                + utils.config["fb_client_secret"] + "&code=" +
                                code).json()

        access_token = raw_data["access_token"]

        self.api_key = access_token

        req_string = ("https://graph.facebook.com/v2.8/me?" +
                      "fields=id,name&access_token=" + self.api_key)

        self.profile_id = requests.get(req_string).json()["id"]
        utils.set_redis("-" + str(self.profile_id), self.id)

    def is_different(self, other_user):
        different = False
        if self.first_name != other_user.first_name:
            different = True
            self.first_name = other_user.first_name

        if self.last_name != other_user.last_name:
            different = True
            self.last_name = other_user.last_name

        if self.profile_pic != other_user.profile_pic:
            different = True
            self.profile_pic = other_user.profile_pic

        if self.gender != other_user.gender:
            different = True
            self.gender = other_user.gender

        return different

    def set_looking_for_chat(self):
        self.looking_for_chat = True
        utils.set_redis(self.id, self)

    def search_for_chat(self):
        friendlist = self.get_friendlist()

        for raw_friend in friendlist:

            cuser = get_user_from_profile_id(raw_friend["id"])

            if cuser != None and cuser.looking_for_chat:
                cuser.looking_for_chat = False
                cuser.in_chat = True
                cuser.in_chat_with = self.id
                utils.set_redis(cuser.id, cuser)

                self.looking_for_chat = False
                self.in_chat = True
                self.in_chat_with = cuser.id
                utils.set_redis(self.id, self)
                return cuser.id

        return False


def intro_message(bot, cuser):

    permission_url = ("https://www.facebook.com/v2.8/dialog/oauth?client_id=" +
                      utils.config["fb_client_id"] + "&scope=user_friends" +
                      "&response_type=code&redirect_uri=" +
                      utils.config["website"] + "/fb_callback?id=" + cuser.id)
    elements = []
    element = Element(title="Please give 20messages access to your friend list",
                      image_url=(
                          "https://20messages.com/images/access_card.png"),
                      subtitle="(We will never post as you)",
                      item_url=permission_url)
    elements.append(element)
    bot.send_generic_message(cuser.id, elements)
    bot.send_text_message(cuser.id, "Hello, welcome to 20messages!")
    bot.send_text_message(
        cuser.id, ("We let you talk with a random Facebook friend anonymously for" +
                   " 20 messages. Then you both vote to share your profile " +
                   "with each other. It only gets shared if both people agree" +
                   " to share it."))

    bot.send_text_message(cuser.id, ("To start, we need access to your friend " +
                                     "list. Please click the link above 🔝"))


def after_registering(cuser):
    bot = Bot(utils.config["page_access_token"])

    bot.send_text_message(cuser.id, "You are now registered!")
    send_starting_gate(bot, cuser)
{'fraction_non_alphanumeric': 0.10143388210302709, 'fraction_numerical': 0.0038236856080722252, 'mean_word_length': 1.9489508299404947, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 10, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1395768', 'n_tokens_mistral': 2871, 'n_tokens_neox': 2728, 'n_words': 531}