Skip to content
chatoob.py 2.11 KiB
Newer Older
# -*- coding: utf-8 -*-

Romain Bignon's avatar
Romain Bignon committed
# Copyright(C) 2010-2011 Christophe Benz
Romain Bignon's avatar
Romain Bignon committed
# This file is part of weboob.
Romain Bignon's avatar
Romain Bignon committed
# weboob 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.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Romain Bignon's avatar
Romain Bignon committed
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
Romain Bignon's avatar
Romain Bignon committed
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.tools.application.repl import ReplApplication
from weboob.capabilities.chat import ICapChat
from weboob.capabilities.contact import ICapContact, Contact


__all__ = ['Chatoob']


class Chatoob(ReplApplication):
    APPNAME = 'chatoob'
Romain Bignon's avatar
Romain Bignon committed
    VERSION = '0.9.1'
Romain Bignon's avatar
Romain Bignon committed
    COPYRIGHT = 'Copyright(C) 2010-2011 Christophe Benz'
    DESCRIPTION = 'Console application allowing to chat with contacts on various websites.'

    def on_new_chat_message(self, message):
        print 'on_new_chat_message: %s' % message

    def do_list(self, line):
        """
        list
        for backend, contact in self.do('iter_contacts', status=Contact.STATUS_ONLINE, caps=ICapContact):
Romain Bignon's avatar
Romain Bignon committed
        self.flush()
    def do_messages(self, line):
        """
        messages

        Get messages.
        """
        for backend, message in self.do('iter_chat_messages'):
Romain Bignon's avatar
Romain Bignon committed
        self.flush()
    def do_send(self, line):
        """
        send CONTACT MESSAGE

        Send a message to the specified contact.
        """
Christophe Benz's avatar
Christophe Benz committed
        _id, message = self.parse_command_args(line, 2, 2)
        for backend, result in self.do('send_chat_message', _id, message):
            if not result:
                logging.error(u'Failed to send message to contact id="%s" on backend "%s"' % (_id, backend.name))