Skip to content

Commit 9a1d597

Browse files
committed
IRCClient can give and revoke channel modes operator and voice.
1 parent 160afae commit 9a1d597

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

fredirc/client.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
from fredirc import messages
1616
from fredirc.errors import ConnectionTimeoutError
17+
from fredirc.messages import ChannelMode
18+
from fredirc.parsing import ChannelModeChange
1719
from fredirc.processor import MessageProcessor
1820

1921

@@ -206,6 +208,62 @@ def pong(self):
206208
""" Send a pong message to the server. """
207209
self._send_message(messages.pong(self._state.server))
208210

211+
def give_op(self, channel, user):
212+
""" Grant operator rights to a user on a channel.
213+
214+
If the client is no operator, the server will respond with an
215+
error message that can be handled via
216+
:py:meth:`fredirc.handler.handle_error`.
217+
218+
Args:
219+
channel (str): the channel
220+
user (str): the affected user
221+
"""
222+
mode_change = ChannelModeChange(True, ChannelMode.OPERATOR, (user,))
223+
self._send_message(messages.channel_mode(channel, mode_change))
224+
225+
def revoke_op(self, channel, user):
226+
""" Revoke operator rights from user on a channel.
227+
228+
If the client is no operator, the server will respond with an
229+
error message that can be handled via
230+
:py:meth:`fredirc.handler.handle_error`.
231+
232+
Args:
233+
channel (str): the channel
234+
user (str): the affected user
235+
"""
236+
mode_change = ChannelModeChange(False, ChannelMode.OPERATOR, (user,))
237+
self._send_message(messages.channel_mode(channel, mode_change))
238+
239+
def give_voice(self, channel, user):
240+
""" Grant voice rights to a user on a channel.
241+
242+
If the client is no operator, the server will respond with an
243+
error message that can be handled via
244+
:py:meth:`fredirc.handler.handle_error`.
245+
246+
Args:
247+
channel (str): the channel
248+
user (str): the affected user
249+
"""
250+
mode_change = ChannelModeChange(True, ChannelMode.VOICE, (user,))
251+
self._send_message(messages.channel_mode(channel, mode_change))
252+
253+
def revoke_voice(self, channel, user):
254+
""" Revoke voice rights from user on a channel.
255+
256+
If the client is no operator, the server will respond with an
257+
error message that can be handled via
258+
:py:meth:`fredirc.handler.handle_error`.
259+
260+
Args:
261+
channel (str): the channel
262+
user (str): the affected user
263+
"""
264+
mode_change = ChannelModeChange(False, ChannelMode.VOICE, (user,))
265+
self._send_message(messages.channel_mode(channel, mode_change))
266+
209267
def is_op_in(self, channel):
210268
"""
211269
Check if this client has operator rights in the given channel.

fredirc/messages.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,13 @@ def part(channels, message):
233233
return '{part_cmd} {channels} :{message}'.format(
234234
part_cmd=Cmd.PART, channels=','.join(channels), message=message)
235235

236+
237+
def channel_mode(channel, mode_change):
238+
"""
239+
Args:
240+
mode_change (ChannelModelChange)
241+
"""
242+
change = '+' if mode_change.added else '-'
243+
return '{mode_cmd} {channel} {change}{mode} {params}'.format(
244+
mode_cmd=Cmd.MODE, channel=channel, change=change,
245+
mode=mode_change.mode, params=' '.join(mode_change.params))

fredirc/parsing.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ def parse_channel_mode_params(params):
173173
class ChannelModeChange(object):
174174
""" Object that contains information about a changed channel mode.
175175
176+
Note: Does not contain the channel name itself, but only the parameters
177+
of the mode-message.
178+
176179
Args:
177180
added (bool): True, if the mode was added. False, otherwise.
178181
mode (str): the mode
@@ -188,7 +191,7 @@ def __init__(self, added, mode, params=None):
188191
class MessageTarget(object):
189192
""" Represents a target of an IRC message.
190193
191-
Corresponds to the non-terminal 'msgto' in IRC's grammer.
194+
Corresponds to the non-terminal 'msgto' in IRC's grammar.
192195
"""
193196

194197
def __init__(self, channel=None, nick=None, user=None, host=None,

0 commit comments

Comments
 (0)