]> jfr.im git - irc/evilnet/x3.git/blobdiff - src/modcmd.c
changed addban to addlamer, added rebindall command
[irc/evilnet/x3.git] / src / modcmd.c
index 21d98cfee571ab7c89aed2c1461e79e8d42a2689..ba282df6886559f7925572f11b80e3073b08a048 100644 (file)
@@ -55,6 +55,7 @@ static const struct message_entry msgtab[] = {
     { "MCMSG_NO_CHANNEL_BEFORE", "You may not give a channel name before this command." },
     { "MCMSG_NO_PLUS_CHANNEL", "You may not use a +channel with this command." },
     { "MCMSG_COMMAND_ALIASES", "%s is an alias for: %s" },
+/*    { "MCMSG_HELP_COMMAND_ALIAS_FOR", "$bALIAS FOR:$b %s" },*/
     { "MCMSG_HELP_COMMAND_ALIAS", "$uAlias for:$u %s" },
     { "MCMSG_COMMAND_BINDING", "%s is a binding of: %s" },
     { "MCMSG_ALIAS_ERROR", "Error in alias expansion for %s; check the error log for details." },
@@ -721,6 +722,7 @@ svccmd_invoke_argv(struct userNode *user, struct service *service, struct chanNo
     }
     if (argc < cmd->command->min_argc) {
         send_message(user, service->bot, "MSG_MISSING_PARAMS", cmd->name);
+        svccmd_send_help_brief(user, service->bot, cmd);
         return 0;
     }
     if (!cmd->command->func) {
@@ -772,7 +774,11 @@ svccmd_send_help(struct userNode *user, struct userNode *bot, struct svccmd *cmd
          * return send_help(user, bot, cmd->command->parent->helpfile, cmd->command->name);
          * TODO: We actually DO want to show the parent IF there is no other help.
          */
-    r = send_help(user, bot, cmd->command->parent->helpfile, cmd->name);
+    r =        send_help(user, bot, cmd->command->parent->helpfile, cmd->name);
+    if(cmd->command->name && strcasecmp(cmd->command->name, cmd->name))
+    {
+        send_message(user, bot, "MCMSG_HELP_COMMAND_ALIAS", cmd->command->name);
+    }
 
     /* If it's an alias, show what it's an alias for. */
     if (cmd->alias.used) {
@@ -783,6 +789,41 @@ svccmd_send_help(struct userNode *user, struct userNode *bot, struct svccmd *cmd
     return r;
 }
 
+int
+svccmd_send_help_brief(struct userNode *user, struct userNode *bot, struct svccmd *cmd) {
+    char cmdname[MAXLEN];
+    unsigned int nn;
+    int r;
+    /* Show command name (in bold). */
+    for (nn=0; cmd->name[nn]; nn++)
+        cmdname[nn] = toupper(cmd->name[nn]);
+    cmdname[nn] = 0;
+
+    /* Show the help entry for the underlying command. */
+        /* Lets not show help for a parent command, thats not what
+         * they asked for!
+         * return send_help(user, bot, cmd->command->parent->helpfile, cmd->command->name);
+         * TODO: We actually DO want to show the parent IF there is no other help.
+         */
+    /* If it's an alias, show what it's an alias for. */
+    if (cmd->alias.used) {
+        char alias_text[MAXLEN];
+        unsplit_string((char**)cmd->alias.list, cmd->alias.used, alias_text);
+        send_message(user, bot, "MCMSG_COMMAND_ALIASES", cmd->name, cmd->command->name);
+    }
+    r = send_help_brief(user, bot, cmd->command->parent->helpfile, cmd->name);
+    if(!r) {
+        if(cmd->command->name)
+        {
+           send_message(user, bot, "MCMSG_COMMAND_ALIASES", cmd->name, cmd->command->name);
+           r = send_help_brief(user, bot, cmd->command->parent->helpfile, cmd->command->name);
+        }
+    }
+
+    return r;
+}
+
+
 int
 svccmd_send_help_2(struct userNode *user, struct service *service, const char *topic) {
     struct module *module;
@@ -1876,6 +1917,14 @@ static MODCMD_FUNC(cmd_version) {
     return 1;
 }
 
+static void create_default_binds(int rebind);
+
+static MODCMD_FUNC(cmd_rebindall) {
+    send_message_type(4, user, cmd->parent->bot, "$bRe-binding all default commands to respective services..$b");
+    create_default_binds(1);
+    return 1;
+}
+
 
 void
 modcmd_nick_change(struct userNode *user, const char *old_nick) {
@@ -2118,6 +2167,7 @@ modcmd_init(void) {
     modcmd_register(modcmd_module, "service privileged", cmd_service_privileged, 2, 0, "flags", "+oper", NULL);
     modcmd_register(modcmd_module, "service remove", cmd_service_remove, 2, 0, "flags", "+oper", NULL);
     modcmd_register(modcmd_module, "dumpmessages", cmd_dump_messages, 1, 0, "oper_level", "1000", NULL);
+    modcmd_register(modcmd_module, "rebindall", cmd_rebindall, 0, MODCMD_KEEP_BOUND, "oper_level", "800", NULL);
     version_command = modcmd_register(modcmd_module, "version", cmd_version, 1, 0, NULL);
     message_register_table(msgtab);
 }
@@ -2283,7 +2333,7 @@ modcmd_saxdb_read(struct dict *db) {
 }
 
 static void
-create_default_binds(void) {
+create_default_binds(int rebind) {
     /* Which services should import which modules by default? */
     struct {
         const char *svcname;
@@ -2310,7 +2360,7 @@ create_default_binds(void) {
             continue;
         if (!(service = service_find(nick)))
             continue;
-        if (dict_size(service->commands) > 0)
+        if (dict_size(service->commands) > 0 && !rebind)
             continue;
 
         /* Bind the default modules for this service to it */
@@ -2328,6 +2378,7 @@ create_default_binds(void) {
         if (!irccasecmp(def_binds[ii].svcname, "ChanServ")) {
             service_make_alias(service, "addowner", "*chanserv.adduser", "$1", "owner", NULL);
             service_make_alias(service, "addcoowner", "*chanserv.adduser", "$1", "coowner", NULL);
+            service_make_alias(service, "addco", "*chanserv.adduser", "$1", "coowner", NULL);
             service_make_alias(service, "addmanager", "*chanserv.adduser", "$1", "manager", NULL);
             service_make_alias(service, "addop", "*chanserv.adduser", "$1", "op", NULL);
             service_make_alias(service, "addhop", "*chanserv.adduser", "$1", "halfop", NULL);
@@ -2337,6 +2388,7 @@ create_default_binds(void) {
             service_make_alias(service, "delmanager", "*chanserv.deluser", "manager", "$1", NULL);
             service_make_alias(service, "delop", "*chanserv.deluser", "op", "$1", NULL);
             service_make_alias(service, "delpeon", "*chanserv.deluser", "peon", "$1", NULL);
+            service_make_alias(service, "llist", "*chanserv.lamers", "1", "$1", NULL);
             service_make_alias(service, "command", "*modcmd.command", NULL);
             service_make_alias(service, "god", "*modcmd.god", NULL);
         } else if (!irccasecmp(def_binds[ii].svcname, "OpServ")) {
@@ -2386,7 +2438,7 @@ modcmd_finalize(void) {
 
     /* Check databases. */
     saxdb_register("modcmd", modcmd_saxdb_read, modcmd_saxdb_write);
-    create_default_binds();
+    create_default_binds(0);
     if (!saxdb_present)
         import_aliases_db();