custom.py 4.51 KB
Newer Older
1 2
# Copyright (c) 2009-2010, Alexander Cherniuk (ts33kr@gmail.com)
# All rights reserved.
3
#
4 5 6
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
7
#
8 9
# * Redistributions of source code must retain the above copyright
#   notice, this list of conditions and the following disclaimer.
10
#
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
# * Redistributions in binary form must reproduce the above copyright
#   notice, this list of conditions and the following disclaimer in the
#   documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 27

"""
28 29
This module contains examples of how to create your own commands, by
creating a new command container, bounded to a specific command host,
Alexander Krotov's avatar
Alexander Krotov committed
30
and defining a set of commands inside of it.
31

32 33 34
Keep in mind that this module is not being loaded from anywhere, so the
code in here will not be executed and commands defined here will not be
detected.
35 36
"""

André's avatar
André committed
37 38
from gajim.command_system.framework import CommandContainer, command, doc
from gajim.command_system.implementation.hosts import ChatCommands, PrivateChatCommands, GroupChatCommands
39 40 41

class CustomCommonCommands(CommandContainer):
    """
42 43 44 45
    The AUTOMATIC class variable, set to a positive value, instructs the
    command system to automatically discover the command container and
    enable it.

46
    This command container bounds to all three available in the default
47
    implementation command hosts. This means that commands defined in
48
    this container will be available to all: chat, private chat and a
49
    group chat.
50 51
    """

52 53
    AUTOMATIC = True
    HOSTS = ChatCommands, PrivateChatCommands, GroupChatCommands
54 55 56 57 58 59 60

    @command
    def dance(self):
        """
        First line of the doc string is called a description and will be
        programmatically extracted and formatted.

61
        After that you can give more help, like explanation of the
Alexander Krotov's avatar
Alexander Krotov committed
62
        options. This one will be programmatically extracted and
63
        formatted too.
64

65 66
        After all the documentation - there will be autogenerated (based
        on the method signature) usage information appended. You can
67
        turn it off, if you want.
68
        """
69
        return "I don't dance."
70 71 72 73

class CustomChatCommands(CommandContainer):
    """
    This command container bounds only to the ChatCommands command host.
74 75
    Therefore commands defined inside of the container will be available
    only to a chat.
76 77
    """

78
    AUTOMATIC = True
79
    HOSTS = ChatCommands,
80

81
    @command("squal", "bawl")
82
    def sing(self):
83 84 85 86 87 88 89 90 91 92
        """
        This command has an additional aliases. It means the command will
        be available under three names: sing (the native name), squal
        (the first alias), bawl (the second alias).

        You can turn off the usage of the native name, if you want, and
        specify a name or a set of names, as aliases, under which a
        command will be available.
        """
        return "Buy yourself a stereo."
93 94 95

class CustomPrivateChatCommands(CommandContainer):
    """
96
    This command container bounds only to the PrivateChatCommands
97 98
    command host. Therefore commands defined inside of the container
    will be available only to a private chat.
99 100
    """

101
    AUTOMATIC = True
102
    HOSTS = PrivateChatCommands,
103 104

    @command
105
    #Example string. Do not translate
106
    @doc(_("The same as using a doc-string, except it supports translation"))
107
    def make_coffee(self):
108
        return "I'm not a coffee machine!"
109 110 111

class CustomGroupChatCommands(CommandContainer):
    """
112
    This command container bounds only to the GroupChatCommands command
113 114
    host. Therefore commands defined inside of the container will be
    available only to a group chat.
115 116
    """

117
    AUTOMATIC = True
118
    HOSTS = GroupChatCommands,
119 120 121

    @command
    def fetch(self):
122
        return "Buy yourself a dog."