~emersion/soju

896caebfcf0d31341c5199977b3c9b0891bba78f — delthas 22 days ago f4562a7
service: Introduce network quote

This command enables sending a raw line to a specific network.
2 files changed, 33 insertions(+), 0 deletions(-)

M doc/soju.1.scd
M service.go
M doc/soju.1.scd => doc/soju.1.scd +3 -0
@@ 196,6 196,9 @@ abbreviated form, for instance *network* can be abbreviated as *net* or just
*network delete* <name>
	Disconnect and delete a network.

*network quote* <name> <command>
	Send a raw IRC line as-is to a network.

*network status*
	Show a list of saved networks and their current status.


M service.go => service.go +30 -0
@@ 222,6 222,11 @@ func init() {
					desc:   "delete a network",
					handle: handleServiceNetworkDelete,
				},
				"quote": {
					usage:  "<name> <command>",
					desc:   "send a raw line to a network",
					handle: handleServiceNetworkQuote,
				},
			},
		},
		"certfp": {


@@ 577,6 582,31 @@ func handleServiceNetworkDelete(dc *downstreamConn, params []string) error {
	return nil
}

func handleServiceNetworkQuote(dc *downstreamConn, params []string) error {
	if len(params) != 2 {
		return fmt.Errorf("expected exactly two arguments")
	}

	net := dc.user.getNetwork(params[0])
	if net == nil {
		return fmt.Errorf("unknown network %q", params[0])
	}

	uc := net.conn
	if uc == nil {
		return fmt.Errorf("network %q is not currently connected", params[0])
	}

	m, err := irc.ParseMessage(params[1])
	if err != nil {
		return fmt.Errorf("failed to parse command %q: %v", params[1], err)
	}
	uc.SendMessage(m)

	sendServicePRIVMSG(dc, fmt.Sprintf("sent command to %q", net.GetName()))
	return nil
}

func handleServiceCertfpGenerate(dc *downstreamConn, params []string) error {
	fs := newFlagSet()
	keyType := fs.String("key-type", "rsa", "key type to generate (rsa, ecdsa, ed25519)")