aboutsummaryrefslogtreecommitdiff
path: root/main/src
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2017-05-13 17:45:06 +0200
committerMarvin W <git@larma.de>2017-08-17 19:56:10 +0200
commit781d241b93c1d7696cafa524f0c6e00d84579951 (patch)
tree2a97ff9327b225f91ae9ef131b9235dafda3fdc5 /main/src
parent5dc460fc1a72a3dfe83453f4c6683be20a1a2a2d (diff)
downloaddino-781d241b93c1d7696cafa524f0c6e00d84579951.tar.gz
dino-781d241b93c1d7696cafa524f0c6e00d84579951.zip
add plugin api for text commands
Diffstat (limited to 'main/src')
-rw-r--r--main/src/ui/chat_input/view.vala34
1 files changed, 25 insertions, 9 deletions
diff --git a/main/src/ui/chat_input/view.vala b/main/src/ui/chat_input/view.vala
index d8a31a22..a7c3099c 100644
--- a/main/src/ui/chat_input/view.vala
+++ b/main/src/ui/chat_input/view.vala
@@ -52,30 +52,46 @@ public class View : Box {
private void send_text() {
string text = text_input.buffer.text;
+ text_input.buffer.text = "";
if (text.has_prefix("/")) {
string[] token = text.split(" ", 2);
switch(token[0]) {
- case "/kick":
- stream_interactor.get_module(MucManager.IDENTITY).kick(conversation.account, conversation.counterpart, token[1]);
- break;
case "/me":
- stream_interactor.get_module(MessageProcessor.IDENTITY).send_message(text, conversation);
+ // Just send as is.
+ break;
+ case "/say":
+ if (token.length == 1) return;
+ text = token[1];
break;
+ case "/kick":
+ stream_interactor.get_module(MucManager.IDENTITY).kick(conversation.account, conversation.counterpart, token[1]);
+ return;
case "/nick":
stream_interactor.get_module(MucManager.IDENTITY).change_nick(conversation.account, conversation.counterpart, token[1]);
- break;
+ return;
case "/ping":
Xmpp.Core.XmppStream? stream = stream_interactor.get_stream(conversation.account);
stream.get_module(Xmpp.Xep.Ping.Module.IDENTITY).send_ping(stream, conversation.counterpart.to_string() + "/" + token[1], null);
- break;
+ return;
case "/topic":
stream_interactor.get_module(MucManager.IDENTITY).change_subject(conversation.account, conversation.counterpart, token[1]);
+ return;
+ default:
+ if (token[0].has_prefix("//")) {
+ text = text.substring(1);
+ } else {
+ string cmd_name = token[0].substring(1);
+ Dino.Application app = GLib.Application.get_default() as Dino.Application;
+ if (app != null && app.plugin_registry.text_commands.has_key(cmd_name)) {
+ string? new_text = app.plugin_registry.text_commands[cmd_name].handle_command(token[1], conversation);
+ if (new_text == null) return;
+ text = (!)new_text;
+ }
+ }
break;
}
- } else {
- stream_interactor.get_module(MessageProcessor.IDENTITY).send_message(text, conversation);
}
- text_input.buffer.text = "";
+ stream_interactor.get_module(MessageProcessor.IDENTITY).send_message(text, conversation);
}
private bool on_text_input_key_press(EventKey event) {