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
6a20a33b
Commit
6a20a33b
authored
15 years ago
by
red-agent
Browse files
Options
Downloads
Patches
Plain Diff
Dropped in an implementation of standard commands
parent
880952b5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/commands/__init__.py
+20
-0
20 additions, 0 deletions
src/commands/__init__.py
src/commands/implementation.py
+142
-0
142 additions, 0 deletions
src/commands/implementation.py
src/commands/middleware.py
+18
-0
18 additions, 0 deletions
src/commands/middleware.py
with
180 additions
and
0 deletions
src/commands/__init__.py
+
20
−
0
View file @
6a20a33b
# Copyright (C) 2009 red-agent <hell.director@gmail.com>
#
# 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.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
The command system providing scalable and convenient architecture in combination
with declarative way of defining commands and a fair amount of automatization
for routine processes.
"""
This diff is collapsed.
Click to expand it.
src/commands/implementation.py
+
142
−
0
View file @
6a20a33b
...
...
@@ -17,7 +17,10 @@
Provides an actual implementation of the standard commands.
"""
import
dialogs
from
common
import
gajim
from
common
import
helpers
from
common.exceptions
import
GajimGeneralException
from
framework
import
command
,
CommandError
from
middleware
import
ChatMiddleware
...
...
@@ -120,3 +123,142 @@ class GroupChatCommands(CommonCommands):
IS_COMMAND_PROCESSOR
=
True
INHERITED
=
True
@command
(
raw
=
True
)
def
nick
(
self
,
new_nick
):
"""
Change your nickname in a group chat
"""
try
:
new_nick
=
helpers
.
parse_resource
(
new_nick
)
except
Exception
:
raise
CommandError
(
_
(
"
Invalid nickname
"
))
self
.
connection
.
join_gc
(
new_nick
,
self
.
room_jid
,
None
,
change_nick
=
True
)
@command
(
'
query
'
,
raw
=
True
)
def
chat
(
self
,
nick
):
"""
Open a private chat window with a specified occupant
"""
nicks
=
gajim
.
contacts
.
get_nick_list
(
self
.
account
,
self
.
room_jid
)
if
nick
in
nicks
:
self
.
on_send_pm
(
nick
=
nick
)
else
:
raise
CommandError
(
_
(
"
Nickname not found
"
))
@command
(
'
msg
'
)
def
message
(
self
,
nick
,
*
a_message
):
"""
Open a private chat window with a specified occupant and send him a
message
"""
a_message
=
self
.
collect
(
a_message
,
False
)
nicks
=
gajim
.
contacts
.
get_nick_list
(
self
.
account
,
self
.
room_jid
)
if
nick
in
nicks
:
self
.
on_send_pm
(
nick
=
nick
,
msg
=
a_message
)
else
:
raise
CommandError
(
_
(
"
Nickname not found
"
))
@command
(
raw
=
True
,
empty
=
True
)
def
topic
(
self
,
new_topic
):
"""
Display or change a group chat topic
"""
if
new_topic
:
self
.
connection
.
send_gc_subject
(
self
.
room_jid
,
new_topic
)
else
:
return
self
.
subject
@command
def
invite
(
self
,
jid
,
*
reason
):
"""
Invite a user to a room for a reason
"""
reason
=
self
.
collect
(
reason
)
self
.
connection
.
send_invite
(
self
.
room_jid
,
jid
,
reason
)
return
_
(
"
Invited %s to %s
"
)
%
(
jid
,
self
.
room_jid
)
@command
def
join
(
self
,
jid
,
*
nick
):
"""
Join a group chat given by a jid, optionally using given nickname
"""
nick
=
self
.
collect
(
nick
)
or
self
.
nick
if
'
@
'
not
in
jid
:
jid
=
jid
+
'
@
'
+
gajim
.
get_server_from_jid
(
self
.
room_jid
)
try
:
gajim
.
interface
.
instances
[
self
.
account
][
'
join_gc
'
].
window
.
present
()
except
KeyError
:
try
:
dialogs
.
JoinGroupchatWindow
(
account
=
None
,
room_jid
=
jid
,
nick
=
nick
)
except
GajimGeneralException
:
pass
@command
(
'
part
'
,
'
close
'
,
raw
=
True
,
empty
=
True
)
def
leave
(
self
,
reason
):
"""
Leave the groupchat, optionally giving a reason, and close tab or window
"""
self
.
parent_win
.
remove_tab
(
self
,
self
.
parent_win
.
CLOSE_COMMAND
,
reason
)
@command
def
ban
(
self
,
who
,
*
reason
):
"""
Ban user by a nick or a jid from a groupchat
If given nickname is not found it will be treated as a jid.
"""
reason
=
self
.
collect
(
reason
,
none
=
False
)
if
who
in
gajim
.
contacts
.
get_nick_list
(
self
.
account
,
self
.
room_jid
):
contact
=
gajim
.
contacts
.
get_gc_contact
(
self
.
account
,
self
.
room_jid
,
who
)
who
=
contact
.
jid
self
.
connection
.
gc_set_affiliation
(
self
.
room_jid
,
who
,
'
outcast
'
,
reason
)
@command
def
kick
(
self
,
who
,
*
reason
):
"""
Kick user by a nick from a groupchat
"""
reason
=
self
.
collect
(
reason
,
none
=
False
)
if
not
who
in
gajim
.
contacts
.
get_nick_list
(
self
.
account
,
self
.
room_jid
):
raise
CommandError
(
_
(
"
Nickname not found
"
))
self
.
connection
.
gc_set_role
(
self
.
room_jid
,
who
,
'
none
'
,
reason
)
@command
def
names
(
self
,
verbose
=
False
):
"""
Display names of all group chat occupants
"""
get_contact
=
lambda
nick
:
gajim
.
contacts
.
get_gc_contact
(
self
.
account
,
self
.
room_jid
,
nick
)
nicks
=
gajim
.
contacts
.
get_nick_list
(
self
.
account
,
self
.
room_jid
)
# First we do alpha-numeric sort and then role-based one.
nicks
.
sort
()
nicks
.
sort
(
key
=
lambda
nick
:
get_contact
(
nick
).
role
)
if
verbose
:
for
nick
in
nicks
:
contact
=
get_contact
(
nick
)
role
=
helpers
.
get_uf_role
(
contact
.
role
)
affiliation
=
helpers
.
get_uf_affiliation
(
contact
.
affiliation
)
self
.
echo
(
"
%s - %s - %s
"
%
(
nick
,
role
,
affiliation
))
else
:
return
'
,
'
.
join
(
nicks
)
@command
(
raw
=
True
)
def
block
(
self
,
who
):
"""
Forbid an occupant to send you public or private messages
"""
self
.
on_block
(
None
,
who
)
@command
(
raw
=
True
)
def
unblock
(
self
,
who
):
"""
Allow an occupant to send you public or privates messages
"""
self
.
on_unblock
(
None
,
who
)
This diff is collapsed.
Click to expand it.
src/commands/middleware.py
+
18
−
0
View file @
6a20a33b
...
...
@@ -19,6 +19,8 @@ would be dropped in. Defines a little bit of scaffolding to support interaction
between the two and a few utility methods so you don
'
t need to dig up the host
code to write basic commands.
"""
from
common
import
gajim
from
types
import
StringTypes
from
framework
import
CommandProcessor
,
CommandError
from
traceback
import
print_exc
...
...
@@ -94,3 +96,19 @@ class ChatMiddleware(CommandProcessor):
using ctrl + up/down arrow keys.
"""
self
.
save_sent_message
(
text
)
def
collect
(
self
,
arguments
,
empty
=
True
,
separator
=
'
'
,
none
=
True
):
"""
Might come in handy in case if you want to map some arguments and
collect the rest of them into a string.
"""
if
not
empty
and
not
arguments
:
raise
CommandError
(
_
(
"
Missing argument
"
))
return
None
if
not
arguments
and
none
else
separator
.
join
(
arguments
)
@property
def
connection
(
self
):
"""
Get the current connection object.
"""
return
gajim
.
connections
[
self
.
account
]
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