diff --git a/app/generator.py b/app/generator.py index 24e3f88..05b26c6 100644 --- a/app/generator.py +++ b/app/generator.py @@ -201,19 +201,21 @@ class AnnouncementGenerator(Generator): write_json(announcements, announcements_path) # Add the new announcement to the channel file - channel_path = join( - path, f"announcements/{new_announcement_channel}.json") + channel_path = join(path, f"announcements") create_if_not_exists(channel_path) - channel_announcements = read_json(channel_path, []) + + channel_file = join(channel_path, f"{new_announcement_channel}.json") + channel_announcements = read_json(channel_file, []) channel_announcements.append(new_announcement) - write_json(channel_announcements, channel_path) + write_json(channel_announcements, channel_file) # Update the latest announcement file write_json(new_announcement, join(path, "announcements/latest.json")) # Update the latest announcement for the channel - write_json(new_announcement, join( - path, f"announcements/{new_announcement_channel}/latest.json")) + channel_path = join(path, f"announcements/{new_announcement_channel}") + create_if_not_exists(channel_path) + write_json(new_announcement, f"{channel_path}/latest.json") class RemoveAnnouncementGenerator(Generator): diff --git a/commands/announcement.py b/commands/announcement.py new file mode 100644 index 0000000..658b40f --- /dev/null +++ b/commands/announcement.py @@ -0,0 +1,42 @@ + +import json +import re +import click + + +@click.group() +def announcement(): + pass + + +@click.command() +@click.option('--author', help='Author') +@click.option('--title', help='Title', required=True) +@click.option('--message', help='Message') +@click.option('--attachment-urls', help='Attachment URLs') +@click.option('--channel', help='Channel', required=True) +@click.option('--level', help='Level', type=int) +def create(author: str, title: str, message: str, attachment_urls: str, channel: str, level: int): + config = { + "configs": [ + { + "generators": ["announcement"], + "announcement":{ + "author": author if author else "ReVanced", + "title": title, + "content": { + "message": message, + "attachment_urls": attachment_urls.split(' ') if attachment_urls else [] + }, + "channel": channel, + "level": level if level else 0 + } + } + ] + } + + with open('config.json', 'w') as f: + json.dump(config, f, indent=2) + + +announcement.add_command(create) diff --git a/commands/generate.py b/commands/generate.py index b214780..07702e9 100644 --- a/commands/generate.py +++ b/commands/generate.py @@ -7,6 +7,12 @@ import click from app.config import load_config from app.dependencies import wire_dependencies from app.generator import get_generators +from app.utils import create_if_not_exists + + +@click.group() +def generator(): + pass @click.command() @@ -23,6 +29,8 @@ def generate(): tasks = [] output = config["output"] + create_if_not_exists(output) + for generator_config in config["configs"]: for generator_name in generator_config["generators"]: generator = generators[generator_name] if generator_name in generators else None @@ -41,3 +49,6 @@ def purge(paths): shutil.rmtree(path) elif isfile(path): os.remove(path) + + +generator.add_command(generate) diff --git a/main.py b/main.py index 8f19547..81e5bc2 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,7 @@ import click -from commands.generate import generate +from commands.announcement import announcement, create +from commands.generate import generator @click.group() @@ -8,7 +9,8 @@ def main(): pass -main.add_command(generate) +main.add_command(generator) +main.add_command(announcement) if __name__ == "__main__": main()