'op:' action
authorChristian Thaeter <ct@pipapo.org>
Tue, 6 Nov 2007 04:19:01 +0000 (05:19 +0100)
committerChristian Thaeter <ct@pipapo.org>
Tue, 6 Nov 2007 04:19:01 +0000 (05:19 +0100)
contrib/irc/xchat/rx.c

index 8482e5f..3317ebb 100644 (file)
@@ -19,6 +19,8 @@
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
+#define _GNU_SOURCE
+
 #include <unistd.h>
 #include <string.h>
 #include <stdlib.h>
@@ -340,10 +342,53 @@ rxhook_cb (char *word[], char *word_eol[], void *userdata)
 
       if (PREFIXCMP(buffer, "ignore:"))
         return XCHAT_EAT_XCHAT;
-      //else if (PREFIXCMP(line, "kick:"))
-      //else if (PREFIXCMP(line, "kickban:"))
-      //else if (PREFIXCMP(line, "ban:"))
-      //else if (PREFIXCMP(line, "op:"))
+
+      else if (PREFIXCMP(buffer, "op:"))
+        {
+          const char* iam = xchat_get_info (ph, "nick");
+
+          char* hisnickend = strchr (word_eol[1]+1, '!');
+          if (hisnickend)
+            {
+              char* hisnick = strndupa (word_eol[1]+1, hisnickend - word_eol[1]-1);
+
+              int op_him = 0;
+
+              xchat_list* users = xchat_list_get (ph, "users");
+              if (users)
+                {
+                  while (xchat_list_next (ph, users))
+                    {
+                      if (!strcmp (iam, xchat_list_str (ph, users, "nick")))
+                        {
+                          if (*xchat_list_str (ph, users, "prefix") != '@')
+                            {
+                              op_him = 0;
+                              break;
+                            }
+                        }
+
+                      if (!strcmp (hisnick, xchat_list_str (ph, users, "nick")))
+                        {
+                          if (*xchat_list_str (ph, users, "prefix") != '@')
+                            op_him = 1;
+                          else
+                            {
+                              op_him = 0;
+                              break;
+                            }
+                        }
+                    }
+                  xchat_list_free (ph, users);
+
+                  if (op_him)
+                    xchat_commandf (ph, "OP %s\n", hisnick);
+                }
+            }
+        }
+      //else if (PREFIXCMP(buffer, "kick:"))
+      //else if (PREFIXCMP(buffer, "kickban:"))
+      //else if (PREFIXCMP(buffer, "ban:"))
     }
 
   return XCHAT_EAT_NONE;