1 # ho_tools.pl
2 #
3 # $Id: ho_tools.pl,v 1.11 2004/08/22 20:20:57 jvunder REL_0_3 $
4 #
5 # Basic HOSC tools. This script is required for the HOSC, and will be
6 # automatically loaded when any other HOSC script is loaded.
7 #
8 # Part of the Hybrid Oper Script Collection.
9 #
10
11 use strict;
12 use warnings;
13
14 use vars qw[ $VERSION %IRSSI];
15 use Irssi;
16
17 use HOSC::again;
18 use HOSC::again 'HOSC::Base';
19 use HOSC::again 'HOSC::Tools';
20
21 ($VERSION) = '$Revision: 1.11 $' =~ / (\d+\.\d+) /;
22 %IRSSI = (
23 authors => 'Garion',
24 contact => 'garion@efnet.nl',
25 name => 'ho_tools.pl',
26 description => 'Required HOSC Tools.',
27 license => 'Public Domain',
28 url => 'http://www.garion.org/irssi/',
29 changed => '24 April 2004 22:48:36',
30 );
31
32 # ---------------------------------------------------------------------
33 # The /HO command.
34 # Coder note: I tried putting this in HOSC/Tools.pm but Irssi doesn't like
35 # it if you execute Irssi::command_bind() inside a .pm file. If you have a
36 # working solution that allows this code to be put in Tools.pm, please let
37 # me know.
38
39 our @subcommands = qw(help status reload_modules);
40
41 Irssi::command_bind('ho', 'cmd_ho');
42 Irssi::command_bind('ho '.$_, 'cmd_ho_'.$_) for @subcommands;
43
44 sub cmd_ho {
45 my ($data, $server, $item) = @_;
46
47 if ($data =~ /^\s*$/) {
48 HOSC::Tools::ho_print("Use /HO HELP for help.");
49 return;
50 }
51 $data =~ s/\s+$//;
52
53 my $command = $data;
54 my $args;
55 if ($data =~ /^(\S+)\s+(.+)$/) {
56 $command = $1;
57 $args = $2;
58 }
59
60 my @subs = grep /^$command/, @subcommands;
61 if (@subs > 1) {
62 ho_print("Ambiguous command. Try /HO HELP for help.");
63 } elsif (@subs == 0) {
64 ho_print("Unknown command $command. Use /HO HELP for help.");
65 } else {
66 Irssi::command_runsub('ho', $data, $server, $item);
67 }
68 }
69
70 sub cmd_ho_help {
71 my ($data, $server, $item) = @_;
72
73 if (!defined $data || length $data == 0) {
74 ho_print("General help");
75 return;
76 }
77
78 if (lc $data eq 'multitoken') {
79 print_help_multitoken();
80 } else {
81 ho_print("No help available for '$data'.");
82 }
83 }
84
85 sub cmd_ho_status {
86 my ($data, $server, $item) = @_;
87
88 HOSC::Tools::ho_print_status();
89 }
90
91 sub cmd_ho_reload_modules {
92 my ($data, $server, $item) = @_;
93
94 ho_reload_modules(1);
95 }
96
97
98 sub print_help_multitoken {
99 ho_print('Multitoken.');
100 ho_print('A multitoken is a string which has one default value ' .
101 'and one or more values for specifice keys. The values are space ' .
102 'separated. The specific values are given by key:value tokens.');
103 ho_print('An example of this would be "def huk:tilde kek:manner", which '.
104 'defines the default value of "def", and the values "tilde" for key '.
105 '"huk" and "manner" for key "kek".');
106 }
syntax highlighted by Code2HTML, v. 0.9.1