3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 18:52:41 +01:00

get rid of editableCommand

This commit is contained in:
Jeremy Latt 2014-03-08 14:24:17 -08:00
parent d1a299792e
commit 77d053ccac
4 changed files with 39 additions and 43 deletions

View File

@ -18,7 +18,7 @@ type Client struct {
capabilities CapabilitySet
capState CapState
channels ChannelSet
commands chan editableCommand
commands chan Command
ctime time.Time
flags map[UserMode]bool
hasQuit bool
@ -43,7 +43,7 @@ func NewClient(server *Server, conn net.Conn) *Client {
capState: CapNone,
capabilities: make(CapabilitySet),
channels: make(ChannelSet),
commands: make(chan editableCommand),
commands: make(chan Command),
ctime: now,
flags: make(map[UserMode]bool),
phase: Registration,

View File

@ -9,18 +9,12 @@ import (
"strings"
)
type editableCommand interface {
Command
SetCode(StringCode)
SetClient(*Client)
}
type checkPasswordCommand interface {
LoadPassword(*Server)
CheckPassword()
}
type parseCommandFunc func([]string) (editableCommand, error)
type parseCommandFunc func([]string) (Command, error)
var (
NotEnoughArgsError = errors.New("not enough arguments")
@ -79,7 +73,7 @@ func (command *BaseCommand) SetCode(code StringCode) {
command.code = code
}
func ParseCommand(line string) (cmd editableCommand, err error) {
func ParseCommand(line string) (cmd Command, err error) {
code, args := ParseLine(line)
constructor := parseCommandFuncs[code]
if constructor == nil {
@ -155,7 +149,7 @@ func (cmd *PingCommand) String() string {
return fmt.Sprintf("PING(server=%s, server2=%s)", cmd.server, cmd.server2)
}
func NewPingCommand(args []string) (editableCommand, error) {
func NewPingCommand(args []string) (Command, error) {
if len(args) < 1 {
return nil, NotEnoughArgsError
}
@ -180,7 +174,7 @@ func (cmd *PongCommand) String() string {
return fmt.Sprintf("PONG(server1=%s, server2=%s)", cmd.server1, cmd.server2)
}
func NewPongCommand(args []string) (editableCommand, error) {
func NewPongCommand(args []string) (Command, error) {
if len(args) < 1 {
return nil, NotEnoughArgsError
}
@ -217,7 +211,7 @@ func (cmd *PassCommand) CheckPassword() {
cmd.err = ComparePassword(cmd.hash, cmd.password)
}
func NewPassCommand(args []string) (editableCommand, error) {
func NewPassCommand(args []string) (Command, error) {
if len(args) < 1 {
return nil, NotEnoughArgsError
}
@ -237,7 +231,7 @@ func (m *NickCommand) String() string {
return fmt.Sprintf("NICK(nickname=%s)", m.nickname)
}
func NewNickCommand(args []string) (editableCommand, error) {
func NewNickCommand(args []string) (Command, error) {
if len(args) != 1 {
return nil, NotEnoughArgsError
}
@ -287,7 +281,7 @@ func (cmd *RFC2812UserCommand) Flags() []UserMode {
return flags
}
func NewUserCommand(args []string) (editableCommand, error) {
func NewUserCommand(args []string) (Command, error) {
if len(args) != 4 {
return nil, NotEnoughArgsError
}
@ -322,7 +316,7 @@ func (cmd *QuitCommand) String() string {
return fmt.Sprintf("QUIT(message=%s)", cmd.message)
}
func NewQuitCommand(args []string) (editableCommand, error) {
func NewQuitCommand(args []string) (Command, error) {
msg := &QuitCommand{}
if len(args) > 0 {
msg.message = args[0]
@ -342,7 +336,7 @@ func (cmd *JoinCommand) String() string {
return fmt.Sprintf("JOIN(channels=%s, zero=%t)", cmd.channels, cmd.zero)
}
func NewJoinCommand(args []string) (editableCommand, error) {
func NewJoinCommand(args []string) (Command, error) {
msg := &JoinCommand{
channels: make(map[string]string),
}
@ -389,7 +383,7 @@ func (cmd *PartCommand) String() string {
return fmt.Sprintf("PART(channels=%s, message=%s)", cmd.channels, cmd.message)
}
func NewPartCommand(args []string) (editableCommand, error) {
func NewPartCommand(args []string) (Command, error) {
if len(args) < 1 {
return nil, NotEnoughArgsError
}
@ -414,7 +408,7 @@ func (cmd *PrivMsgCommand) String() string {
return fmt.Sprintf("PRIVMSG(target=%s, message=%s)", cmd.target, cmd.message)
}
func NewPrivMsgCommand(args []string) (editableCommand, error) {
func NewPrivMsgCommand(args []string) (Command, error) {
if len(args) < 2 {
return nil, NotEnoughArgsError
}
@ -437,7 +431,7 @@ func (cmd *TopicCommand) String() string {
return fmt.Sprintf("TOPIC(channel=%s, topic=%s)", cmd.channel, cmd.topic)
}
func NewTopicCommand(args []string) (editableCommand, error) {
func NewTopicCommand(args []string) (Command, error) {
if len(args) < 1 {
return nil, NotEnoughArgsError
}
@ -487,7 +481,7 @@ type ModeCommand struct {
}
// MODE <nickname> *( ( "+" / "-" ) *( "i" / "w" / "o" / "O" / "r" ) )
func NewUserModeCommand(args []string) (editableCommand, error) {
func NewUserModeCommand(args []string) (Command, error) {
cmd := &ModeCommand{
nickname: args[0],
changes: make(ModeChanges, 0),
@ -564,7 +558,7 @@ type ChannelModeCommand struct {
}
// MODE <channel> *( ( "-" / "+" ) *<modes> *<modeparams> )
func NewChannelModeCommand(args []string) (editableCommand, error) {
func NewChannelModeCommand(args []string) (Command, error) {
cmd := &ChannelModeCommand{
channel: args[0],
changes: make(ChannelModeChanges, 0),
@ -611,7 +605,7 @@ func (msg *ChannelModeCommand) String() string {
return fmt.Sprintf("MODE(channel=%s, changes=%s)", msg.channel, msg.changes)
}
func NewModeCommand(args []string) (editableCommand, error) {
func NewModeCommand(args []string) (Command, error) {
if len(args) == 0 {
return nil, NotEnoughArgsError
}
@ -630,7 +624,7 @@ type WhoisCommand struct {
}
// WHOIS [ <target> ] <mask> *( "," <mask> )
func NewWhoisCommand(args []string) (editableCommand, error) {
func NewWhoisCommand(args []string) (Command, error) {
if len(args) < 1 {
return nil, NotEnoughArgsError
}
@ -662,7 +656,7 @@ type WhoCommand struct {
}
// WHO [ <mask> [ "o" ] ]
func NewWhoCommand(args []string) (editableCommand, error) {
func NewWhoCommand(args []string) (Command, error) {
cmd := &WhoCommand{}
if len(args) > 0 {
@ -694,7 +688,7 @@ func (msg *OperCommand) LoadPassword(server *Server) {
}
// OPER <name> <password>
func NewOperCommand(args []string) (editableCommand, error) {
func NewOperCommand(args []string) (Command, error) {
if len(args) < 2 {
return nil, NotEnoughArgsError
}
@ -717,7 +711,7 @@ func (msg *CapCommand) String() string {
msg.subCommand, msg.capabilities)
}
func NewCapCommand(args []string) (editableCommand, error) {
func NewCapCommand(args []string) (Command, error) {
if len(args) < 1 {
return nil, NotEnoughArgsError
}
@ -751,7 +745,7 @@ func (msg *ProxyCommand) String() string {
return fmt.Sprintf("PROXY(sourceIP=%s, sourcePort=%s)", msg.sourceIP, msg.sourcePort)
}
func NewProxyCommand(args []string) (editableCommand, error) {
func NewProxyCommand(args []string) (Command, error) {
if len(args) < 5 {
return nil, NotEnoughArgsError
}
@ -775,7 +769,7 @@ func (msg *AwayCommand) String() string {
return fmt.Sprintf("AWAY(%s)", msg.text)
}
func NewAwayCommand(args []string) (editableCommand, error) {
func NewAwayCommand(args []string) (Command, error) {
cmd := &AwayCommand{}
if len(args) > 0 {
@ -795,7 +789,7 @@ func (msg *IsOnCommand) String() string {
return fmt.Sprintf("ISON(nicks=%s)", msg.nicks)
}
func NewIsOnCommand(args []string) (editableCommand, error) {
func NewIsOnCommand(args []string) (Command, error) {
if len(args) == 0 {
return nil, NotEnoughArgsError
}
@ -810,7 +804,7 @@ type MOTDCommand struct {
target string
}
func NewMOTDCommand(args []string) (editableCommand, error) {
func NewMOTDCommand(args []string) (Command, error) {
cmd := &MOTDCommand{}
if len(args) > 0 {
cmd.target = args[0]
@ -828,7 +822,7 @@ func (cmd *NoticeCommand) String() string {
return fmt.Sprintf("NOTICE(target=%s, message=%s)", cmd.target, cmd.message)
}
func NewNoticeCommand(args []string) (editableCommand, error) {
func NewNoticeCommand(args []string) (Command, error) {
if len(args) < 2 {
return nil, NotEnoughArgsError
}
@ -851,7 +845,7 @@ func (msg *KickCommand) Comment() string {
return msg.comment
}
func NewKickCommand(args []string) (editableCommand, error) {
func NewKickCommand(args []string) (Command, error) {
if len(args) < 2 {
return nil, NotEnoughArgsError
}
@ -882,7 +876,7 @@ type ListCommand struct {
target string
}
func NewListCommand(args []string) (editableCommand, error) {
func NewListCommand(args []string) (Command, error) {
cmd := &ListCommand{}
if len(args) > 0 {
cmd.channels = strings.Split(args[0], ",")
@ -899,7 +893,7 @@ type NamesCommand struct {
target string
}
func NewNamesCommand(args []string) (editableCommand, error) {
func NewNamesCommand(args []string) (Command, error) {
cmd := &NamesCommand{}
if len(args) > 0 {
cmd.channels = strings.Split(args[0], ",")
@ -915,7 +909,7 @@ type DebugCommand struct {
subCommand string
}
func NewDebugCommand(args []string) (editableCommand, error) {
func NewDebugCommand(args []string) (Command, error) {
if len(args) == 0 {
return nil, NotEnoughArgsError
}
@ -930,7 +924,7 @@ type VersionCommand struct {
target string
}
func NewVersionCommand(args []string) (editableCommand, error) {
func NewVersionCommand(args []string) (Command, error) {
cmd := &VersionCommand{}
if len(args) > 0 {
cmd.target = args[0]
@ -944,7 +938,7 @@ type InviteCommand struct {
channel string
}
func NewInviteCommand(args []string) (editableCommand, error) {
func NewInviteCommand(args []string) (Command, error) {
if len(args) < 2 {
return nil, NotEnoughArgsError
}
@ -960,7 +954,7 @@ type TimeCommand struct {
target string
}
func NewTimeCommand(args []string) (editableCommand, error) {
func NewTimeCommand(args []string) (Command, error) {
cmd := &TimeCommand{}
if len(args) > 0 {
cmd.target = args[0]
@ -974,7 +968,7 @@ type KillCommand struct {
comment string
}
func NewKillCommand(args []string) (editableCommand, error) {
func NewKillCommand(args []string) (Command, error) {
if len(args) < 2 {
return nil, NotEnoughArgsError
}
@ -991,7 +985,7 @@ type WhoWasCommand struct {
target string
}
func NewWhoWasCommand(args []string) (editableCommand, error) {
func NewWhoWasCommand(args []string) (Command, error) {
if len(args) < 1 {
return nil, NotEnoughArgsError
}

View File

@ -20,7 +20,7 @@ type Socket struct {
writer *bufio.Writer
}
func NewSocket(conn net.Conn, commands chan<- editableCommand) *Socket {
func NewSocket(conn net.Conn, commands chan<- Command) *Socket {
socket := &Socket{
conn: conn,
reader: bufio.NewReader(conn),
@ -43,7 +43,7 @@ func (socket *Socket) Close() {
}
}
func (socket *Socket) readLines(commands chan<- editableCommand) {
func (socket *Socket) readLines(commands chan<- Command) {
commands <- &ProxyCommand{
hostname: AddrLookupHostname(socket.conn.RemoteAddr()),
}

View File

@ -193,6 +193,8 @@ type Replier interface {
type Command interface {
Code() StringCode
Client() *Client
SetCode(StringCode)
SetClient(*Client)
}
type ServerCommand interface {