mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 16:59:12 +00:00
feat(tools): Add a simple MockIndexer helper for IRC announcing and indexing (#555)
* Add a simple SelfIndexer for IRC announcing and indexing * Rename to MockIndexer * fix: close file after reading
This commit is contained in:
parent
ef088c27ad
commit
0f2ce26ba2
7 changed files with 242 additions and 6 deletions
50
test/mockindexer/irc/server.go
Normal file
50
test/mockindexer/irc/server.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
package irc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
listener net.Listener
|
||||
clients []*Client
|
||||
options *ServerOptions
|
||||
}
|
||||
|
||||
type ServerOptions struct {
|
||||
BotName string
|
||||
Channel string
|
||||
}
|
||||
|
||||
func NewServer(options *ServerOptions) (*Server, error) {
|
||||
listener, err := net.Listen("tcp", "localhost:6697")
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Server{
|
||||
listener: listener,
|
||||
options: options,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Server) Run() {
|
||||
for {
|
||||
conn, err := s.listener.Accept()
|
||||
|
||||
if err != nil {
|
||||
log.Printf("Failed accept: %v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
s.clients = append(s.clients, NewClient(conn, s.options.BotName, s.options.Channel))
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) SendAll(line string) {
|
||||
for _, client := range s.clients {
|
||||
client.writer <- fmt.Sprintf(":%s PRIVMSG %s :%s", s.options.BotName, s.options.Channel, line)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue