Beispiel #1
0
func CreateConnection(host string) *IrcConn {
	flag.Parse()
	ic := new(IrcConn)
	ic.Host = host
	ic.Bot = ircx.Classic(*server, *name)
	return ic
}
Beispiel #2
0
func main() {
	bot := ircx.Classic(*server, *name)
	if err := bot.Connect(); err != nil {
		log.Panicln("Unable to dial IRC Server ", err)
	}
	RegisterHandlers(bot)
	bot.HandleLoop()
	log.Println("Exiting..")
}
Beispiel #3
0
// Start start the client
func (client IRCClient) Start() {

	bot := ircx.Classic(server, name)
	if err := bot.Connect(); err != nil {
		log.Panicln("Unable to dial IRC Server ", err)
	}
	bot.HandleFunc(irc.RPL_WELCOME, client.onConnected)
	bot.HandleFunc(irc.PRIVMSG, client.onMessage)

	fmt.Fprintf(client.robot, "IRCClient: Joined %s channel %s as %s", server, "#landerblom", name)
	bot.HandleLoop()
}
Beispiel #4
0
func main() {
	var err error

	conf.Use(configure.NewFlag())
	conf.Use(configure.NewEnvironment())
	conf.Parse()

	models.Init(
		*dbUser,
		*dbPass,
		*dbService,
		*dbPort,
		*dbName,
	)

	_, err = logrus_sentry.NewSentryHook(*sentryDSN, []log.Level{
		log.PanicLevel,
		log.FatalLevel,
		log.ErrorLevel,
	})

	if err != nil {
		log.WithFields(log.Fields{
			"error": err,
		}).Fatal("Unable to get connect to sentry")

		return
	}

	bot := ircx.Classic(*serverName, *name)

	log.WithFields(log.Fields{
		"address": *serverName,
	}).Info("Starting connection to the IRC server")

	reconnect(bot.Connect, "IRC")

	bot.HandleFunc(irc.RPL_WELCOME, registerHandler)
	bot.HandleFunc(irc.PING, pingHandler)
	bot.HandleFunc(irc.PRIVMSG, msgHandler)
	bot.HandleFunc(irc.INVITE, inviteHandler)

	log.WithFields(log.Fields{
		"address": *dispatch,
	}).Info("Starting connection to RPC the server")

	reconnect(connectRPC, "RPC")

	bot.HandleLoop()

	log.Println("finished")
}
Beispiel #5
0
func realMain(c *cli.Context) {
	// Create the underlying connection
	bot := ircx.Classic(c.String("server"), c.String("name"))
	bot.Config.MaxRetries = 10
	if usr := c.String("user"); usr != "" {
		bot.Config.User = usr
	}
	bot.Config.Password = c.String("pass")

	channels := strings.Split(c.String("channels"), ",")

	// Create a new bogon
	bogon, err := bogon.New(bot, c.String("name"), channels)
	if err != nil {
		log.Fatalf("Unable to start new bogon: %s", err)
	}

	// Setup & add config
	viper.AutomaticEnv()

	// Add config file if provided
	if cfg := c.String("config"); cfg != "" {
		viper.SetConfigFile(cfg)
		viper.WatchConfig()
		if err := viper.ReadInConfig(); err != nil {
			log.Fatalf("Unable to read config: %s", err)
		}
	}

	// Add viper provider
	config.RegisterProvider(viperprovider.V{})

	// Set up commands
	if err := commandSetup(bogon, c); err != nil {
		log.Fatalf("error setting up commands: %s", err)
	}

	if cfg := c.String("admin"); cfg != "" {
		bogon.AdminSocket(cfg)
	}

	// Connect!
	if err := bogon.Connect(); err != nil {
		log.Fatalf("Unable to connect: %s", err)
	}
	bogon.Start()
}
Beispiel #6
0
func main() {
	conf = configure()
	var bot *ircx.Bot
	if len(serverpass) > 0 {
		bot = ircx.WithLoginTLS(server, name, name, serverpass, nil)
	} else {
		bot = ircx.Classic(server, name)
	}

	performRegistrations(bot)

	if err := bot.Connect(); err != nil {
		log.Fatal(err)
	}
	messages.WriteLoop()
	fmt.Printf("Connecting...\n")
	bot.HandleLoop()
}
Beispiel #7
0
// NewZombie either creates or retrieves a zombie. Zombies will be created if
// they do not already exist for that user on a server. Zombies will be
// retrieved if a zombie for the user on a server already exists
func NewZombie(server, nick string) (*Zombie, error) {
	zombie := ircx.Classic(server, nick)

	if err := zombie.Connect(); err != nil {
		return nil, err
	}

	user := &Zombie{
		Messages: make(chan Send),
		irc:      zombie,
		server:   server,
		nick:     nick,
	}

	zombie.HandleFunc(irc.PING, user.pingHandler)
	zombie.HandleFunc(irc.RPL_WELCOME, user.registerHandler)
	zombie.HandleFunc(irc.JOIN, user.messageHandler)

	go zombie.HandleLoop()

	return user, nil
}
Beispiel #8
0
func main() {
	b, err := ioutil.ReadFile(*configfile)

	if err != nil {
		fmt.Printf("Can not read file (%s)\n", *configfile)
		os.Exit(1)
	}

	err = yaml.Unmarshal(b, &config)

	if err != nil {
		fmt.Printf("Config (%s) is invalid\n", *configfile)
		os.Exit(1)
	}

	bot := ircx.Classic(config.General.Server, config.General.Name)
	if err := bot.Connect(); err != nil {
		log.Panicln("Unable to dial IRC Server ", err)
	}

	RegisterHandlers(bot)
	bot.HandleLoop()
	log.Println("Exiting..")
}