Create a gist now

Instantly share code, notes, and snippets.

@Likk /slack.pl
Created Mar 24, 2017

What would you like to do?
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