diff options
author | Luke Bratch <luke@bratch.co.uk> | 2019-05-19 18:37:27 +0100 |
---|---|---|
committer | Luke Bratch <luke@bratch.co.uk> | 2019-05-19 18:37:27 +0100 |
commit | f767fc29fb0c192d20308a09aaa18918ac8a0875 (patch) | |
tree | 0d207d9dfe0c6474bb2f707342a6fe10500144c6 /logging.c | |
parent | a5880d645c2bbf8dfae6daabb1d3c3c66e3c310b (diff) |
Enable logging of TOPIC changes.
Diffstat (limited to 'logging.c')
-rw-r--r-- | logging.c | 31 |
1 files changed, 26 insertions, 5 deletions
@@ -10,11 +10,13 @@ // If LOG_PRIVMSG then it expects a string in the format: // :from!bar@baz PRIVMSG to :hello world // -// If LOG_JOINPART then -// Expects a string in the format: -// :nick!bar@baz JOIN :#blabouncer +// If LOG_JOINPART then it expects a string in the format: +// :nick!bar@baz JOIN :#channel // or -// :nick!bar@baz PART #blabouncer +// :nick!bar@baz PART #channel +// +// If LOG_TOPIC then it expects a string in the format: +// :nick!bar@baz TOPIC #channel :bla bla bla // // With the ":foo!bar@baz "prefix being important for either // type. @@ -42,6 +44,9 @@ int logline(char *str, char *ournick, char *basedir, int type) { // If LOG_JOINPART: // This gets us the prefix (containing the joined/parted nick), the JOIN/PART command (not needed), // and the channel name. + // If LOG_TOPIC: + // This gets us the prefix (containing the topic setting nick), the TOPIC command (not needed), + // the channel whose topic was set, and the rest of the string intact (which is the new topic). for (int i = 0; i < 3; i++) { // Try to split if ((token = strsep(&str, " ")) == NULL) { @@ -120,6 +125,22 @@ int logline(char *str, char *ournick, char *basedir, int type) { break; + case LOG_TOPIC: + // Extract the username from the prefix + extractnickfromprefix(tokens[0]); + + // Remove the leading ":" from the topic + stripprefix(str); + + snprintf(filename, MAXCHAR, "%s/logs/%s.log", basedir, tokens[2]); + + printf("logline(): Logging TOPIC for '%s' in filename '%s'.\n", tokens[2], filename); + + // Build a friendly message (e.g. ":nick!user@host TOPIC #channel :blah blah" -> "nick has changed the topic to: blah blah") + snprintf(line, MAXCHAR, "%s has changed the topic to: %s", tokens[0], str); + + break; + default : printf("Unknown log type '%d', returning 0.\n", type); return 0; @@ -165,7 +186,7 @@ int logline(char *str, char *ournick, char *basedir, int type) { fprintf(stderr, "Error while preparing log string to write!\n"); exit(1); } - } else if (type == LOG_JOINPART) { + } else if (type == LOG_JOINPART || type == LOG_TOPIC) { // Prepend the time string char line2[MAXCHAR]; if (!snprintf(line2, MAXCHAR, "%s %s", timestr, line)) { |