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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
# Copyright (C) 02 October 2001 Author FoxMaSk <foxmask@phpfr.org>
#
# 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 2
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#============================================================================
# This script manage a list of keywords
# with their definition...
# The file, named "doc", is composed as follow :
# keyword=definition
#
# Then, anyone on the channel can query the file and
# if the keyword exists the script displays the definition,
# if not ; the script /msg to $nick an appropriate message
#
# You can also, Add ; Modify or Delete definitions ;
# but only *known* people can do it...
#
# To install it ; put the script in ~/.irssi/scripts and then
# cd to autorun and make ln -s ../doc.pl .
#================================WARNING======================================
# Requirement : script friends.pl (http://irssi.atn.pl/friends/) version 2.3
# this one permit us to identify people who can
# addd/modify/delete records in the file
#=============================================================================
#
# History :
# Before using irssi and make this script ; i used (and continue to use)
# an eggdrop that use this feature of querying the file to help anyone
# on the channel to find online help on demand.
#
# Now :
# I will try to merge all my tcl scripts (that i use with my egg) for irssi.
# Then, irssi will be able to react _as_ an eggdrop, but with more functions.
#
# Todo :
# 1) make it work on multi-channel
#
# Update :
#
# make it work with latest friends.pl (http://irssi.atn.pl/friends/) version 2.3
#
# get_idx() give me the state "Friends or Not ?"
# instead of old is_friends() function
#
#
# 2003/01/09
# changes Irssi::get_irssi_dir()."/doc"; instead of $ENVENV{HOME}/.irssi/doc";
# thanks to Wouter Coekaerts
use Irssi::Irc;
use Irssi;
use strict;
use vars qw($VERSION %IRSSI);
$VERSION = "0.0.4";
%IRSSI = (
authors => 'FoxMaSk',
contact => 'foxmask@phpfr.org ',
name => 'doc',
description => 'manage tips ; url ; help in a doc file in the keyword=definition form',
license => 'GNU GPL',
url => 'http://team.gcu-squad.org/~odemah/'
);
#name of the channel where this feature will be used
my $channel = "#phpfr";
#commands that manage the "doc" script
#query
my $cmd_query = "!doc";
#add
my $cmd_add = "!doc+";
#delete
my $cmd_del = "!doc-";
#modify
my $cmd_mod = "!doc*";
#file name to store data
my $doc_file = Irssi::get_irssi_dir()."/doc";
#==========================END OF PARMS======================================
#init array
my @doc = ();
my $x = 0;
#The main function
sub doc_find {
my ($server, $msg, $nick, $address, $target) = @_;
my $keyword="";
my $new_definition="";
my $definition="";
#flag if keyword is found
my $find="";
#*action* to do
my $cmd="";
#the string behind *action*
my $line="";
#to display /msg
my $info="";
#split the *action* and the rest of the line
($cmd,$line) = split / /,$msg,2;
if ($target eq $channel) {
#to query
if ($cmd eq $cmd_query) {
$keyword = $line;
($find,$definition) = exist_doc($keyword);
if ($find ne '') {
my $newmsg = join("=",$keyword,$definition);
$server->command("notice $target $newmsg");
}
#definition not found ; so we tell it to $nick
else {
$info="$nick $keyword does not exist";
info_doc($server,$info);
}
}
else {
my $code = Irssi::Script::friends::->can('get_idx') || Irssi::Script::friends_shasta::->can('get_idx');
if ($code && $code->($nick,$address) != -1) {
#call of friends.pl script to determine if the current
#$nick can manage the doc file
#to add
if ($cmd eq $cmd_add) {
($keyword,$new_definition) = split /=/,$line,2;
($find,$definition) = exist_doc($keyword);
#definition not found ; so we add it
if ($find eq '') {
push(@doc,"$keyword=$new_definition");
save_doc();
$info="$nick added, thank you for your contribution";
info_doc($server,$info);
#definition found ; so we tell it to the $nick
} else {
$info="$nick $keyword already exists";
info_doc($server,$info);
}
}
#to modify
elsif ($cmd eq $cmd_mod) {
($keyword,$new_definition) = split /=/,$line,2;
($find,$definition) = exist_doc($keyword);
#definition not found ; so we can't modify it
if ($find eq '') {
$info="$nick $keyword does not exists, can not be modified";
info_doc($server,$info);
} else {
del_doc($keyword) ;
push(@doc,"$keyword=$new_definition");
save_doc();
$info="$nick modified, thank you for your contribution";
info_doc($server,$info);
}
}
#to delete
elsif ($cmd eq $cmd_del) {
$keyword = $line;
($find,$definition) = exist_doc($keyword);
if ($find ne '') {
del_doc($keyword);
save_doc();
$info="$nick definition has been removed";
info_doc($server,$info);
}
else {
$info="$nick $keyword does not exist, can't be deleted";
info_doc($server,$info);
}
}
}
}
}
}
#load datas
sub load_doc {
my $doc_line="";
if (-e $doc_file) {
@doc = ();
Irssi::print("Loading doc from $doc_file");
local *DOC;
open(DOC, q{<}, $doc_file);
local $/ = "\n";
while (<DOC>) {
chop();
$doc_line = $_;
push(@doc,$doc_line);
}
close DOC;
Irssi::print("Loaded " . scalar(@doc) . " record(s)");
} else {
Irssi::print("Cannot load $doc_file");
}
}
#remove data
sub del_doc {
my ($keyword) = @_;
my $key_del="";
my $def_del="";
for ($x=0;$x < @doc; $x++) {
($key_del,$def_del) = split /=/,$doc[$x],2;
if ( $key_del eq $keyword ) {
splice (@doc,$x,1);
last;
}
}
}
#store data inf "doc" file
sub save_doc {
my $keyword="";
my $definition="";
if (-e $doc_file) {
open(DOC, q{>}, $doc_file);
for ($x=0;$x < @doc;$x++) {
($keyword,$definition) = split /=/,$doc[$x],2;
print DOC "$keyword=$definition\n";
}
close DOC;
}
}
#search if keyword already exists or not
sub exist_doc {
my ($keyword) = @_;
my $key="";
my $def="";
my $find="";
for ($x=0;$x < @doc;$x++) {
($key,$def) = split /=/,$doc[$x],2;
if ($key eq $keyword) {
$find = "*";
last;
}
}
return $find,$def;
}
#display /msg to $nick
sub info_doc {
my ($server,$string) = @_;
$server->command("/msg $string");
Irssi::signal_stop();
}
load_doc();
Irssi::signal_add_last('message public', 'doc_find');
Irssi::print("Doc Management $VERSION loaded!");
|