smp/review/toolkit.nu

159 lines
3.5 KiB
Plaintext
Raw Normal View History

2023-08-26 18:57:00 -03:00
#!/usr/bin/env nu
export def "listMods" [] {
2023-08-31 14:29:44 -03:00
open all.json | reject body gallery
2023-08-26 18:57:00 -03:00
}
export def "removeMods" [...slugs: string] {
2023-08-31 15:17:32 -03:00
let deleted = open all.json | where slug in $slugs | select slug title description kind link
2023-08-26 18:57:00 -03:00
(
open all.json |
where slug not-in $slugs |
save all.json -f
)
updateMods
2023-08-31 15:17:32 -03:00
$deleted
2023-08-26 18:57:00 -03:00
}
export def "searchMods" [term: string] {
(
open all.json |
where slug =~ $term or title =~ $term |
select slug title description kind
)
}
2023-08-31 14:29:44 -03:00
export def "showMods" [...slugs: string] {
open all.json | where slug in $slugs | select slug title description kind link
}
2023-08-31 15:17:32 -03:00
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
)
2023-08-26 18:57:00 -03:00
(
open all.json |
2023-08-31 15:17:32 -03:00
append $newMods |
2023-08-26 18:57:00 -03:00
uniq-by slug |
save all.json -f
)
2023-08-31 15:17:32 -03:00
2023-08-26 18:57:00 -03:00
updateMods
2023-08-31 15:17:32 -03:00
open all.json | where slug in $slugs | select slug description kind review link
2023-08-26 18:57:00 -03:00
}
export def "updateMods" [] {
(
open all.json |
upsert kind {
kindOf client_side, server_side
} |
upsert link {|row|
$"https://modrinth.com/mod/($row.slug)"
} |
2023-08-31 14:29:44 -03:00
save -f all.json
2023-08-26 18:57:00 -03:00
)
}
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"
}
}
2023-08-31 12:16:43 -03:00
export def review [...review: string] {
(
open all.json |
upsert review {
2023-08-31 14:29:44 -03:00
if ("review" in $in) {
($in.review | into bool) or ($in.slug in $review)
2023-08-31 13:21:04 -03:00
} else {
2023-08-31 14:29:44 -03:00
false
2023-08-31 12:16:43 -03:00
}
} |
save all.json -f
)
updateMods
2023-08-31 14:29:44 -03:00
open all.json | where slug in $review | select slug review
2023-08-31 12:16:43 -03:00
}
2023-08-26 18:57:00 -03:00
export def conflicts [mod: string, ...conflicts: string] {
(
open all.json |
upsert conflicts {
if $in.slug == $mod {
2023-08-31 13:21:04 -03:00
if ("conflicts" in $in) {
$in.conflicts | append $conflicts | uniq
} else {
$conflicts
}
2023-08-26 18:57:00 -03:00
} else if $in.slug in $conflicts {
if ("conflicts" in $in) {
$in.conflicts | append $mod | uniq
} else {
[$mod]
}
2023-08-31 13:21:04 -03:00
} else {
$in.conflicts
2023-08-26 18:57:00 -03:00
}
} |
save all.json -f
)
updateMods
2023-08-31 14:29:44 -03:00
open all.json | where slug in $conflicts or slug == $mod | select slug conflicts
2023-08-26 18:57:00 -03:00
}
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)"
}
)
}