Skip to content

Commit bec1e07

Browse files
Rewrite functions using deprecated groups API.
Fixes RamblingCookieMonster#113
1 parent 259f418 commit bec1e07

File tree

2 files changed

+17
-158
lines changed

2 files changed

+17
-158
lines changed

PSSlack/Public/Get-SlackGroup.ps1

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,21 @@
3434
end
3535
{
3636
Write-Verbose "$($PSBoundParameters | Remove-SensitiveData | Out-String)"
37-
37+
$body = @{
38+
types = 'private_channel';
39+
};
3840
if($ExcludeArchived)
3941
{
40-
$body = @{ exclude_archived = 1 }
42+
$body['exclude_archived'] = 1
4143
}
4244
else
4345
{
44-
$body = @{ exclude_archived = 0 }
46+
$body['exclude_archived'] = 0
4547
}
4648
$params = @{
4749
Body = $body
4850
Token = $Token
49-
Method = 'groups.list'
51+
Method = 'users.conversations'
5052
}
5153
$RawGroups = Send-SlackApi @params
5254

@@ -62,14 +64,14 @@
6264

6365
if($Name -and -not $HasWildCard)
6466
{
65-
# torn between independent queries, or filtering groups.list
67+
# torn between independent queries, or filtering users.conversations
6668
# submit a PR if this isn't performant enough or doesn't make sense.
67-
$Groups = $RawGroups.groups |
69+
$Groups = $RawGroups.channels |
6870
Where-Object {$Name -Contains $_.name}
6971
}
7072
elseif ($Name -and$HasWildCard)
7173
{
72-
$AllGroups = $RawGroups.groups
74+
$AllGroups = $RawGroups.channels
7375

7476
# allow like operator on each group requested in the param, avoid dupes
7577
$GroupHash = [ordered]@{}
@@ -87,7 +89,7 @@
8789
}
8890
else # nothing specified
8991
{
90-
$Groups = $RawGroups.groups
92+
$Groups = $RawGroups.channels
9193
}
9294

9395
if($Raw)

PSSlack/Public/Get-SlackGroupHistory.ps1

Lines changed: 7 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Get history from a Slack group
55
66
.DESCRIPTION
7-
Get history from a Slack group
7+
Get history from a Slack group (this is more or less an alias for Get-SlackHistory).
88
99
.PARAMETER Token
1010
Specify a token for authorization.
@@ -25,7 +25,7 @@
2525
If specified, include history from the date specified in Before and/or After parameters
2626
2727
.PARAMETER Count
28-
Number of messages to return per query. Defaults to 100. Max 1000
28+
Maximum number of messages to return per query (see 'limit' on API docs). Defaults to 100. Max 1000
2929
3030
.PARAMETER Paging
3131
If specified, and more data is available with a given 'Count', continue querying Slack until
@@ -61,156 +61,13 @@
6161
)
6262
begin
6363
{
64-
function Get-UnixTime {
65-
param($Date)
66-
$unixEpochStart = new-object DateTime 1970,1,1,0,0,0,([DateTimeKind]::Utc)
67-
[int]($Date.ToUniversalTime() - $unixEpochStart).TotalSeconds
68-
}
69-
7064
Write-Verbose "$($PSBoundParameters | Remove-SensitiveData | Out-String)"
71-
72-
$body = @{
73-
channel = $null
74-
count = $count
75-
}
76-
if($Paging)
77-
{
78-
$PageDirection = 'Backward'
79-
}
80-
$BeforeTS = $null
81-
$AfterTS = $null
82-
if($PSBoundParameters.ContainsKey('Before'))
83-
{
84-
$BeforeTS = Get-UnixTime -Date $Before
85-
$body.add('latest', $BeforeTS)
86-
}
87-
if($PSBoundParameters.ContainsKey('After'))
88-
{
89-
$AfterTS = Get-UnixTime -Date $After
90-
$body.add('oldest', $AfterTS)
91-
if(-not $PSBoundParameters.ContainsKey('Before') -and $Paging)
92-
{
93-
$PageDirection = 'Forward'
94-
}
95-
}
96-
if($Inclusive)
97-
{
98-
$body.add('inclusive', 1)
99-
}
100-
$params = @{
101-
Token = $Token
102-
Method = 'groups.history'
103-
Body = $body
65+
if ($PSBoundParameters.ContainsKey('GroupID')) {
66+
$PSBoundParameters['ChannelID'] = $PSBoundParameters['GroupID']
67+
$PSBoundParameters.Remove('GroupID')
10468
}
105-
$Queries = 1
106-
10769
}
108-
process
109-
{
110-
foreach($ID in $GroupID)
111-
{
112-
$has_more = $false
113-
$Params.body.channel = $ID
114-
do
115-
{
116-
if($has_more)
117-
{
118-
if($Params.Body.oldest)
119-
{
120-
[void]$Params.Body.remove('oldest')
121-
}
122-
if($Params.Body.latest)
123-
{
124-
[void]$Params.Body.remove('latest')
125-
}
126-
if($PageDirection -eq 'Forward')
127-
{
128-
129-
$ts = $response.messages.ts | Sort-Object |
130-
Microsoft.PowerShell.Utility\Select-Object -last 1
131-
$Params.body.oldest = $ts
132-
Write-Debug "Paging Forward.`n$(
133-
[pscustomobject]@{
134-
After = $After
135-
Before = $Before
136-
LastTS = $response.messages[-1].ts
137-
SortLast = $response.messages.ts | Sort-Object |
138-
Microsoft.PowerShell.Utility\Select-Object -last 1
139-
SortFirst = $response.messages.ts | Sort-Object |
140-
Microsoft.PowerShell.Utility\Select-Object -first 1
141-
ts = $ts
142-
} | Out-String
143-
)"
144-
}
145-
elseif($PageDirection -eq 'Backward')
146-
{
147-
$ts = $response.messages[-1].ts
148-
if($AfterTS -and $ts -lt $AfterTS)
149-
{
150-
Write-Debug "TS is less than AfterTS, breaking!"
151-
break
152-
}
153-
$Params.body.latest = $ts
154-
Write-Debug "Paging Forward.`n$(
155-
[pscustomobject]@{
156-
After = $After
157-
Before = $Before
158-
LastTS = $response.messages[-1].ts
159-
SortLast = $response.messages.ts | Sort-Object |
160-
Microsoft.PowerShell.Utility\Select-Object -last 1
161-
SortFirst = $response.messages.ts | Sort-Object |
162-
Microsoft.PowerShell.Utility\Select-Object -first 1
163-
ts = $ts
164-
} | Out-String
165-
)"
166-
}
167-
168-
$has_more = $false
169-
Write-Debug "Body is now:$($params.body | out-string)"
170-
}
171-
$response = Send-SlackApi @params
172-
173-
Write-Debug "$($Response | Format-List -Property * | Out-String)"
174-
175-
if ($response.ok)
176-
{
177-
178-
if($response.psobject.properties.name -contains 'has_more' -and $response.has_more)
179-
{
180-
Write-Debug 'Paging engaged!'
181-
$has_more = $true
182-
}
183-
184-
if($Raw)
185-
{
186-
$link = "$($Script:PSSlack.ArchiveUri)/$($response.group)/p$($response.ts -replace '\.')"
187-
$response | Add-Member -MemberType NoteProperty -Name link -Value $link
188-
$response
189-
}
190-
else
191-
{
192-
#Order our messages appropriately according to page direction
193-
if($Paging -and $PageDirection -eq 'Forward')
194-
{
195-
Parse-SlackMessage -InputObject $Response | Sort-Object TimeStamp
196-
}
197-
else
198-
{
199-
Parse-SlackMessage -InputObject $Response
200-
}
201-
}
202-
}
203-
else
204-
{
205-
$response
206-
}
207-
$Queries++
208-
}
209-
until (
210-
-not $Paging -or
211-
-not $has_more -or
212-
($MaxQueries -and $Queries -gt $MaxQueries)
213-
)
214-
}
70+
end {
71+
Get-SlackHistory @PSBoundParameters
21572
}
21673
}

0 commit comments

Comments
 (0)