-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.ps1
172 lines (153 loc) · 5.89 KB
/
main.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
[CmdletBinding()]
param (
[string]$Server,
[Alias("FullName")]
[string]$Path,
[string[]]$Type
)
<#
Validation
#>
if (-not $Path) {
Write-Warning "FilePath empty or missing"
return
}
Write-Verbose "Exporting $Type to $Path"
. $PSScriptRoot/helpers.ps1
$myaccount = Invoke-Request -Path "accounts/verify_credentials" -Method GET
$script:myid = $myaccount.id
$script:accounts = New-Object System.Collections.ArrayList
# help 'em out
if ($Server -match '://') {
$Server = ([uri]$Server).DnsSafeHost
} elseif ($Server -match '/@') {
$Server = $($Server -split "/@" | Select-Object -First 1)
} elseif ($Server.StartsWith("@") -or $Server -match "@") {
$Server = $($Server -split "@" | Select-Object -Last 1)
}
$dir = Resolve-Path -Path $Path -ErrorAction Ignore
if (-not $dir) {
$dir = $Path
}
if (-not (Test-Path $dir)) {
$null = New-Item -Path $dir -Type Directory -ErrorAction Stop
}
$dir = Resolve-Path -Path $dir -ErrorAction Ignore
$items = "follows", "lists", "blocks", "mutes", "domain_blocks", "bookmarks", "followers", "posts"
foreach ($item in $items) {
if ($Type -contains $item -or "$Type" -eq "all") {
Write-Verbose "Processing $item"
if ($item -eq "blocks") {
Write-Verbose "Exporting account blocks"
$filepath = Join-Path -Path $dir -ChildPath blocked_accounts.csv
# No header, Just acct
(Get-AccountBlock).acct | Out-File -FilePath $filepath
}
if ($item -eq "lists") {
Write-Verbose "Exporting lists"
$filepath = Join-Path -Path $dir -ChildPath lists.csv
# No header, two columns formatted like: listname, user@domain.tld
foreach ($list in (Get-List)) {
foreach ($member in (Get-ListMember -Id $list.Id)) {
"$($list.title),$($member.acct)" | Add-Content -Path $filepath
}
}
}
if ($item -eq "follows") {
Write-Verbose "Exporting following"
$filepath = Join-Path -Path $dir -ChildPath following_accounts.csv
# Account address,Show boosts,Notify on new posts,Languages
# id[]=1&id[]=2
<#
id : 109344415928696897
following : True
showing_reblogs : True
notifying : False
languages :
followed_by : True
blocking : False
blocked_by : False
muting : False
muting_notifications : False
requested : False
domain_blocking : False
endorsed : False
note :
#>
$follows = Get-WhoAmIFollowing
$relationships = Get-Relationship
$follows | ForEach-Object -Process {
$rel = $relationships | Where-Object Id -eq $PSItem.Id
$showboosts = $rel.showing_reblogs -eq $true
$notify = $rel.notifying -eq $true
[pscustomobject]@{
'Account address' = $PSItem.acct
'Show boosts' = $showboosts
'Notify on new posts' = $notify
'Languages' = $rel.languages
}
} | Export-Csv -Path $filepath
}
if ($item -eq "mutes") {
Write-Verbose "Exporting mutes"
$filepath = Join-Path -Path $dir -ChildPath muted_accounts.csv
# Account address,Hide notifications
foreach ($account in (Get-AccountMute).acct) {
"$account, $true" | Add-Content -Path $filepath
}
}
if ($item -eq "domain_blocks") {
Write-Verbose "Exporting domain blocks"
$filepath = Join-Path -Path $dir -ChildPath blocked_domains.csv
# Just the domain
Get-DomainBlock | Out-File -Filepath $filepath
}
if ($item -eq "bookmarks") {
Write-Verbose "Exporting bookmarks"
$filepath = Join-Path -Path $dir -ChildPath bookmarks.csv
(Get-Bookmark).uri | Out-File -Filepath $filepath
}
if ($item -eq "followers") {
# Thi can't be imported
Write-Verbose "Exporting followers"
$filepath = Join-Path -Path $dir -ChildPath followers.csv
"Follower" | Set-Content -Path $filepath
(Get-WhoFollowsMe).acct | Add-Content -Path $filepath
}
if ($item -eq "posts") {
Write-Verbose "Exporting posts"
$filepath = Join-Path -Path $dir -ChildPath posts.json
Get-Post | ConvertTo-Json -Depth 10 | Out-File -FilePath $filepath
}
if ((Test-Path -Path $filepath)) {
Get-ChildItem -Path $filepath -ErrorAction Ignore
}
}
}
<#
if (-not $PSBoundParameter.Type) {
if ($first -match "Hide Notifications") {
$Type = "mutes"
$csv = Import-Csv -Path $file
} elseif ($first -match "Show boosts") {
$Type = "follows"
$csv = Import-Csv -Path $file
} elseif ($first -match "@" -and $first -notmatch ",") {
$Type = "accountblocks"
$csv = Get-Content -Path $file
} elseif ($first -match "@" -and $first -match ",") {
$Type = "lists"
$csv = Import-Csv -Path $file -Header List, UserName
} elseif ($first -notmatch "," -and $first -match "http") {
$Type = "bookmarks"
$csv = Get-Content -Path $file
} elseif ($first -notmatch "http" -and $first -notmatch "," -and $first -match ".") {
$Type = "domainblocks"
$csv = Get-Content -Path $file
} else {
$basename = Split-Path -Path $file -Leaf
throw "Can't auto-detect file type for $basename. Please specify type in the Action"
}
}
#>
"csv-path=$dir" >> $env:GITHUB_OUTPUT