Open SakiiR opened 7 years ago
Hi, I was able to have this working by using the function "config_option_set". Basically :
- server.options['autojoin'] = autojoins
- # TODO: Needs help here #PLS #TotallyLost (It doesn't want to work)
- r = weechat.config_write_option(jabber_config_file, server.options['autojoin'])
- weechat.prnt("", "Response: %s" % server.option_string("autojoin"))
+
+ r = weechat.config_option_set(server.options["autojoin"], autojoins, 1)
In fact server.options["autojoin"]
is already an object, pointing to the option in the configuration file.
It cannot be set as a string directly, but can be used as parameter to config_option_set
.
One other issue might be that the "/jroom " commands takes the nickname as optional parameter, so the way the args is parsed might need to be improved.
I quickly tried something like this as a workaround, but a cleaner parsing would be better :
diff --git a/jabber.py b/jabber.py
index 15873e4..860ced7 100644
--- a/jabber.py
+++ b/jabber.py
@@ -1736,10 +1736,16 @@ def jabber_cmd_room(data, buffer, args):
if args:
argv = args.split()
room = argv[0]
+ autojoin = "-autojoin" in argv
+
if len(argv) == 1:
nickname = None
+ elif len(argv) == 2:
+ nickname = argv[1] if argv[1] != "-autojoin" else None
+ autojoin = argv[1] == "-autojoin"
else:
nickname = argv[1]
+ autojoin = argv[2]
context = jabber_search_context(buffer)
server = context["server"]
if server:
@@ -1748,14 +1754,12 @@ def jabber_cmd_room(data, buffer, args):
buddy = server.add_muc(room, nickname)
if not buddy.chat:
server.add_chat(buddy)
- if "-autojoin" in argv:
+ if autojoin:
autojoins = [r.strip() for r in server.option_string("autojoin").split(',')]
autojoins.append(room)
autojoins = ", ".join(autojoins)
- server.options['autojoin'] = autojoins
- # TODO: Needs help here #PLS #TotallyLost (It doesn't want to work)
- r = weechat.config_write_option(jabber_config_file, server.options['autojoin'])
- weechat.prnt("", "Response: %s" % server.option_string("autojoin"))
+
+ r = weechat.config_option_set(server.options["autojoin"], autojoins, 1)
weechat.buffer_set(buddy.chat.buffer, "display", "auto")
weechat.buffer_set(buddy.chat.buffer, "nicklist", "1")
weechat.buffer_set(buddy.chat.buffer, "nicklist_display_groups", "1")
One last thought : in other jabber clients, the notion of "autojoin" for a MUC is not really handled like this. In fact AFAIK (at least on gajim and mcabber) they are manager through bookmarks : https://xmpp.org/extensions/xep-0048.html#format-conference The idea is that the user registers its autojoin list directly on the server, and not on a local configuration. It would have the advrantage to work across multiple clients, and would not require a configuration file modification. But it would require a little more work to implement the "bookmark" API in the plugin
Applied your patch !
I see now, I were right for the server.option[key]
, it is an object since it is defined in the script API.
struct t_config_option;
I couldn't find the definition in the source code.
typedef struct s_config_option
{
unsigned char *value;
/* [...] */
} t_config_option;
I just have to say okay about autojoin server handling. (good practice btw) in the xmpp
philosophy I guess.
Maybe in a next issue :)
btw, Argument Parsing can be done by https://docs.python.org/3/library/argparse.html
easily.
Just replying to say a room autojoin feature would be great.
@inolen just pull my branch ;)
Added autojoin Feature !
Not working yet, see the "#PLS" comment.
Working only by adding your room to the server.autojoin option IN the config file
jabber.conf
.Edit: Patch okay waiting for merge