-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLeaveSlackChannels.pl
40 lines (31 loc) · 1 KB
/
LeaveSlackChannels.pl
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
#!/usr/bin/perl -w
use strict;
use warnings;
use WebService::Slack::WebApi;
use Data::Dumper;
use List::Util 'any';
my $slack = WebService::Slack::WebApi->new(token => '<TOKEN>');
my $conversations = $slack->conversations->list;
my $own_slack_id = '<MY ID>';
my $members;
my $name;
while (1) {
for my $channel (@{$conversations->{channels}}) {
$members = $channel->{members};
if ( any { /$own_slack_id/ } @$members ) {
$name = $channel->{name};
if (
# YOUR REGEX HERE
) {
print $name."\n";
my $response = $slack->conversations->leave(channel => $channel->{id});
print (Dumper $response);
}
} else {
}
}
my $next_cursor = $conversations->{response_metadata}->{next_cursor};
print (Dumper $conversations->{response_metadata});
if ( $next_cursor =~ /^$/ ) { exit -1; }
$conversations = $slack->conversations->list(cursor => $next_cursor );
}