aboutsummaryrefslogtreecommitdiffstats
path: root/modules/m_assign_mode.sh
blob: 7fb4ea17c97219254666f218f97d118da828eba9 (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
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
#!/bin/bash
# -*- coding: utf-8 -*-
###########################################################################
#                                                                         #
#  envbot - an IRC bot in bash                                            #
#  Copyright (C) 2007-2008  Arvid Norlander                               #
#  Copyright (C) 2007-2008  EmErgE <halt.system@gmail.com>                #
#                                                                         #
#  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/>.  #
#                                                                         #
###########################################################################
#---------------------------------------------------------------------
## Channel modes
#---------------------------------------------------------------------

module_assign_mode_INIT() {
	modinit_API='2'
	modinit_HOOKS=''
	commands_register "$1" 'op'        || return 1
	commands_register "$1" 'deop'      || return 1
	commands_register "$1" 'halfop'    || return 1
	commands_register "$1" 'dehalfop'  || return 1
	commands_register "$1" 'voice'     || return 1
	commands_register "$1" 'devoice'   || return 1
	commands_register "$1" 'protect'   || return 1
	commands_register "$1" 'deprotect' || return 1
	commands_register "$1" 'topic'     || return 1
	helpentry_module_assign_mode_description="Provides op, deop and related commands."

	local help_cmd
	for help_cmd in op deop halfop halfdeop voice devoice protect deprotect; do
		printf -v "helpentry_assign_mode_${help_cmd}_syntax" '<#channel> <nick>'
		printf -v "helpentry_assign_mode_${help_cmd}_description" "$(tr 'a-z' 'A-Z' <<< "${help_cmd:0:1}")${help_cmd:1} <nick> in <#channel>."
	done

	helpentry_assign_mode_topic_syntax='<#channel> <new topic>'
	helpentry_assign_mode_topic_description='Change topic to <new topic> in <#channel>'
}

module_assign_mode_UNLOAD() {
	return 0
}

module_assign_mode_REHASH() {
	return 0
}

module_assign_mode_handler_op() {
	local sender="$1"
	local sendon_channel="$2"
	local parameters="$3"
	if [[ "$parameters" =~ ^(#[^ ]+)\ ([^ ]+) ]]; then
		local channel="${BASH_REMATCH[1]}"
		local nick="${BASH_REMATCH[2]}"
		if access_check_capab "op" "$sender" "$channel"; then
			send_modes "$channel" "+o $nick"
		else
			access_fail "$sender" "make the bot op somebody" "op"
		fi
	else
		local sendernick
		parse_hostmask_nick "$sender" 'sendernick'
		feedback_bad_syntax "$sendernick" "op" "<#channel> <nick>"
	fi
}

module_assign_mode_handler_deop() {
	local sender="$1"
	local sendon_channel="$2"
	local parameters="$3"
	if [[ "$parameters" =~ ^(#[^ ]+)\ ([^ ]+) ]]; then
		local channel="${BASH_REMATCH[1]}"
		local nick="${BASH_REMATCH[2]}"
		if access_check_capab "op" "$sender" "$channel"; then
			send_modes "$channel" "-o $nick"
		else
			access_fail "$sender" "make the bot deop somebody" "op"
		fi
	else
		local sendernick
		parse_hostmask_nick "$sender" 'sendernick'
		feedback_bad_syntax "$sendernick" "deop" "<#channel> <nick>"
	fi
}

module_assign_mode_handler_halfop() {
	local sender="$1"
	local sendon_channel="$2"
	local parameters="$3"
	if [[ "$parameters" =~ ^(#[^ ]+)\ ([^ ]+) ]]; then
		local channel="${BASH_REMATCH[1]}"
		local nick="${BASH_REMATCH[2]}"
		if access_check_capab "halfop" "$sender" "$channel"; then
				send_modes "$channel" "+h $nick"
		else
			access_fail "$sender" "make the bot halfop somebody" "halfop"
		fi
	else
		local sendernick
		parse_hostmask_nick "$sender" 'sendernick'
		feedback_bad_syntax "$sendernick" "halfop" "<#channel> <nick>"
	fi
}

module_assign_mode_handler_dehalfop() {
	local sender="$1"
	local sendon_channel="$2"
	local parameters="$3"
	if [[ "$parameters" =~ ^(#[^ ]+)\ ([^ ]+) ]]; then
		local channel="${BASH_REMATCH[1]}"
		local nick="${BASH_REMATCH[2]}"
		if access_check_capab "halfop" "$sender" "$channel"; then
			send_modes "$channel" "-h $nick"
		else
			access_fail "$sender" "make the bot dehalfop somebody" "halfop"
		fi
	else
		local sendernick
		parse_hostmask_nick "$sender" 'sendernick'
		feedback_bad_syntax "$sendernick" "dehalfop" "<#channel> <nick>"
	fi
}

module_assign_mode_handler_voice() {
	local sender="$1"
	local sendon_channel="$2"
	local parameters="$3"
	if [[ "$parameters" =~ ^(#[^ ]+)\ ([^ ]+) ]]; then
		local channel="${BASH_REMATCH[1]}"
		local nick="${BASH_REMATCH[2]}"
		if access_check_capab "voice" "$sender" "$channel"; then
			send_modes "$channel" "+v $nick"
		else
			access_fail "$sender" "make the bot give voice to somebody" "voice"
		fi
	else
		local sendernick
		parse_hostmask_nick "$sender" 'sendernick'
		feedback_bad_syntax "$sendernick" "voice" "<#channel> <nick>"
	fi
}

module_assign_mode_handler_devoice() {
	local sender="$1"
	local sendon_channel="$2"
	local parameters="$3"
	if [[ "$parameters" =~ ^(#[^ ]+)\ ([^ ]+) ]]; then
		local channel="${BASH_REMATCH[1]}"
		local nick="${BASH_REMATCH[2]}"
		if access_check_capab "voice" "$sender" "$channel"; then
			send_modes "$channel" "-v $nick"
		else
			access_fail "$sender" "make the bot take voice from somebody" "voice"
		fi
	else
		local sendernick
		parse_hostmask_nick "$sender" 'sendernick'
		feedback_bad_syntax "$sendernick" "devoice" "<#channel> <nick>"
	fi
}

module_assign_mode_handler_protect() {
	local sender="$1"
	local sendon_channel="$2"
	local parameters="$3"
	if [[ "$parameters" =~ ^(#[^ ]+)\ ([^ ]+) ]]; then
		local channel="${BASH_REMATCH[1]}"
		local nick="${BASH_REMATCH[2]}"
		if access_check_capab "protect" "$sender" "$channel"; then
			send_modes "$channel" "+a $nick"
		else
			access_fail "$sender" "make the bot protect somebody" "protect"
		fi
	else
		local sendernick
		parse_hostmask_nick "$sender" 'sendernick'
		feedback_bad_syntax "$sendernick" "protect" "<#channel> <nick>"
	fi
}

module_assign_mode_handler_deprotect() {
	local sender="$1"
	local sendon_channel="$2"
	local parameters="$3"
	if [[ "$parameters" =~ ^(#[^ ]+)\ ([^ ]+) ]]; then
		local channel="${BASH_REMATCH[1]}"
		local nick="${BASH_REMATCH[2]}"
		if access_check_capab "protect" "$sender" "$channel"; then
			send_modes "$channel" "-a $nick"
		else
			access_fail "$sender" "make the bot deprotect somebody" "protect"
		fi
	else
		local sendernick
		parse_hostmask_nick "$sender" 'sendernick'
		feedback_bad_syntax "$sendernick" "deprotect" "<#channel> <nick>"
	fi
}

module_assign_mode_handler_topic() {
	local sender="$1"
	local sendon_channel="$2"
	local parameters="$3"
	if [[ "$parameters" =~ ^(#[^ ]+)\ (.+) ]]; then
		local channel="${BASH_REMATCH[1]}"
		local message="${BASH_REMATCH[2]}"
		if access_check_capab "topic" "$sender" "$channel"; then
			send_topic "$channel" "$message"
		else
			access_fail "$sender" "change the topic" "topic"
		fi
	else
		local sendernick
		parse_hostmask_nick "$sender" 'sendernick'
		feedback_bad_syntax "$sendernick" "topic" "<#channel> <new topic>"
	fi
}