Skip to content

Commit

Permalink
Check if command is enabled for member when executing default command
Browse files Browse the repository at this point in the history
  • Loading branch information
ztefn committed Jun 23, 2024
1 parent f039cb3 commit e0773b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/command.vala
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,7 @@ namespace Haguichi {
if (active_commands != null) {
var number = 1;
foreach (CustomCommand command in active_commands) {
// Enable if member is online or command doesn't use address variable
var enabled = (member.status.status_int == 1 || (!command.cmd_ipv4.contains ("%A") && !command.cmd_ipv6.contains ("%A")));
win.action_set_enabled ("win.run-command-%d".printf (number), enabled);
win.action_set_enabled ("win.run-command-%d".printf (number), command.enabled_for_member (member));
number ++;
}
}
Expand Down Expand Up @@ -270,9 +268,11 @@ namespace Haguichi {
}

public static void execute_default_command (Member member) {
var cmd = default_command.return_for_member (member);
debug ("execute_default_command: %s", cmd);
execute (cmd);
if (default_command.enabled_for_member (member)) {
var cmd = default_command.return_for_member (member);
debug ("execute_default_command: %s", cmd);
execute (cmd);
}
}

public static void open_uri (string uri) {
Expand Down
7 changes: 6 additions & 1 deletion src/custom-command.vala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ namespace Haguichi {
Command.exists (Command.replace_variables (cmd_ipv6, "", "", "").split (" ", 0)[0]));
}

public string return_for_member (Member? member) {
public bool enabled_for_member (Member member) {
// Enabled if member is online or command doesn't use address variable
return member.status.status_int == 1 || (!cmd_ipv4.contains ("%A") && !cmd_ipv6.contains ("%A"));
}

public string return_for_member (Member member) {
string command = "";
string address = "";

Expand Down

0 comments on commit e0773b0

Please sign in to comment.