smp/review/toolkit.nu
2023-08-31 15:17:32 -03:00

159 lines
3.5 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 installed = ls ../mods | get name | parse ../mods/{slug}.pw.toml | get slug
open all.json | insert installed { |row| $row.slug in $installed } | where not installed | select slug kind review 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)"
} |
save -f all.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 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)"
}
)
}