smp/review/toolkit.nu
2023-09-01 11:20:51 -03:00

194 lines
4.0 KiB
Plaintext

#!/usr/bin/env nu
export def "listMods" [] {
open all.json | reject body gallery
}
export def "removeMods" [...slugs: string] {
let deleted = open all.json | where slug in $slugs | select slug title description kind link
(
open all.json |
where slug not-in $slugs |
save all.json -f
)
updateMods
$deleted
}
export def "searchMods" [term: string] {
(
open all.json |
where slug =~ $term or title =~ $term |
select slug title description kind
)
}
export def "showMods" [...slugs: string] {
open all.json | where slug in $slugs | select slug title description kind link
}
export def "diffInstalled" [] {
let tracked = open all.json | where not review | get slug
let installed = ls ../mods | get name | parse ../mods/{slug}.pw.toml | get slug
(
($tracked | append $installed) |
uniq |
each {{
slug: $in,
tracked: ($in in $tracked),
installed: ($in in $installed)
}} |
where { $in.tracked != $in.installed }
)
}
export def "addMods" [...slugs: string, --review: bool = false] {
let newMods = (
$slugs |
each { getMod } |
insert review $review |
insert conflicts null
)
(
open all.json |
append $newMods |
uniq-by slug |
save all.json -f
)
updateMods
open all.json | where slug in $slugs | select slug description kind review link
}
export def "updateMods" [] {
(
open all.json |
upsert kind {
kindOf client_side, server_side
} |
upsert link {|row|
$"https://modrinth.com/mod/($row.slug)"
} |
sort-by slug |
save -f all.json
)
(
open all.json |
where review |
save -f review.json
)
}
def kindOf [client_side: string, server_side: string] string {
if $in.client_side == "required" and $in.server_side == "required" {
"required"
} else if $in.client_side == "optional" and $in.server_side == "optional" {
"optional"
} else if $in.server_side == "unsupported" {
"clientside"
} else if $in.client_side == "unsupported" {
"serverside"
} else if $in.client_side == "optional" and $in.server_side == "required" {
"client-optional"
} else if $in.client_side == "required" and $in.server_side == "optional" {
"server-optional"
}
}
export def approve [...approve: string] {
(
open all.json |
upsert review {
if ($in.slug in $approve) {
false
} else {
if ("review" in $in) {
($in.review | into bool)
} else {
false
}
}
} |
save all.json -f
)
updateMods
open all.json | where slug in $approve | select slug review
}
export def review [...review: string] {
(
open all.json |
upsert review {
if ("review" in $in) {
($in.review | into bool) or ($in.slug in $review)
} else {
false
}
} |
save all.json -f
)
updateMods
open all.json | where slug in $review | select slug review
}
export def conflicts [mod: string, ...conflicts: string] {
(
open all.json |
upsert conflicts {
if $in.slug == $mod {
if ("conflicts" in $in) {
$in.conflicts | append $conflicts | uniq
} else {
$conflicts
}
} else if $in.slug in $conflicts {
if ("conflicts" in $in) {
$in.conflicts | append $mod | uniq
} else {
[$mod]
}
} else {
$in.conflicts
}
} |
save all.json -f
)
updateMods
open all.json | where slug in $conflicts or slug == $mod | select slug conflicts
}
export def getMods [] {
let list = $in | each { |v| $"\"($v)\"" } | str join , | $"[($in)]"
(
http get $"https://api.modrinth.com/v2/projects?ids=($list)" |
select slug project_type title description body client_side server_side categories additional_categories gallery |
update gallery {
get url
} |
insert kind {
kindOf client_side, server_side
} |
insert link {|row|
$"https://modrinth.com/mod/($row.slug)"
}
)
}
export def getMod [] {
(
http get $"https://api.modrinth.com/v2/project/($in)" |
select slug project_type title description body client_side server_side categories additional_categories gallery |
update gallery {
get url
} |
insert kind {
kindOf client_side, server_side
} |
insert link {|row|
$"https://modrinth.com/mod/($row.slug)"
}
)
}