Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gajim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Weblate
gajim
Commits
7c1f4bf2
Commit
7c1f4bf2
authored
14 years ago
by
Alexander Cherniuk
Browse files
Options
Downloads
Patches
Plain Diff
Rewrote the command_system/implementation/custom.py
parent
44fb0529
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/command_system/implementation/custom.py
+61
-30
61 additions, 30 deletions
src/command_system/implementation/custom.py
with
61 additions
and
30 deletions
src/command_system/implementation/custom.py
+
61
−
30
View file @
7c1f4bf2
# 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 command
s
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
h
er
e
will be
available only to a
group chat.
host. Therefore command
s
defined
inside of the contain
er 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
.
"
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment