Skip to content

Instantly share code, notes, and snippets.

@Likk
Created March 24, 2017 10:15
Show Gist options
  • Save Likk/48ca948802e3dad7b6ad61a1c3cf6a9f to your computer and use it in GitHub Desktop.
Save Likk/48ca948802e3dad7b6ad61a1c3cf6a9f to your computer and use it in GitHub Desktop.
Slack::RTM::Bot CLI viewer Raw
use strict;
use warnings;
use utf8;
use Encode;
use Slack::RTM::Bot;
use Term::ANSIColor;
my $bot = Slack::RTM::Bot->new(
token => 'YOUR TOKEN',
);
$bot->on(
+{ },
\&main::display_tl,
);
$bot->start_RTM(sub {
while(1) { sleep 10; }
});
sub display_tl {
my ($response) = @_;
if($response->{text} && $response->{channel} && $response->{user}){
my $message = $response->{text};
my $channel = $response->{channel};
my $user = $response->{user};
my $ts = $response->{ts};
my @t = localtime($ts);
my $ymdhms = sprintf('%02d/%02d/%02d %02d:%02d:%02d',1900 + $t[5], ++$t[4], $t[3], $t[2], $t[1], $t[0] );
my $line = sprintf("[%s] <%s\@%s> :%-10s",
color('yellow') . $ymdhms . color('reset'),
color('cyan') . $user . color('reset'),
color('green') . $channel . color('reset'),
color('bright_white') . Encode::encode_utf8($message) . color('reset'),
);
print "$line\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment