nemubot/nemubot/message/printer/IRC.py

71 lines
2.4 KiB
Python
Raw Normal View History

2014-10-05 16:19:20 +00:00
# -*- coding: utf-8 -*-
# Nemubot is a smart and modulable IM bot.
# Copyright (C) 2012-2015 Mercier Pierre-Olivier
2014-10-05 16:19:20 +00:00
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from nemubot.message import Text
from nemubot.message.visitor import AbstractVisitor
2014-10-05 16:19:20 +00:00
2014-11-09 13:11:54 +00:00
2014-10-05 16:19:20 +00:00
class IRC(AbstractVisitor):
def __init__(self):
self.pp = ""
def visit_Text(self, msg):
2014-10-05 16:19:20 +00:00
self.pp += "PRIVMSG %s :" % ",".join(msg.to)
if isinstance(msg.message, str):
self.pp += msg.message
else:
msg.message.accept(self)
self.pp += "\r\n"
def visit_DirectAsk(self, msg):
others = [to for to in msg.to if to != msg.designated]
# Avoid nick starting message when discussing on user channel
if len(others) != len(msg.to):
res = Text(msg.message,
server=msg.server, date=msg.date,
to=msg.to, frm=msg.frm)
2014-10-05 16:19:20 +00:00
res.accept(self)
if len(others):
res = Text("%s: %s" % (msg.designated, msg.message),
server=msg.server, date=msg.date,
to=others, frm=msg.frm)
2014-10-05 16:19:20 +00:00
res.accept(self)
def visit_Command(self, msg):
res = Text("!%s%s%s" % (msg.cmd,
" " if len(msg.args) else "",
" ".join(msg.args)),
server=msg.server, date=msg.date,
to=msg.to, frm=msg.frm)
2014-10-05 16:19:20 +00:00
res.accept(self)
def visit_OwnerCommand(self, msg):
res = Text("`%s%s%s" % (msg.cmd,
" " if len(msg.args) else "",
" ".join(msg.args)),
server=msg.server, date=msg.date,
to=msg.to, frm=msg.frm)
2014-10-05 16:19:20 +00:00
res.accept(self)