diff --git a/.env.example b/.env.example index fe3584d..a23a126 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,6 @@ -EMOJI_INSTANCE_BASE_PROTO="https" -EMOJI_INSTANCE_BASE_URL="yourinstance.net" -EMOJI_AUTH_TOKEN="Bearer yourtoken" +INSTANCE_BASE_PROTO="https" +INSTANCE_BASE_URL="yourinstance.net" +AUTH_TOKEN="Bearer yourtoken" + EMOJI_FILE_TYPES='["png", "jpg", "gif"]' EMOJI_SUFFIXES='["256"]' \ No newline at end of file diff --git a/add-emojis-from-subdirs.py b/add-emojis-from-subdirs.py index 9f7880f..92e9cd4 100644 --- a/add-emojis-from-subdirs.py +++ b/add-emojis-from-subdirs.py @@ -3,10 +3,10 @@ from dotenv import load_dotenv load_dotenv() -instance_base_proto = os.getenv("EMOJI_INSTANCE_BASE_PROTO") -instance_base_url = os.getenv("EMOJI_INSTANCE_BASE_URL") +instance_base_proto = os.getenv("INSTANCE_BASE_PROTO") +instance_base_url = os.getenv("INSTANCE_BASE_URL") instance_full_url = instance_base_proto + "://" + instance_base_url + "/api/iceshrimp/emoji" -auth_token = os.getenv("EMOJI_AUTH_TOKEN") +auth_token = os.getenv("AUTH_TOKEN") image_types = json.loads(os.getenv("EMOJI_FILE_TYPES")) suffixes = json.loads(os.getenv("EMOJI_SUFFIXES")) diff --git a/instance-blocks.py b/instance-blocks.py new file mode 100644 index 0000000..2e62e91 --- /dev/null +++ b/instance-blocks.py @@ -0,0 +1,80 @@ +import requests, json, argparse, os +from dotenv import load_dotenv + +load_dotenv() + +parser = argparse.ArgumentParser() + +sp = parser.add_subparsers(dest="list_or_push") +list_sp = sp.add_parser("list") +push_sp = sp.add_parser("push") + +list_sp.add_argument("-o", "--output") +push_sp.add_argument("input") + +list_grp = list_sp.add_mutually_exclusive_group() +list_grp.add_argument("-a", "--allowed", action="store_true") +list_grp.add_argument("-b", "--blocked", action="store_true") + +push_grp = push_sp.add_mutually_exclusive_group() +push_grp.add_argument("-a", "--allowed", action="store_true") +push_grp.add_argument("-b", "--blocked", action="store_true") + +args = parser.parse_args() + +if args.list_or_push == "list": + instance_base_proto = os.getenv("INSTANCE_BASE_PROTO") + instance_base_url = os.getenv("INSTANCE_BASE_URL") + instance_full_url = instance_base_proto + "://" + instance_base_url + "/api/iceshrimp/admin/instances/" + auth_token = os.getenv("AUTH_TOKEN") + + if args.blocked: + instance_full_url += "blocked" + ab = "blocked" + elif args.allowed: + instance_full_url += "allowed" + ab = "allowed" + else: + print("specify -a or -b") + exit() + + headers = {"authorization": auth_token} + req = requests.get(instance_full_url, headers=headers) + + json_dumped = json.loads(req.text) + + if len(json_dumped) == 0: + print("no instances are " + ab) + exit() + + if args.output: + x = open(args.output, "w+") + x.writelines(json.dumps(json_dumped)) + else: + for instance in json_dumped: + print(instance) +elif args.list_or_push == "push": + instance_base_proto = os.getenv("INSTANCE_BASE_PROTO") + instance_base_url = os.getenv("INSTANCE_BASE_URL") + instance_full_url = instance_base_proto + "://" + instance_base_url + "/api/iceshrimp/admin/instances/" + auth_token = os.getenv("AUTH_TOKEN") + + if args.blocked: + ab = "block" + elif args.allowed: + ab = "allow" + else: + print("specify -a or -b") + exit() + + x = open(args.input, "r") + x_data = x.read() + + x_json = json.loads(x_data) + + headers = {"authorization": auth_token} + for instance in x_json: + instance["imported"] = instance.pop("isImported") + url = instance_full_url + instance["host"] + "/" + ab + instance.pop("host") + req = requests.post(url, headers=headers, data=instance) \ No newline at end of file