megawac / qwebirc-enhancements

Rich and intuitive browser IRC client.
http://justplay.tf/irc
Other
22 stars 10 forks source link

Adding new commands #51

Open RobertEcker opened 9 years ago

RobertEcker commented 9 years ago

Which are the steps if you want to add new commands which are implemented on the irc server?

megawac commented 9 years ago

If they're commands that run off the IRC server you should be able to run them directly. For instance geeks auth service is ns and we can do /ns id megawac <pass>.

If you want to alias you can set them via qwebirc.config.COMMAND_ALIAS, so to alias ns we could do

qwebirc.config.COMMAND_ALIAS.NickServ = "ns";

If we want to create a custom handler, its a bit more tricky; we have to implement on qwebirc.irc.Commands

qwebirc.irc.Commands.implement({
   cmd_NS: {
        splitargs: 2,
        minargs: 2,
        fn: function(args) {
              var username = args[0],
                    password = args[1];
              return "ns id " + username + " " + password;
        }
   }
});

Message me on #brouhaha on geeks if you have any trouble.

RobertEcker commented 9 years ago

tnx for your answer

so a dice-command (random generate number between 1 and 6) would be possible :)

in general, i think, each channel knows its channel name which can be used for the command as parameter? where can i find it ;)

megawac commented 9 years ago

One day this stuff will be documented.. If you set target: true the last argument to your command handler will be which ever window (channel/query window/status) the command was called from

qwebirc.irc.Client.implement({
   cmd_CMD: {
        fn: function(args, target) {
              console.log(args, target);
        }
   }
});
megawac commented 9 years ago

Sorry, correction.\ If target is a number that argument will be used as the target. So for example

qwebirc.irc.Commands.implement({
   cmd_KICK: {
        target: 2,
        splitargs: 2,
        minargs: 2,
        fn: function(args) {
              // ....
        }
   }
});

Enables both /kick megawac #brouhaha and the following using current channel /kick megawac

By the way, logic only can have the optional explict target in the command if its provided as the last argument at the moment. Don't set target and find it your self if its the 4th of 6 args or something :)

megawac commented 9 years ago

Note to self change pop to splice to allow targeting specific arg On Aug 18, 2014 11:24 AM, "Robert" notifications@github.com wrote:

tnx for your answer

so a dice-command (random generate number between 1 and 6) would be possible :)

in general, i think, each channel knows its channel name which can be used for the command as parameter? where can i find it ;)

— Reply to this email directly or view it on GitHub https://github.com/megawac/qwebirc-enhancements/issues/51#issuecomment-52507703 .