blob: ca1f7598d78025e765a8769a8ff1463af1c0bb22 (
plain)
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
|
#!/bin/bash
# -*- coding: utf-8 -*-
###########################################################################
# #
# envbot - an IRC bot in bash #
# Copyright (C) 2007-2008 Arvid Norlander #
# Copyright (C) 2007-2008 Vsevolod Kozlov #
# #
# 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/>. #
# #
###########################################################################
#---------------------------------------------------------------------
## Command-related utility commands
#---------------------------------------------------------------------
module_commands_INIT() {
modinit_API='2'
modinit_HOOKS=''
commands_register "$1" 'provides' || return 1
commands_register "$1" 'commands' || return 1
helpentry_module_commands_description="Provides a set of command-related commands."
helpentry_commands_provides_syntax='<command>'
helpentry_commands_provides_description='Shows which module provides command <command>'
helpentry_commands_commands_syntax='[<module>]'
helpentry_commands_commands_description='Lists commands available in <module>. If module name is not given, lists all commands'
}
module_commands_UNLOAD() {
return 0
}
module_commands_REHASH() {
return 0
}
module_commands_handler_provides() {
local sender="$1"
local parameters="$3"
if [[ $parameters =~ ^([a-zA-Z0-9][^ ]*)( [^ ]+)? ]]; then # regex suggested by AnMaster
local command_name="${BASH_REMATCH[1]}${BASH_REMATCH[2]}"
local target
if [[ $2 =~ ^# ]]; then
target="$2"
else
parse_hostmask_nick "$sender" 'target'
fi
local module_name
commands_provides "$command_name" module_name
if [[ -z $module_name ]]; then # No such command
send_msg "$target" "Command \"$command_name\" does not exist."
else
send_msg "$target" "Command \"$command_name\" is provided by module \"$module_name\""
fi
else
local sendernick
parse_hostmask_nick "$sender" 'sendernick'
feedback_bad_syntax "$sendernick" "provides" "<modulename>"
fi
}
module_commands_handler_commands() {
local parameters="$3"
local target
if [[ $2 =~ ^# ]]; then
target="$2"
else
parse_hostmask_nick "$1" 'target'
fi
if [[ -z $parameters ]]; then
send_msg "$target" "${format_bold}Available commands${format_bold}: ${commands_commands//,/, }"
else
# So we got a parameter
local module_name
if [[ $parameters =~ ^([^ ]+)\ *$ ]]; then
module_name="${BASH_REMATCH[1]}"
else
send_notice "$target" "\"$parameters\" is not a valid module name"
return 1
fi
local commands_in_module
commands_in_module "$module_name" 'commands_in_module'
if [[ $commands_in_module ]]; then
send_msg "$target" "${format_bold}Available commands (in module \"$module_name\")${format_bold}: ${commands_in_module//,/, }"
elif list_contains "modules_loaded" "$module_name"; then
send_notice "$target" "Module \"$module_name\" provides no commands"
else
send_notice "$target" "Module \"$module_name\" is not loaded"
fi
fi
}
|