Rewrote the command_system/implementation/custom.py

This commit is contained in:
Alexander Cherniuk 2010-08-06 01:49:46 +03:00
parent 44fb0529d0
commit 7c1f4bf23e
1 changed files with 61 additions and 30 deletions

View File

@ -1,38 +1,56 @@
# Copyright (C) 2009-2010 Alexander Cherniuk <ts33kr@gmail.com>
# Copyright (c) 2009-2010, Alexander Cherniuk (ts33kr@gmail.com)
# All rights reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 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 General Public License for more details.
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# * 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.
"""
The module contains examples of how to create your own commands, by
creating a new command container and definding a set of commands.
This module contains examples of how to create your own commands, by
creating a new command container, bounded to a specific command host,
and definding a set of commands inside of it.
Keep in mind that this module is not being loaded, so the code will not
be executed and commands defined here will not be detected.
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.
"""
from ..framework import CommandContainer, command, doc
from hosts import ChatCommands, PrivateChatCommands, GroupChatCommands
from hosts import *
class CustomCommonCommands(CommandContainer):
"""
The AUTOMATIC class variable, set to a positive value, instructs the
command system to automatically discover the command container and
enable it.
This command container bounds to all three available in the default
implementation command hosts. This means that commands defined in
this container will be available to all - chat, private chat and a
this container will be available to all: chat, private chat and a
group chat.
"""
HOSTS = (ChatCommands, PrivateChatCommands, GroupChatCommands)
AUTOMATIC = True
HOSTS = ChatCommands, PrivateChatCommands, GroupChatCommands
@command
def dance(self):
@ -46,45 +64,58 @@ class CustomCommonCommands(CommandContainer):
After all the documentation - there will be autogenerated (based
on the method signature) usage information appended. You can
turn it off though, if you want.
turn it off, if you want.
"""
return "I can't dance, you stupid fuck, I'm just a command system! A cool one, though..."
return "I don't dance."
class CustomChatCommands(CommandContainer):
"""
This command container bounds only to the ChatCommands command host.
Therefore command defined here will be available only to a chat.
Therefore commands defined inside of the container will be available
only to a chat.
"""
AUTOMATIC = True
HOSTS = (ChatCommands,)
@doc(_("The same as using a doc-string, except it supports translation"))
@command
@command("squal", "bawl")
def sing(self):
return "Are you phreaking kidding me? Buy yourself a damn stereo..."
"""
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."
class CustomPrivateChatCommands(CommandContainer):
"""
This command container bounds only to the PrivateChatCommands
command host. Therefore command defined here will be available only
to a private chat.
command host. Therefore commands defined inside of the container
will be available only to a private chat.
"""
AUTOMATIC = True
HOSTS = (PrivateChatCommands,)
@command
@doc(_("The same as using a doc-string, except it supports translation"))
def make_coffee(self):
return "What do I look like, you ass? A coffee machine!?"
return "I'm not a coffee machine!"
class CustomGroupChatCommands(CommandContainer):
"""
This command container bounds only to the GroupChatCommands command
host. Therefore command defined here will be available only to a
group chat.
host. Therefore commands defined inside of the container will be
available only to a group chat.
"""
AUTOMATIC = True
HOSTS = (GroupChatCommands,)
@command
def fetch(self):
return "You should really buy yourself a dog and start torturing it instead of me..."
return "Buy yourself a dog."