Skip to content

Commit

Permalink
Merge pull request #192 from jheddings/main
Browse files Browse the repository at this point in the history
Added support for NOTICE commands.
  • Loading branch information
jaraco committed Sep 13, 2021
2 parents 5ee34d8 + cf6ac8b commit b8fd3c7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
v19.1
=======

(Draft Release)

* Added server support for NOTICE commands.

v19.0.1
=======

Expand Down
24 changes: 19 additions & 5 deletions irc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ def _handle_incoming(self):
self._handle_line(line)

def _handle_line(self, line):
response = None

try:
log.debug('from %s: %s' % (self.client_ident(), line))
command, sep, params = line.partition(' ')
Expand All @@ -175,7 +177,7 @@ def _handle_line(self, line):
raise
except IRCError as e:
response = ':%s %s %s' % (self.server.servername, e.code, e.value)
log.error(response)
log.warning(response)
except Exception as e:
response = ':%s ERROR %r' % (self.server.servername, e)
log.error(response)
Expand Down Expand Up @@ -320,16 +322,28 @@ def handle_privmsg(self, params):
"""
Handle sending a private message to a user or channel.
"""
self._send_msg('PRIVMSG', params)

def handle_notice(self, params):
"""
Handle sending a notice to a user or channel.
"""
self._send_msg('NOTICE', params)

def _send_msg(self, cmd, params):
"""
A generic message handler (e.g. PRIVMSG and NOTICE)
"""
target, sep, msg = params.partition(' ')
if not msg:
raise IRCError.from_name('needmoreparams', 'PRIVMSG :Not enough parameters')
raise IRCError.from_name('needmoreparams', cmd + ' :Not enough parameters')

message = ':%s PRIVMSG %s %s' % (self.client_ident(), target, msg)
message = ':%s %s %s %s' % (self.client_ident(), cmd, target, msg)
if target.startswith('#') or target.startswith('$'):
# Message to channel. Check if the channel exists.
channel = self.server.channels.get(target)
if not channel:
raise IRCError.from_name('nosuchnick', 'PRIVMSG :%s' % target)
raise IRCError.from_name('nosuchnick', cmd + ' :%s' % target)

if channel.name not in self.channels:
# The user isn't in the channel.
Expand All @@ -342,7 +356,7 @@ def handle_privmsg(self, params):
# Message to user
client = self.server.clients.get(target, None)
if not client:
raise IRCError.from_name('nosuchnick', 'PRIVMSG :%s' % target)
raise IRCError.from_name('nosuchnick', cmd + ' :%s' % target)

client.send_queue.append(message)

Expand Down

0 comments on commit b8fd3c7

Please sign in to comment.