Changeset 577 in code for trunk/service.go


Ignore:
Timestamp:
Jul 7, 2021, 8:34:46 AM (4 years ago)
Author:
delthas
Message:

service: Introduce network quote

This command enables sending a raw line to a specific network.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/service.go

    r575 r577  
    223223                                        handle: handleServiceNetworkDelete,
    224224                                },
     225                                "quote": {
     226                                        usage:  "<name> <command>",
     227                                        desc:   "send a raw line to a network",
     228                                        handle: handleServiceNetworkQuote,
     229                                },
    225230                        },
    226231                },
     
    578583}
    579584
     585func handleServiceNetworkQuote(dc *downstreamConn, params []string) error {
     586        if len(params) != 2 {
     587                return fmt.Errorf("expected exactly two arguments")
     588        }
     589
     590        net := dc.user.getNetwork(params[0])
     591        if net == nil {
     592                return fmt.Errorf("unknown network %q", params[0])
     593        }
     594
     595        uc := net.conn
     596        if uc == nil {
     597                return fmt.Errorf("network %q is not currently connected", params[0])
     598        }
     599
     600        m, err := irc.ParseMessage(params[1])
     601        if err != nil {
     602                return fmt.Errorf("failed to parse command %q: %v", params[1], err)
     603        }
     604        uc.SendMessage(m)
     605
     606        sendServicePRIVMSG(dc, fmt.Sprintf("sent command to %q", net.GetName()))
     607        return nil
     608}
     609
    580610func handleServiceCertfpGenerate(dc *downstreamConn, params []string) error {
    581611        fs := newFlagSet()
Note: See TracChangeset for help on using the changeset viewer.