mirror of
				https://github.com/fluffle/goirc
				synced 2025-11-04 03:58:03 +00:00 
			
		
		
		
	Keep track of bans by nick and allow unban on nicks
This commit is contained in:
		
							parent
							
								
									9723754282
								
							
						
					
					
						commit
						62e450dd8a
					
				
					 3 changed files with 42 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -288,6 +288,22 @@ func (conn *Conn) setupEvents() {
 | 
			
		|||
					} else {
 | 
			
		||||
						conn.error("irc.MODE(): buh? not enough arguments to process MODE %s %s%s", ch.Name, modestr, m)
 | 
			
		||||
					}
 | 
			
		||||
				case 'b':
 | 
			
		||||
					if len(modeargs) != 0 {
 | 
			
		||||
						// we only care about host bans
 | 
			
		||||
						if modeop && strings.HasPrefix(modeargs[0], "*!*@") {
 | 
			
		||||
							for n, _ := range ch.Nicks {
 | 
			
		||||
								if modeargs[0][4:] == n.Host {
 | 
			
		||||
									ch.AddBan(n.Nick, modeargs[0])
 | 
			
		||||
								}
 | 
			
		||||
							}
 | 
			
		||||
						} else if !modeop {
 | 
			
		||||
							ch.DeleteBan(modeargs[0])
 | 
			
		||||
						}
 | 
			
		||||
						modeargs = modeargs[1:len(modeargs)]
 | 
			
		||||
					} else {
 | 
			
		||||
						conn.error("irc.MODE(): buh? not enough arguments to process MODE %s %s%s", ch.Name, modestr, m)
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		} else if n := conn.GetNick(line.Args[0]); n != nil {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,6 +13,7 @@ type Channel struct {
 | 
			
		|||
	Name, Topic string
 | 
			
		||||
	Modes       *ChanMode
 | 
			
		||||
	Nicks       map[*Nick]*ChanPrivs
 | 
			
		||||
	Bans        map[string]string
 | 
			
		||||
	conn        *Conn
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -103,6 +104,7 @@ func (conn *Conn) GetChannel(c string) *Channel {
 | 
			
		|||
func (ch *Channel) initialise() {
 | 
			
		||||
	ch.Modes = new(ChanMode)
 | 
			
		||||
	ch.Nicks = make(map[*Nick]*ChanPrivs)
 | 
			
		||||
	ch.Bans = make(map[string]string)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Associates an *irc.Nick with an *irc.Channel using a shared *irc.ChanPrivs
 | 
			
		||||
| 
						 | 
				
			
			@ -132,6 +134,18 @@ func (ch *Channel) DelNick(n *Nick) {
 | 
			
		|||
	// consistency, and this would mean spewing an error message every delete
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (ch *Channel) AddBan(nick, ban string) {
 | 
			
		||||
	ch.Bans[nick] = ban
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (ch *Channel) DeleteBan(ban string) {
 | 
			
		||||
	for n, b := range ch.Bans {
 | 
			
		||||
		if b == ban {
 | 
			
		||||
			ch.Bans[n] = "", false // see go issue 1249
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Stops the channel from being tracked by state tracking handlers. Also calls
 | 
			
		||||
// n.DelChannel(ch) for all nicks that are associated with the channel.
 | 
			
		||||
func (ch *Channel) Delete() {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue