mirror of
https://github.com/revanced/revanced-static-api.git
synced 2025-04-29 22:24:37 +02:00
feat: Add announcements command
This commit is contained in:
parent
86eba632c2
commit
983462368b
@ -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):
|
||||
|
42
commands/announcement.py
Normal file
42
commands/announcement.py
Normal file
@ -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)
|
@ -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)
|
||||
|
6
main.py
6
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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user