Browse Source

fix up MODE behavior to allow /mode <not-your-nick> and show per-channel modes, fixes #29

tags/v0.1.0
Edmund Huber 10 years ago
parent
commit
e1c235a9ea
2 changed files with 20 additions and 3 deletions
  1. 4
    2
      irc/modes.go
  2. 16
    1
      irc/reply.go

+ 4
- 2
irc/modes.go View File

@@ -145,10 +145,12 @@ func (m *ModeCommand) HandleServer(s *Server) {
145 145
 		}
146 146
 	}
147 147
 
148
-	// Who should get these replies?
149 148
 	if len(changes) > 0 {
150
-		client.Reply(RplMode(client, target, changes))
149
+		client.Reply(RplModeChanges(client, target, changes))
150
+	} else if client == target {
151
+		client.RplUModeIs(client)
151 152
 	}
153
+	client.Reply(RplCurrentMode(client, target))
152 154
 }
153 155
 
154 156
 func (msg *ChannelModeCommand) HandleServer(server *Server) {

+ 16
- 1
irc/reply.go View File

@@ -119,10 +119,25 @@ func RplPart(client *Client, channel *Channel, message Text) string {
119 119
 	return NewStringReply(client, PART, "%s :%s", channel, message)
120 120
 }
121 121
 
122
-func RplMode(client *Client, target *Client, changes ModeChanges) string {
122
+func RplModeChanges(client *Client, target *Client, changes ModeChanges) string {
123 123
 	return NewStringReply(client, MODE, "%s :%s", target.Nick(), changes)
124 124
 }
125 125
 
126
+func RplCurrentMode(client *Client, target *Client) string {
127
+	globalFlags := ""
128
+	for mode, _ := range target.flags {
129
+		globalFlags += mode.String()
130
+	}
131
+
132
+	perChannelFlags := ""
133
+	for channel, _ := range target.channels {
134
+		perChannelFlags += fmt.Sprintf(" %s:%s", channel.name, channel.members[target])
135
+	}
136
+
137
+	response := fmt.Sprintf("All user modes: %s%s", globalFlags, perChannelFlags)
138
+	return NewStringReply(client, NOTICE, "%s :%s", target.Nick(), response)
139
+}
140
+
126 141
 func RplChannelMode(client *Client, channel *Channel,
127 142
 	changes ChannelModeChanges) string {
128 143
 	return NewStringReply(client, MODE, "%s %s", channel, changes)

Loading…
Cancel
Save