summaryrefslogtreecommitdiff
path: root/logging.c
diff options
context:
space:
mode:
Diffstat (limited to 'logging.c')
-rw-r--r--logging.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/logging.c b/logging.c
index a3fdda4..a4698c6 100644
--- a/logging.c
+++ b/logging.c
@@ -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)) {