]> jfr.im git - irc/quakenet/newserv.git/blobdiff - lua/luabot.c
LUA: port luadb to dbapi2 to drop postgres dependency
[irc/quakenet/newserv.git] / lua / luabot.c
index a7a3692202d0348d4fe1ce31c0fa85fc24345d8b..a1132a57272cc8a199bf4a8c7b3b2434335398af 100644 (file)
@@ -27,6 +27,8 @@ void lua_onauth(int hooknum, void *arg);
 void lua_ondisconnect(int hooknum, void *arg);
 void lua_onmode(int hooknum, void *arg);
 void lua_onop(int hooknum, void *arg);
+void lua_onvoice(int hooknum, void *arg);
+void lua_onprequit(int hooknum, void *arg);
 void lua_onquit(int hooknum, void *arg);
 void lua_onrename(int hooknum, void *arg);
 void lua_onconnect(int hooknum, void *arg);
@@ -45,6 +47,9 @@ void lua_registerevents(void) {
   registerhook(HOOK_CHANNEL_KICK, &lua_onkick);
   registerhook(HOOK_CHANNEL_OPPED, &lua_onop);
   registerhook(HOOK_CHANNEL_DEOPPED, &lua_onop);
+  registerhook(HOOK_CHANNEL_VOICED, &lua_onvoice);
+  registerhook(HOOK_CHANNEL_DEVOICED, &lua_onvoice);
+  registerhook(HOOK_NICK_PRE_LOSTNICK, &lua_onprequit);
   registerhook(HOOK_NICK_LOSTNICK, &lua_onquit);
   registerhook(HOOK_NICK_RENAME, &lua_onrename);
   registerhook(HOOK_IRC_CONNECTED, &lua_onconnect);
@@ -62,8 +67,11 @@ void lua_deregisterevents(void) {
   deregisterhook(HOOK_IRC_CONNECTED, &lua_onconnect);
   deregisterhook(HOOK_NICK_RENAME, &lua_onrename);
   deregisterhook(HOOK_NICK_LOSTNICK, &lua_onquit);
+  deregisterhook(HOOK_NICK_PRE_LOSTNICK, &lua_onprequit);
   deregisterhook(HOOK_CHANNEL_DEOPPED, &lua_onop);
   deregisterhook(HOOK_CHANNEL_OPPED, &lua_onop);
+  deregisterhook(HOOK_CHANNEL_DEVOICED, &lua_onvoice);
+  deregisterhook(HOOK_CHANNEL_VOICED, &lua_onvoice);
   deregisterhook(HOOK_CHANNEL_KICK, &lua_onkick);
   deregisterhook(HOOK_CHANNEL_TOPIC, &lua_ontopic);
   deregisterhook(HOOK_NICK_ACCOUNT, &lua_onauth);
@@ -248,7 +256,8 @@ void lua_bothandler(nick *target, int type, void **args) {
           p[le - 1] = '\000';
 
         lua_avpcall("irc_onctcp", "ls", np->numeric, p + 1);
-
+      } else {
+        lua_avpcall("irc_onnotice", "ls", np->numeric, p);
       }
 
       break;
@@ -294,18 +303,11 @@ void lua_onkick(int hooknum, void *arg) {
   nick *kicked = arglist[1];
   nick *kicker = arglist[2];
   char *message = (char *)arglist[3];
-  int mode = 1;
-
-  if(!kicker || IsOper(kicker) || IsService(kicker) || IsXOper(kicker)) /* bloody Cruicky */
-    mode = 0;
 
-  if(mode) {
+  if(kicker)
     lua_avpcall("irc_onkick", "Slls", ci->name, kicked->numeric, kicker->numeric, message);
-  } else if(kicker) {
-    lua_avpcall("irc_onkickall", "Slls", ci->name, kicked->numeric, kicker->numeric, message);
-  } else {
-    lua_avpcall("irc_onkickall", "Sl0s", ci->name, kicked->numeric, message);
-  }
+  else
+    lua_avpcall("irc_onkick", "Sl0s", ci->name, kicked->numeric, message);
 }
 
 void lua_ontopic(int hooknum, void *arg) {
@@ -313,12 +315,13 @@ void lua_ontopic(int hooknum, void *arg) {
   channel *cp=(channel*)arglist[0];
   nick *np = (nick *)arglist[1];
 
-  if(!np || IsOper(np) || IsService(np) || IsXOper(np))
-    return;
-  if(!cp || !cp->topic) 
+  if(!cp || !cp->topic)
     return;
 
-  lua_avpcall("irc_ontopic", "SlS", cp->index->name, np->numeric, cp->topic);
+  if(np)
+    lua_avpcall("irc_ontopic", "SlS", cp->index->name, np->numeric, cp->topic);
+  else
+    lua_avpcall("irc_ontopic", "S0S", cp->index->name, cp->topic);
 }
 
 void lua_onop(int hooknum, void *arg) {
@@ -337,6 +340,22 @@ void lua_onop(int hooknum, void *arg) {
   }
 }
 
+void lua_onvoice(int hooknum, void *arg) {
+  void **arglist = (void **)arg;
+  chanindex *ci = ((channel *)arglist[0])->index;
+  nick *np = arglist[1];
+  nick *target = arglist[2];
+
+  if(!target)
+    return;
+
+  if(np) {
+    lua_avpcall(hooknum == HOOK_CHANNEL_VOICED?"irc_onvoice":"irc_ondevoice", "Sll", ci->name, np->numeric, target->numeric);
+  } else {
+    lua_avpcall(hooknum == HOOK_CHANNEL_VOICED?"irc_onvoice":"irc_ondevoice", "S0l", ci->name, target->numeric);
+  }
+}
+
 void lua_onjoin(int hooknum, void *arg) {
   void **arglist = (void **)arg;
   chanindex *ci = ((channel *)arglist[0])->index;
@@ -380,6 +399,15 @@ void lua_onquit(int hooknum, void *arg) {
   lua_avpcall("irc_onquit", "l", np->numeric);
 }
 
+void lua_onprequit(int hooknum, void *arg) {
+  nick *np = (nick *)arg;
+
+  if(!np)
+    return;
+
+  lua_avpcall("irc_onprequit", "l", np->numeric);
+}
+
 void lua_onauth(int hooknum, void *arg) {
   nick *np = (nick *)arg;
 
@@ -477,5 +505,3 @@ void lua_onmode(int hooknum, void *arg) {
     lua_avpcall("irc_onmode", "S0ss", ci->name, printallmodes(cp), printlimitedmodes(cp, beforeflags));
   }
 }
-
-