Exemplo n.º 1
0
 def __init__(self, PATH):
     self._PATH = PATH
     # TODO: Make sure this works
     with io.open(os.path.join(self._PATH, "users.json"),
                  encoding="utf8") as f:
         self.__USER_DATA = {u["id"]: User(u) for u in json.load(f)}
         slackbot = {
             "id": "USLACKBOT",
             "name": "slackbot",
             "profile": {
                 "image_24":
                 "https://a.slack-edge.com/0180/img/slackbot_24.png",
                 "image_32":
                 "https://a.slack-edge.com/2fac/plugins/slackbot/assets/service_32.png",
                 "image_48":
                 "https://a.slack-edge.com/2fac/plugins/slackbot/assets/service_48.png",
                 "image_72":
                 "https://a.slack-edge.com/0180/img/slackbot_72.png",
                 "image_192":
                 "https://a.slack-edge.com/66f9/img/slackbot_192.png",
                 "image_512":
                 "https://a.slack-edge.com/1801/img/slackbot_512.png",
             }
         }
         self.__USER_DATA.setdefault("USLACKBOT", User(slackbot))
Exemplo n.º 2
0
    def find_user(self, message):
        if message.get(
                "subtype",
                "").startswith("bot_") and "bot_id" in message and message[
                    "bot_id"] not in self.__USER_DATA:
            bot_id = message["bot_id"]
            logging.debug("bot addition for %s", bot_id)
            if "bot_link" in message:
                (bot_url,
                 bot_name) = message["bot_link"].strip("<>").split("|", 1)
            elif "username" in message:
                bot_name = message["username"]
                bot_url = None
            else:
                bot_name = None
                bot_url = None

            self.__USER_DATA[bot_id] = User({
                "user": bot_id,
                "real_name": bot_name,
                "bot_url": bot_url,
                "is_bot": True,
                "is_app_user": True
            })
        user_id = message.get("user") or message.get("bot_id")
        if user_id in self.__USER_DATA:
            return self.__USER_DATA.get(user_id)
        else:
            return User({"name": message.get("user_profile").get("real_name")})
        logging.error("unable to find user in %s", message)
Exemplo n.º 3
0
    def search_unknown_user(self, c_name, id):
        if not os.path.exists(os.path.join(self._PATH, c_name)):
            return None
        dir_path = os.path.join(self._PATH, c_name)
        if not os.path.isdir(dir_path):
            return None

        for json_file in os.listdir(dir_path):
            try:
                with io.open(os.path.join(dir_path, json_file),
                             encoding="utf8") as f:
                    for data in json.load(f):
                        if data["user"] != id:
                            continue
                        ret = {
                            "name":
                            data["user_profile"]["name"],
                            "real_name":
                            data["user_profile"]["real_name"],
                            "profile":
                            data["user_profile"],
                            "teams": [
                                data["team"], data["user_team"],
                                data["source_team"]
                            ]
                        }
                        return User(ret)
            except Exception as e:
                return None
        ret = {
            "name": "Unknown_{}".format(id),
            "display_name": "Unknown User({})".format(id),
            "real_name": "Unknown User({})".format(id)
        }
        return User(ret)
Exemplo n.º 4
0
 def __init__(self, PATH):
     self._PATH = PATH
     usr_file = None
     if os.path.exists(os.path.join(self._PATH, "users.json")):
         usr_file = "users.json"
     if os.path.exists(os.path.join(self._PATH, "org_users.json")):
         usr_file = "org_users.json"
     # TODO: Make sure this works
     with io.open(os.path.join(self._PATH, usr_file), encoding="utf8") as f:
         self.__USER_DATA = {u["id"]: User(u) for u in json.load(f)}
Exemplo n.º 5
0
    def find_user(self, message):
        if message.get("user") == "USLACKBOT":
            return User({"name": "slackbot"})
        if message.get("subtype", "").startswith(
                "bot_") and message["bot_id"] not in self.__USER_DATA:
            bot_id = message["bot_id"]
            #logging.debug("bot addition for %s", bot_id)
            if "bot_link" in message:
                (bot_url,
                 bot_name) = message["bot_link"].strip("<>").split("|", 1)
            elif "username" in message:
                bot_name = message["username"]
                bot_url = None
            else:
                bot_name = None
                bot_url = None

            self.__USER_DATA[bot_id] = User({
                "user": bot_id,
                "real_name": bot_name,
                "bot_url": bot_url,
                "is_bot": True,
                "is_app_user": True
            })
        user_id = message.get("user") or message.get("bot_id")
        #BEGIN JSR - alternate user_id based on deleted message!
        if message.get("subtype") == "message_deleted":
            user_id = message.get("original").get("user")
        if message.get(
                "subtype") == "message_changed" and "edited_by" in message:
            user_id = message.get("original").get("user")
        if message.get(
                "subtype") == "message_changed" and "edited_by" not in message:
            user_id = message.get("message").get("user")
        #END JSR
        if user_id in self.__USER_DATA:
            return self.__USER_DATA.get(user_id)
Exemplo n.º 6
0
 def __init__(self, PATH):
     self._PATH = PATH
     # TODO: Make sure this works
     with io.open(os.path.join(self._PATH, "users.json"),
                  encoding="utf8") as f:
         self.__USER_DATA = {u["id"]: User(u) for u in json.load(f)}