-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmoberry.pl
More file actions
executable file
·105 lines (86 loc) · 2.27 KB
/
Copy pathmoberry.pl
File metadata and controls
executable file
·105 lines (86 loc) · 2.27 KB
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
use strict;
use Irssi qw/signal_add/;
use Irssi::Irc;
use warnings;
use Switch;
use vars qw($VERSION %IRSSI);
$VERSION = "1";
%IRSSI = (
authors => 'Jaykob Ross',
contact => 'mosai57@gmail.com',
name => 'Moberry',
description => 'Sends a random phrase to an irc channel when triggered.',
changed => '2014-1-1 19:28 (UTC-8:00)',
);
my @responses = (
"Yes.",
"No.",
"That's a terrible idea.",
"What? Sorry, I fell asleep while reading that.",
"*snrk*",
"Uhhhhhh... No comment.",
);
my @emotes = ( "D:", ":|", ":D", );
sub format_uptime{
# Initialize variables
my $string = "";
my $uptime = `uptime`;
my $emote = "";
# Match the capture groups
$uptime =~ m/(\d+ days,)/;
my $days = $1;
$uptime =~ m/(\d+:\d+,)/;
my $time = $1;
# Formatting
$uptime =~ s/up \d days,//;
$uptime =~ s/\d+:\d+,//;
$uptime =~ s/\s+/ /g;
$days =~ s/ days,//;
$time =~ s/,//;
# Determine emote
if(!($days) || $days < 3){
$emote = $emotes[0];
} elsif($days >= 3 && $days < 7){
$emote = $emotes[1];
} elsif($days >= 7){
$emote = $emotes[2];
}
$string = "It has been ";
if($days){ $string .= "$days days, "; }
$string .= "$time since the last system crash $emote (Uptime: $uptime)";
return $string;
}
#### FRONTEND COMMANDS ####
sub info{
my($server, $message, $nick, $address, $target) = @_;
my $me = $server->{nick};
if($nick =~ /amiigo\|\d+/i){ return; }
if($message =~ /^$me[:,]\s/i){
my(undef, $command) = split ' ', $message;
if($command =~ /uptime$/i){
my $output = format_uptime();
$server->command("MSG $target $output");
}
elsif($command =~ /lscpu$/i){
my @lscpu = `lscpu`;
chomp @lscpu;
s/:\s+/: / for @lscpu;
my $response = join(', ', @lscpu);
$server->command("MSG $target $response");
}
else{ return; }
}
}
sub respond{
my($server, $message, $nick, $address, $target) = @_;
if($nick =~ /amiigo\|\d+/i){ return; }
my $me = $server->{nick};
if($message =~ /right,? $me\?/i){
$server->command("MSG $target " . $responses[int(rand(scalar(@responses)))]);
}
if($message =~ /fuck you(\s\w+)? $me/i){
$server->command("MSG $target t(*-*t)");
}
}
signal_add('message public', \&info);
signal_add('message public', \&respond);