1POE::Component::IRC::CoUmsmeorn(C3o)ntributed Perl DocumPeOnEt:a:tCioomnponent::IRC::Common(3)
2
3
4
6 POE::Component::IRC::Common - Provides a set of common functions for
7 the POE::Component::IRC suite
8
10 use strict;
11 use warnings;
12
13 use POE::Component::IRC::Common qw( :ALL );
14
15 my $nickname = '^Lame|BOT[moo]';
16 my $uppercase_nick = u_irc( $nickname );
17 my $lowercase_nick = l_irc( $nickname );
18
19 my $mode_line = 'ov+b-i Bob sue stalin*!*@*';
20 my $hashref = parse_mode_line( $mode_line );
21
22 my $banmask = 'stalin*';
23 my $full_banmask = parse_ban_mask( $banmask );
24
25 if ( matches_mask( $full_banmask, 'stalin!joe@kremlin.ru' ) ) {
26 print "EEK!";
27 }
28
29 if ( has_color($message) ) {
30 print 'COLOR CODE ALERT!";
31 }
32
33 my $results_hashref = matches_mask_array( \@masks, \@items_to_match_against );
34
35 my $nick = parse_user( 'stalin!joe@kremlin.ru' );
36 my ($nick, $user, $host) = parse_user( 'stalin!joe@kremlin.ru' );
37
39 POE::Component::IRC::Common provides a set of common functions for the
40 POE::Component::IRC suite. There are included functions for uppercase
41 and lowercase nicknames/channelnames and for parsing mode lines and ban
42 masks.
43
45 Use the following constants to add formatting and mIRC color codes to
46 IRC messages.
47
48 Normal text:
49
50 NORMAL
51
52 Formatting:
53
54 BOLD
55 UNDERLINE
56 REVERSE
57 ITALIC
58 FIXED
59
60 Colors:
61
62 WHITE
63 BLACK
64 DARK_BLUE
65 DARK_GREEN
66 RED
67 BROWN
68 PURPLE
69 ORANGE
70 YELLOW
71 LIGHT_GREEN
72 TEAL
73 CYAN
74 LIGHT_BLUE
75 MAGENTA
76 DARK_GREY
77 LIGHT_GREY
78
79 Individual formatting codes can be cancelled with their corresponding
80 constant, but you can also cancel all of them at once with "NORMAL". To
81 cancel the effect of previous color codes, you must use "NORMAL". which
82 of course has the side effect of cancelling the effect of all previous
83 formatting codes as well.
84
85 $irc->yield('This word is ' . YELLOW . 'yellow' . NORMAL
86 . ' while this word is ' . BOLD . 'bold' . BOLD);
87
88 $irc->yield(UNDERLINE . BOLD . 'This sentence is both underlined and bold.'
89 . NORMAL);
90
92 "u_irc"
93 Takes one mandatory parameter, a string to convert to IRC uppercase,
94 and one optional parameter, the casemapping of the ircd ( which can be
95 'rfc1459', 'strict-rfc1459' or 'ascii'. Default is 'rfc1459' ). Returns
96 the IRC uppercase equivalent of the passed string.
97
98 "l_irc"
99 Takes one mandatory parameter, a string to convert to IRC lowercase,
100 and one optional parameter, the casemapping of the ircd ( which can be
101 'rfc1459', 'strict-rfc1459' or 'ascii'. Default is 'rfc1459' ). Returns
102 the IRC lowercase equivalent of the passed string.
103
104 "parse_mode_line"
105 Takes a list representing an IRC mode line. Returns a hashref. If the
106 modeline couldn't be parsed the hashref will be empty. On success the
107 following keys will be available in the hashref:
108
109 'modes', an arrayref of normalised modes;
110
111 'args', an arrayref of applicable arguments to the modes;
112
113 Example:
114
115 my $hashref = parse_mode_line( 'ov+b-i', 'Bob', 'sue', 'stalin*!*@*' );
116
117 # $hashref will be:
118 {
119 modes => [ '+o', '+v', '+b', '-i' ],
120 args => [ 'Bob', 'sue', 'stalin*!*@*' ],
121 }
122
123 "parse_ban_mask"
124 Takes one parameter, a string representing an IRC ban mask. Returns a
125 normalised full banmask.
126
127 Example:
128
129 $fullbanmask = parse_ban_mask( 'stalin*' );
130
131 # $fullbanmask will be: 'stalin*!*@*';
132
133 "matches_mask"
134 Takes two parameters, a string representing an IRC mask ( it'll be
135 processed with parse_ban_mask() to ensure that it is normalised ) and
136 something to match against the IRC mask, such as a nick!user@hostname
137 string. Returns a true value if they match, a false value otherwise.
138 Optionally, one may pass the casemapping (see "u_irc"), as this
139 function uses "u_irc" internally.
140
141 "matches_mask_array"
142 Takes two array references, the first being a list of strings
143 representing IRC masks, the second a list of somethings to test against
144 the masks. Returns an empty hashref if there are no matches. Otherwise,
145 the keys will be the masks matched, each value being an arrayref of the
146 strings that matched it. Optionally, one may pass the casemapping (see
147 "u_irc"), as this function uses "u_irc" internally.
148
149 "parse_user"
150 Takes one parameter, a string representing a user in the form
151 nick!user@hostname. In a scalar context it returns just the nickname.
152 In a list context it returns a list consisting of the nick, user and
153 hostname, respectively.
154
155 "has_color"
156 Takes one parameter, a string of IRC text. Returns 1 if it contains any
157 IRC color codes, 0 otherwise. Useful if you want your bot to kick users
158 for (ab)using colors. :)
159
160 "has_formatting"
161 Takes one parameter, a string of IRC text. Returns 1 if it contains any
162 IRC formatting codes, 0 otherwise.
163
164 "strip_color"
165 Takes one parameter, a string of IRC text. Returns the string stripped
166 of all IRC color codes. Due to the fact that both color and formatting
167 codes can be cancelled with the same character, this might strip more
168 than you hoped for if the string contains both color and formatting
169 codes. Stripping both will always do what you expect it to.
170
171 "strip_formatting"
172 Takes one parameter, a string of IRC text. Returns the string stripped
173 of all IRC formatting codes. Due to the fact that both color and
174 formatting codes can be cancelled with the same character, this might
175 strip more than you hoped for if the string contains both color and
176 formatting codes. Stripping both will always do what you expect it to.
177
178 "irc_to_utf8"
179 This function takes a byte string (e.g. a message from an "irc_public"
180 handler) in "IRC encoding" and returns a text string. Since the source
181 encoding might have been UTF-8, you should encode/store it in UTF-8 or
182 some other Unicode encoding in your file/database/whatever.
183
184 use POE::Component::IRC::Common qw(irc_to_utf8);
185
186 sub irc_public {
187 my ($who, $where, $what) = @_[ARG0..ARG2];
188
189 # not wise, $what is either CP1252 or UTF-8
190 print $what, "\n";
191
192 $what = irc_to_utf8($what);
193
194 # good, $what is always UTF-8
195 print $what, "\n";
196 }
197
198 "irc_ip_get_version"
199 Try to guess the IP version of an IP address.
200
201 Params: IP address Returns: 4, 6, 0(unable to determine)
202
203 "$version = ip_get_version ($ip)"
204
205 "irc_ip_is_ipv4"
206 Check if an IP address is of type 4.
207
208 Params: IP address Returns: 1 (yes) or 0 (no)
209
210 "ip_is_ipv4($ip) and print "$ip is IPv4";"
211
212 "irc_ip_is_ipv6"
213 Check if an IP address is of type 6.
214
215 Params: IP address Returns: 1 (yes) or 0 (no)
216
217 ip_is_ipv6($ip) && print "$ip is IPv6";
218
220 Chris 'BinGOs' Williams
221
222 IP functions are shamelessly 'borrowed' from Net::IP by Manuel Valente
223
225 POE::Component::IRC
226
227 Net::IP
228
229
230
231perl v5.12.2 2010-11-05 POE::Component::IRC::Common(3)