mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-22 20:09:41 +01:00
motd command
This commit is contained in:
parent
a203a3ca16
commit
09887b2db3
@ -23,6 +23,7 @@ var (
|
|||||||
"ISON": NewIsOnCommand,
|
"ISON": NewIsOnCommand,
|
||||||
"JOIN": NewJoinCommand,
|
"JOIN": NewJoinCommand,
|
||||||
"MODE": NewModeCommand,
|
"MODE": NewModeCommand,
|
||||||
|
"MOTD": NewMOTDCommand,
|
||||||
"NICK": NewNickCommand,
|
"NICK": NewNickCommand,
|
||||||
"OPER": NewOperCommand,
|
"OPER": NewOperCommand,
|
||||||
"PART": NewPartCommand,
|
"PART": NewPartCommand,
|
||||||
@ -651,3 +652,16 @@ func NewIsOnCommand(args []string) (editableCommand, error) {
|
|||||||
nicks: args,
|
nicks: args,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MOTDCommand struct {
|
||||||
|
BaseCommand
|
||||||
|
target string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMOTDCommand(args []string) (editableCommand, error) {
|
||||||
|
cmd := &MOTDCommand{}
|
||||||
|
if len(args) > 0 {
|
||||||
|
cmd.target = args[0]
|
||||||
|
}
|
||||||
|
return cmd, nil
|
||||||
|
}
|
||||||
|
@ -6,11 +6,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string
|
|
||||||
Listeners []ListenerConfig
|
|
||||||
Password string
|
|
||||||
Operators []OperatorConfig
|
|
||||||
Debug map[string]bool
|
Debug map[string]bool
|
||||||
|
Listeners []ListenerConfig
|
||||||
|
MOTD string
|
||||||
|
Name string
|
||||||
|
Operators []OperatorConfig
|
||||||
|
Password string
|
||||||
}
|
}
|
||||||
|
|
||||||
type OperatorConfig struct {
|
type OperatorConfig struct {
|
||||||
|
15
irc/reply.go
15
irc/reply.go
@ -276,6 +276,21 @@ func RplIsOn(server *Server, nicks []string) Reply {
|
|||||||
":%s", strings.Join(nicks, " "))
|
":%s", strings.Join(nicks, " "))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RplMOTDStart(server *Server) Reply {
|
||||||
|
return NewNumericReply(server, RPL_MOTDSTART,
|
||||||
|
":- %s Message of the day - ", server.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func RplMOTD(server *Server, line string) Reply {
|
||||||
|
return NewNumericReply(server, RPL_MOTD,
|
||||||
|
":- %s", line)
|
||||||
|
}
|
||||||
|
|
||||||
|
func RplMOTDEnd(server *Server) Reply {
|
||||||
|
return NewNumericReply(server, RPL_ENDOFMOTD,
|
||||||
|
":End of MOTD command")
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// errors (also numeric)
|
// errors (also numeric)
|
||||||
//
|
//
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
package irc
|
package irc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -14,6 +16,7 @@ type Server struct {
|
|||||||
channels ChannelNameMap
|
channels ChannelNameMap
|
||||||
commands chan<- Command
|
commands chan<- Command
|
||||||
ctime time.Time
|
ctime time.Time
|
||||||
|
motdFile string
|
||||||
name string
|
name string
|
||||||
operators map[string]string
|
operators map[string]string
|
||||||
password string
|
password string
|
||||||
@ -27,6 +30,7 @@ func NewServer(config *Config) *Server {
|
|||||||
clients: make(ClientNameMap),
|
clients: make(ClientNameMap),
|
||||||
commands: commands,
|
commands: commands,
|
||||||
ctime: time.Now(),
|
ctime: time.Now(),
|
||||||
|
motdFile: config.MOTD,
|
||||||
name: config.Name,
|
name: config.Name,
|
||||||
operators: make(map[string]string),
|
operators: make(map[string]string),
|
||||||
password: config.Password,
|
password: config.Password,
|
||||||
@ -152,7 +156,39 @@ func (s *Server) tryRegister(c *Client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) MOTD(client *Client) {
|
func (server *Server) MOTD(client *Client) {
|
||||||
client.Reply(ErrNoMOTD(server))
|
if server.motdFile == "" {
|
||||||
|
client.Reply(ErrNoMOTD(server))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
file, err := os.Open(server.motdFile)
|
||||||
|
if err != nil {
|
||||||
|
client.Reply(ErrNoMOTD(server))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
client.Reply(RplMOTDStart(server))
|
||||||
|
reader := bufio.NewReader(file)
|
||||||
|
for {
|
||||||
|
line, err := reader.ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(line) > 80 {
|
||||||
|
for len(line) > 80 {
|
||||||
|
client.Reply(RplMOTD(server, line[0:80]))
|
||||||
|
line = line[80:]
|
||||||
|
}
|
||||||
|
if len(line) > 0 {
|
||||||
|
client.Reply(RplMOTD(server, line))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
client.Reply(RplMOTD(server, line))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
client.Reply(RplMOTDEnd(server))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Id() string {
|
func (s *Server) Id() string {
|
||||||
@ -435,3 +471,7 @@ func (msg *IsOnCommand) HandleServer(server *Server) {
|
|||||||
|
|
||||||
client.Reply(RplIsOn(server, ison))
|
client.Reply(RplIsOn(server, ison))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (msg *MOTDCommand) HandleServer(server *Server) {
|
||||||
|
server.MOTD(msg.Client())
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user