2
# -*- coding: utf-8 -*-
3
###########################################################################
5
# envbot - an IRC bot in bash #
6
# Copyright (C) 2007-2009 Arvid Norlander #
7
# Copyright (C) 2007-2008 Vsevolod Kozlov #
9
# This program is free software: you can redistribute it and/or modify #
10
# it under the terms of the GNU General Public License as published by #
11
# the Free Software Foundation, either version 3 of the License, or #
12
# (at your option) any later version. #
14
# This program is distributed in the hope that it will be useful, #
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
17
# GNU General Public License for more details. #
19
# You should have received a copy of the GNU General Public License #
20
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
22
###########################################################################
23
#---------------------------------------------------------------------
24
## Command-related utility commands
25
#---------------------------------------------------------------------
27
module_commands_INIT() {
30
commands_register "$1" 'provides' || return 1
31
commands_register "$1" 'commands' || return 1
32
helpentry_module_commands_description="Provides a set of command-related commands."
34
helpentry_commands_provides_syntax='<command>'
35
helpentry_commands_provides_description='Shows which module provides command <command>'
37
helpentry_commands_commands_syntax='[<module>]'
38
helpentry_commands_commands_description='Lists commands available in <module>. If module name is not given, lists all commands'
41
module_commands_UNLOAD() {
45
module_commands_REHASH() {
49
module_commands_handler_provides() {
52
if [[ $parameters =~ ^([a-zA-Z0-9][^ ]*)( [^ ]+)? ]]; then # regex suggested by AnMaster
53
local command_name="${BASH_REMATCH[1]}${BASH_REMATCH[2]}"
55
if [[ $2 =~ ^# ]]; then
58
parse_hostmask_nick "$sender" 'target'
61
commands_provides "$command_name" module_name
62
if [[ -z $module_name ]]; then # No such command
63
send_msg "$target" "Command \"$command_name\" does not exist."
65
send_msg "$target" "Command \"$command_name\" is provided by module \"$module_name\""
69
parse_hostmask_nick "$sender" 'sendernick'
70
feedback_bad_syntax "$sendernick" "provides" "<modulename>"
74
module_commands_handler_commands() {
77
if [[ $2 =~ ^# ]]; then
80
parse_hostmask_nick "$1" 'target'
82
if [[ -z $parameters ]]; then
83
send_msg "$target" "${format_bold}Available commands${format_bold}: ${commands_commands//,/, }"
85
# So we got a parameter
87
if [[ $parameters =~ ^([^ ]+)\ *$ ]]; then
88
module_name="${BASH_REMATCH[1]}"
90
send_notice "$target" "\"$parameters\" is not a valid module name"
93
local commands_in_module
94
commands_in_module "$module_name" 'commands_in_module'
95
if [[ $commands_in_module ]]; then
96
send_msg "$target" "${format_bold}Available commands (in module \"$module_name\")${format_bold}: ${commands_in_module//,/, }"
97
elif list_contains "modules_loaded" "$module_name"; then
98
send_notice "$target" "Module \"$module_name\" provides no commands"
100
send_notice "$target" "Module \"$module_name\" is not loaded"