2010-08-06 00:49:46 +02:00
|
|
|
# Copyright (c) 2009-2010, Alexander Cherniuk (ts33kr@gmail.com)
|
|
|
|
# All rights reserved.
|
2009-10-02 22:57:11 +02:00
|
|
|
#
|
2010-08-06 00:49:46 +02:00
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
2009-10-02 22:57:11 +02:00
|
|
|
#
|
2010-08-06 00:49:46 +02:00
|
|
|
# * Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
2009-10-02 22:57:11 +02:00
|
|
|
#
|
2010-08-06 00:49:46 +02:00
|
|
|
# * 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.
|
2009-10-02 22:57:11 +02:00
|
|
|
|
|
|
|
"""
|
2010-08-06 00:49:46 +02:00
|
|
|
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.
|
2009-10-02 22:57:11 +02:00
|
|
|
|
2010-08-06 00:49:46 +02:00
|
|
|
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.
|
2009-10-02 22:57:11 +02:00
|
|
|
"""
|
|
|
|
|
2010-03-19 02:22:17 +01:00
|
|
|
from ..framework import CommandContainer, command, doc
|
2013-01-01 21:06:16 +01:00
|
|
|
from .hosts import *
|
2009-10-02 22:57:11 +02:00
|
|
|
|
|
|
|
class CustomCommonCommands(CommandContainer):
|
|
|
|
"""
|
2010-08-06 00:49:46 +02:00
|
|
|
The AUTOMATIC class variable, set to a positive value, instructs the
|
|
|
|
command system to automatically discover the command container and
|
|
|
|
enable it.
|
|
|
|
|
2009-10-02 22:57:11 +02:00
|
|
|
This command container bounds to all three available in the default
|
2010-02-26 11:35:09 +01:00
|
|
|
implementation command hosts. This means that commands defined in
|
2010-08-06 00:49:46 +02:00
|
|
|
this container will be available to all: chat, private chat and a
|
2010-02-26 11:35:09 +01:00
|
|
|
group chat.
|
2009-10-02 22:57:11 +02:00
|
|
|
"""
|
|
|
|
|
2010-08-06 00:49:46 +02:00
|
|
|
AUTOMATIC = True
|
|
|
|
HOSTS = ChatCommands, PrivateChatCommands, GroupChatCommands
|
2009-10-02 22:57:11 +02:00
|
|
|
|
|
|
|
@command
|
|
|
|
def dance(self):
|
|
|
|
"""
|
|
|
|
First line of the doc string is called a description and will be
|
|
|
|
programmatically extracted and formatted.
|
|
|
|
|
2010-02-26 11:35:09 +01:00
|
|
|
After that you can give more help, like explanation of the
|
|
|
|
options. This one will be programatically extracted and
|
|
|
|
formatted too.
|
2009-10-02 22:57:11 +02:00
|
|
|
|
2010-02-26 11:35:09 +01:00
|
|
|
After all the documentation - there will be autogenerated (based
|
|
|
|
on the method signature) usage information appended. You can
|
2010-08-06 00:49:46 +02:00
|
|
|
turn it off, if you want.
|
2009-10-02 22:57:11 +02:00
|
|
|
"""
|
2010-08-06 00:49:46 +02:00
|
|
|
return "I don't dance."
|
2009-10-02 22:57:11 +02:00
|
|
|
|
|
|
|
class CustomChatCommands(CommandContainer):
|
|
|
|
"""
|
|
|
|
This command container bounds only to the ChatCommands command host.
|
2010-08-06 00:49:46 +02:00
|
|
|
Therefore commands defined inside of the container will be available
|
|
|
|
only to a chat.
|
2009-10-02 22:57:11 +02:00
|
|
|
"""
|
|
|
|
|
2010-08-06 00:49:46 +02:00
|
|
|
AUTOMATIC = True
|
2010-08-06 20:47:34 +02:00
|
|
|
HOSTS = ChatCommands,
|
2009-10-02 22:57:11 +02:00
|
|
|
|
2010-08-06 00:49:46 +02:00
|
|
|
@command("squal", "bawl")
|
2009-10-02 22:57:11 +02:00
|
|
|
def sing(self):
|
2010-08-06 00:49:46 +02:00
|
|
|
"""
|
|
|
|
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."
|
2009-10-02 22:57:11 +02:00
|
|
|
|
|
|
|
class CustomPrivateChatCommands(CommandContainer):
|
|
|
|
"""
|
2010-02-26 11:35:09 +01:00
|
|
|
This command container bounds only to the PrivateChatCommands
|
2010-08-06 00:49:46 +02:00
|
|
|
command host. Therefore commands defined inside of the container
|
|
|
|
will be available only to a private chat.
|
2009-10-02 22:57:11 +02:00
|
|
|
"""
|
|
|
|
|
2010-08-06 00:49:46 +02:00
|
|
|
AUTOMATIC = True
|
2010-08-06 20:47:34 +02:00
|
|
|
HOSTS = PrivateChatCommands,
|
2009-10-02 22:57:11 +02:00
|
|
|
|
|
|
|
@command
|
2014-05-29 23:28:25 +02:00
|
|
|
#Example string. Do not translate
|
2010-08-06 00:49:46 +02:00
|
|
|
@doc(_("The same as using a doc-string, except it supports translation"))
|
2009-10-02 22:57:11 +02:00
|
|
|
def make_coffee(self):
|
2010-08-06 00:49:46 +02:00
|
|
|
return "I'm not a coffee machine!"
|
2009-10-02 22:57:11 +02:00
|
|
|
|
|
|
|
class CustomGroupChatCommands(CommandContainer):
|
|
|
|
"""
|
2010-02-26 11:35:09 +01:00
|
|
|
This command container bounds only to the GroupChatCommands command
|
2010-08-06 00:49:46 +02:00
|
|
|
host. Therefore commands defined inside of the container will be
|
|
|
|
available only to a group chat.
|
2009-10-02 22:57:11 +02:00
|
|
|
"""
|
|
|
|
|
2010-08-06 00:49:46 +02:00
|
|
|
AUTOMATIC = True
|
2010-08-06 20:47:34 +02:00
|
|
|
HOSTS = GroupChatCommands,
|
2009-10-02 22:57:11 +02:00
|
|
|
|
|
|
|
@command
|
|
|
|
def fetch(self):
|
2014-05-29 23:28:25 +02:00
|
|
|
return "Buy yourself a dog."
|