Package command_system :: Package implementation :: Module custom
[hide private]
[frames] | no frames]

Source Code for Module command_system.implementation.custom

  1  # Copyright (c) 2009-2010, Alexander Cherniuk (ts33kr@gmail.com) 
  2  # All rights reserved. 
  3  # 
  4  # Redistribution and use in source and binary forms, with or without 
  5  # modification, are permitted provided that the following conditions 
  6  # are met: 
  7  # 
  8  # * Redistributions of source code must retain the above copyright 
  9  #   notice, this list of conditions and the following disclaimer. 
 10  # 
 11  # * Redistributions in binary form must reproduce the above copyright 
 12  #   notice, this list of conditions and the following disclaimer in the 
 13  #   documentation and/or other materials provided with the distribution. 
 14  # 
 15  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 16  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 17  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
 18  # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
 19  # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 20  # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
 21  # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 22  # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
 23  # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 24  # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 25  # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 26   
 27  """ 
 28  This module contains examples of how to create your own commands, by 
 29  creating a new command container, bounded to a specific command host, 
 30  and definding a set of commands inside of it. 
 31   
 32  Keep in mind that this module is not being loaded from anywhere, so the 
 33  code in here will not be executed and commands defined here will not be 
 34  detected. 
 35  """ 
 36   
 37  from ..framework import CommandContainer, command, doc 
 38  from hosts import * 
39 40 -class CustomCommonCommands(CommandContainer):
41 """ 42 The AUTOMATIC class variable, set to a positive value, instructs the 43 command system to automatically discover the command container and 44 enable it. 45 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 AUTOMATIC = True 53 HOSTS = ChatCommands, PrivateChatCommands, GroupChatCommands 54 55 @command
56 - def dance(self):
57 """ 58 First line of the doc string is called a description and will be 59 programmatically extracted and formatted. 60 61 After that you can give more help, like explanation of the 62 options. This one will be programatically extracted and 63 formatted too. 64 65 After all the documentation - there will be autogenerated (based 66 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 -class CustomChatCommands(CommandContainer):
72 """ 73 This command container bounds only to the ChatCommands command host. 74 Therefore commands defined inside of the container will be available 75 only to a chat. 76 """ 77 78 AUTOMATIC = True 79 HOSTS = ChatCommands, 80 81 @command("squal", "bawl")
82 - def sing(self):
83 """ 84 This command has an additional aliases. It means the command will 85 be available under three names: sing (the native name), squal 86 (the first alias), bawl (the second alias). 87 88 You can turn off the usage of the native name, if you want, and 89 specify a name or a set of names, as aliases, under which a 90 command will be available. 91 """ 92 return "Buy yourself a stereo."
93
94 -class CustomPrivateChatCommands(CommandContainer):
95 """ 96 This command container bounds only to the PrivateChatCommands 97 command host. Therefore commands defined inside of the container 98 will be available only to a private chat. 99 """ 100 101 AUTOMATIC = True 102 HOSTS = PrivateChatCommands, 103 104 @command 105 @doc(_("The same as using a doc-string, except it supports translation"))
106 - def make_coffee(self):
107 return "I'm not a coffee machine!"
108
109 -class CustomGroupChatCommands(CommandContainer):
110 """ 111 This command container bounds only to the GroupChatCommands command 112 host. Therefore commands defined inside of the container will be 113 available only to a group chat. 114 """ 115 116 AUTOMATIC = True 117 HOSTS = GroupChatCommands, 118 119 @command
120 - def fetch(self):
121 return "Buy yourself a dog."
122