-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.pl
executable file
·225 lines (189 loc) · 6.14 KB
/
bot.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/usr/bin/perl
########################################################################
##hobobot - a simple, personal IRC bot. #
## #
##Copyright (C) 2013 Lance Clark #
## #
##This program is free software: you can redistribute it and/or modify #
##it under the terms of the GNU General Public License as published by #
##the Free Software Foundation, either version 3 of the License, or #
##(at your option) any later version. #
## #
##This program is distributed in the hope that it will be useful, #
##but WITHOUT ANY WARRANTY; without even the implied warranty of #
##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
##GNU General Public License for more details. #
## #
##You should have received a copy of the GNU General Public License #
##along with this program. If not, see <http://www.gnu.org/licenses/>.#
## #
########################################################################
package HoboBot;
use base qw(Bot::BasicBot);
use DateTime;
use Yahoo::Weather;
use encoding 'utf8';
use strict;
#Configuration - Begin ####################
# Connection Information
my $server = "irc.freenode.net";
my $port = "6667";
#Bot Configuration
my $bot_nick = "hobobot";
my @channels = ["#ggoogi","#korea"];
my @op_list = ("armlesshobo", "ggoogi", "iGG", "xGG");
my @bot_alt_nicks = ["ahobobot", "h0bobot"];
my $bot_name = "hobobot";
my $bot_username = "hobobot";
my @ignore_list = [qw( dddddd toocool armfulhobo )];
#Configuration - End #######################
#Global defs ##################
my %seen_list; #contains user info for !seen command
#End Global defs #############
sub isOp($) #checks to see if sender is Op
{
my $sender = $_[0];
foreach( @op_list )
{
if ( $_ eq $sender )
{
return 1;
}
}
return 0;
}
sub said(\%)
{
my ($self, $msg) = @_;
#pull out the sender and msg
my $txt = $msg->{body};
my $sndr = $msg->{who};
#process input
if ($txt =~ m/^!info$/) #standard info about the bot
{
return "I'm $bot_name. I'm a robotic vagrant.";
}
elsif ( $txt =~ m/^!poke $bot_name$/ )
{
return "$sndr: don't touch me, pervert...";
}
elsif ( $txt =~ m/^!shutdown$/ or #to cleanly shutdown the bot
$txt =~ m/^!die$/ )
{
if ( isOp($sndr) )
{
$self->shutdown();
}
}
elsif ( $txt =~ m/^!weather/ ) #weather query
{
my @tokens = split( ' ', $txt );
shift(@tokens);
my $location = join(' ', @tokens);
#clean the input a bit
$location =~ s/[\\\/]//g; #back and forward slashes
$location =~ s/[0-9]//g; #numbers
$location =~ s/[\`\~\!\@\#\$\%\^\&\*\(\)\-\_\=\+]//g; #special chars
$location =~ s/[\[\]\{\}\;\:\"\,\.\<\>\?]//g;
$location =~ s/\'/\\'/g; #some places have apostrophes in their name. Don't strip out.
if ( $location eq "" )
{
return "$sndr: Please use the format '!weather <location>'";
}
else
{
my $yw = Yahoo::Weather->new();
my $wres = $yw->getWeatherByLocation($location);
if ( $wres <= 0 )
{
return "$sndr: No data available" if ( $wres == -1 );
return "$sndr: Invalid location specified" if ( $wres == -2 );
return "$sndr: Forecast for that area not available" if ( $wres == -3 );
return "$sndr: Unknown error ($wres)";
}
else
{
my %res = %{$wres};
if ( $res{CurrentObservation} )
{
my %co = %{$res{CurrentObservation}};
return "$sndr: $res{Title}: $co{text}, Temperature of $co{temp}C. Last updated on $co{date}. ";
}
else
{
return "$sndr: No data available for $location";
}
}
}
}
elsif ( $txt =~ m/^!seen/ ) #outputs when a person was last seen
{
my @tokens = split(' ', $txt);
shift( @tokens );
if ( defined( $tokens[0] ) )
{
my $name = join(' ', @tokens);
if ( $name eq "hobobot" )
{
return "I'm right here. This is the last thing I said";
}
my @tuple = $seen_list{lc($name)};
if ( @tuple and $tuple[0][0] and $tuple[0][1] )
{
return "Last saw $name on $tuple[0][0]. Their last message was: <$name> $tuple[0][1]";
}
else
{
return "$name hasn't been seen recently.";
}
}
else
{
return "Please use '!seen <nick>' format";
}
}
elsif ( $txt =~ m/^!ndic/ ) #generates a naver dictionary search URL
{
my @tokens = split(' ', $txt );
shift( @tokens );
my $query = join('+', @tokens);
if ( defined( $query ) )
{
return "http://dic.naver.com/search.naver?query=$query";
}
else
{
return "Please use '!ndic QUERY' format.";
}
}
elsif ( $txt =~ m/^!google/ ) #generate google search URL
{
my @tokens = split(' ', $txt );
shift( @tokens );
my $query = join('+', @tokens);
if ( defined( $query ) )
{
return "https://www.google.com/search?q=$query&ie=UTF-8";
}
else
{
return "Please use '!googl QUERY' format.";
}
}
#update the !seen table
my $date = DateTime->now();
my $date = $date->mdy('/') . " " . $date->hms . "CST";
my @seen_tuple = ($date, $txt);
$seen_list{lc($sndr)} = \@seen_tuple;
}
# we have all that we need
HoboBot->new(
server => $server,
port => $port,
channels => @channels,
nick => $bot_nick,
alt_nicks => @bot_alt_nicks,
username => $bot_username,
name => $bot_name,
ignore_list => @ignore_list,
)->run();