1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-09-01 19:24:15 -04:00

Add slashguard feature

New command `/slashguard` tries to protect against typing ` /quit` by
not allowing a slash in the first 4 characters.
This commit is contained in:
Michael Vetter 2020-03-18 18:20:05 +01:00
parent ed97e3730a
commit 3c56b289ed
10 changed files with 54 additions and 1 deletions

View File

@ -1567,7 +1567,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ
// autocomplete boolean settings // autocomplete boolean settings
gchar *boolean_choices[] = { "/beep", "/intype", "/states", "/outtype", "/flash", "/splash", gchar *boolean_choices[] = { "/beep", "/intype", "/states", "/outtype", "/flash", "/splash",
"/history", "/vercheck", "/privileges", "/wrap", "/carbons", "/lastactivity", "/os"}; "/history", "/vercheck", "/privileges", "/wrap", "/carbons", "/lastactivity", "/os", "/slashguard"};
for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) { for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) {
result = autocomplete_param_with_func(input, boolean_choices[i], prefs_autocomplete_boolean_choice, previous, NULL); result = autocomplete_param_with_func(input, boolean_choices[i], prefs_autocomplete_boolean_choice, previous, NULL);

View File

@ -2418,6 +2418,23 @@ static struct cmd_t command_defs[] =
{ "message", "The corrected message."}) { "message", "The corrected message."})
CMD_NOEXAMPLES CMD_NOEXAMPLES
}, },
{ "/slashguard",
parse_args, 1, 1, &cons_slashguard_setting,
CMD_NOSUBFUNCS
CMD_MAINFUNC(cmd_slashguard)
CMD_TAGS(
CMD_TAG_UI,
CMD_TAG_CHAT)
CMD_SYN(
"/slashguard on|off")
CMD_DESC(
"Slashguard won't accept a slash in the first 4 characters of your input field. "
"It tries to protect you from typing ' /quit' and similar things in chats.")
CMD_ARGS(
{ "on|off", "Enable or disable slashguard." })
CMD_NOEXAMPLES
},
}; };
static GHashTable *search_index; static GHashTable *search_index;

View File

@ -8836,3 +8836,15 @@ cmd_correct(ProfWin *window, const char *const command, gchar **args)
win_println(window, THEME_DEFAULT, "!", "Command /correct only valid in regular chat windows."); win_println(window, THEME_DEFAULT, "!", "Command /correct only valid in regular chat windows.");
return TRUE; return TRUE;
} }
gboolean
cmd_slashguard(ProfWin *window, const char *const command, gchar **args)
{
if (args[0] == NULL) {
return FALSE;
}
_cmd_set_boolean_preference(args[0], command, "Slashguard", PREF_SLASH_GUARD);
return TRUE;
}

View File

@ -231,4 +231,5 @@ gboolean cmd_avatar(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_os(ProfWin *window, const char *const command, gchar **args); gboolean cmd_os(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_correction(ProfWin *window, const char *const command, gchar **args); gboolean cmd_correction(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_correct(ProfWin *window, const char *const command, gchar **args); gboolean cmd_correct(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_slashguard(ProfWin *window, const char *const command, gchar **args);
#endif #endif

View File

@ -1744,6 +1744,7 @@ _get_group(preference_t pref)
case PREF_STATUSBAR_ROOM: case PREF_STATUSBAR_ROOM:
case PREF_TITLEBAR_MUC_TITLE: case PREF_TITLEBAR_MUC_TITLE:
case PREF_HISTORY_COLOR_MUC: case PREF_HISTORY_COLOR_MUC:
case PREF_SLASH_GUARD:
return PREF_GROUP_UI; return PREF_GROUP_UI;
case PREF_STATES: case PREF_STATES:
case PREF_OUTTYPE: case PREF_OUTTYPE:
@ -2051,6 +2052,8 @@ _get_key(preference_t pref)
return "history.muc.color"; return "history.muc.color";
case PREF_AVATAR_CMD: case PREF_AVATAR_CMD:
return "avatar.cmd"; return "avatar.cmd";
case PREF_SLASH_GUARD:
return "slashguard";
default: default:
return NULL; return NULL;
} }

View File

@ -167,6 +167,7 @@ typedef enum {
PREF_CORRECTION_ALLOW, PREF_CORRECTION_ALLOW,
PREF_HISTORY_COLOR_MUC, PREF_HISTORY_COLOR_MUC,
PREF_AVATAR_CMD, PREF_AVATAR_CMD,
PREF_SLASH_GUARD,
} preference_t; } preference_t;
typedef struct prof_alias_t { typedef struct prof_alias_t {

View File

@ -2049,6 +2049,16 @@ cons_avatar_setting(void)
prefs_free_string(pref); prefs_free_string(pref);
} }
void
cons_slashguard_setting(void)
{
if (prefs_get_boolean(PREF_SLASH_GUARD)) {
cons_show("Slashguard (/slashguard) : ON");
} else {
cons_show("Slashguard (/slashguard) : OFF");
}
}
void void
cons_show_connection_prefs(void) cons_show_connection_prefs(void)
{ {

View File

@ -196,6 +196,13 @@ inp_readline(void)
} }
if (inp_line) { if (inp_line) {
if (!get_password && prefs_get_boolean(PREF_SLASH_GUARD)) {
char *res = (char*) memchr (inp_line+1, '/', 3);
if (res) {
cons_show("Your text contains a slash in the first 4 characters");
return NULL;
}
}
return strdup(inp_line); return strdup(inp_line);
} else { } else {
return NULL; return NULL;

View File

@ -320,6 +320,7 @@ void cons_color_setting(void);
void cons_os_setting(void); void cons_os_setting(void);
void cons_correction_setting(void); void cons_correction_setting(void);
void cons_avatar_setting(void); void cons_avatar_setting(void);
void cons_slashguard_setting(void);
void cons_show_contact_online(PContact contact, Resource *resource, GDateTime *last_activity); void cons_show_contact_online(PContact contact, Resource *resource, GDateTime *last_activity);
void cons_show_contact_offline(PContact contact, char *resource, char *status); void cons_show_contact_offline(PContact contact, char *resource, char *status);
void cons_theme_properties(void); void cons_theme_properties(void);

View File

@ -453,6 +453,7 @@ void cons_tray_setting(void) {}
void cons_os_setting(void) {} void cons_os_setting(void) {}
void cons_correction_setting(void) {} void cons_correction_setting(void) {}
void cons_avatar_setting(void) {} void cons_avatar_setting(void) {}
void cons_slashguard_setting(void) {}
void cons_show_contact_online(PContact contact, Resource *resource, GDateTime *last_activity) void cons_show_contact_online(PContact contact, Resource *resource, GDateTime *last_activity)
{ {