MCPcopy Create free account
hub / github.com/babycommando/nightride-cli / connectServerCmd

Method connectServerCmd

zuse.go:854–1085  ·  view source on GitHub ↗
(id serverID)

Source from the content-addressed store, hash-verified

852
853
854func (m *ircModel) connectServerCmd(id serverID) tea.Cmd {
855 return func() tea.Msg {
856 s := m.servers[id]
857 if s == nil {
858 return ircErrMsg(fmt.Errorf("server not found"))
859 }
860
861 host, portStr, err := net.SplitHostPort(s.address)
862 if err != nil {
863 return ircErrMsg(fmt.Errorf("invalid server address: %w", err))
864 }
865 port, err := strconv.Atoi(portStr)
866 if err != nil {
867 return ircErrMsg(fmt.Errorf("invalid port: %w", err))
868 }
869
870 cfg := girc.Config{
871 Server: host,
872 Port: port,
873 Nick: s.nick,
874 User: s.nick,
875 Name: s.nick,
876 SSL: s.tls,
877 }
878 c := girc.New(cfg)
879
880 // c.Handlers.Add(girc.CONNECTED, func(cl *girc.Client, _ girc.Event) {
881 // m.push(ircChanLineMsg{id: id, channel: "_sys", line: styleDim.Render("-- connected to " + s.address + " --")})
882 // for _, ch := range s.channels {
883 // cl.Cmd.Join(ch)
884 // }
885 // m.push(connectedMsg(id))
886 // })
887
888 c.Handlers.Add(girc.CONNECTED, func(cl *girc.Client, _ girc.Event) {
889 // banner first
890 banner := asciiBanner()
891 m.push(ircChanLineMsg{id: id, channel: "_sys", line: banner})
892 for _, ch := range s.channels {
893 m.push(ircChanLineMsg{id: id, channel: ch, line: banner})
894 }
895
896 m.push(ircChanLineMsg{id: id, channel: "_sys", line: styleDim.Render("-- connected to " + s.address + " --")})
897 for _, ch := range s.channels {
898 cl.Cmd.Join(ch)
899 }
900 m.push(connectedMsg(id))
901 })
902 c.Handlers.Add(girc.DISCONNECTED, func(cl *girc.Client, _ girc.Event) {
903 m.push(ircChanLineMsg{id: id, channel: "_sys", line: styleDim.Render("-- disconnected --")})
904 m.push(disconnectedMsg{id: id, err: nil})
905 })
906
907 c.Handlers.Add(girc.PRIVMSG, func(_ *girc.Client, e girc.Event) {
908 if len(e.Params) < 2 {
909 return
910 }
911 target := e.Params[0]

Callers 3

updateServersPaneMethod · 0.95
updateFormMethod · 0.95
updateChatMethod · 0.95

Calls 4

ircErrMsgTypeAlias · 0.85
asciiBannerFunction · 0.85
connectedMsgTypeAlias · 0.85
dispatchTargetFunction · 0.85

Tested by

no test coverage detected