<commit_before>package main

import (
	"encoding/xml"
	"flag"
	"fmt"
	"github.com/priscillachat/prisclient"
	"github.com/priscillachat/prislog"
	"os"
	"regexp"
	"strings"
	"time"
)

const (
	hipchatHost = "chat.hipchat.com"
	hipchatConf = "conf.hipchat.com"
)

type hipchatClient struct {
	username string
	password string
	resource string
	id       string
	nick     string

	// private
	usersByMention  map[string]*hipchatUser
	usersByName     map[string]*hipchatUser
	usersByJid      map[string]*hipchatUser
	usersByEmail    map[string]*hipchatUser
	xmpp            *xmppConn
	receivedMessage chan *message
	roomsByName     map[string]string
	roomsById       map[string]string
	host            string
	jid             string
	accountId       string
	apiHost         string
	chatHost        string
	mucHost         string
	webHost         string
	token           string
	mention         string
	aMention        string
}

type message struct {
	From        string
	To          string
	Body        string
	MentionName string
}

type xmppMessage struct {
	XMLName  xml.Name `xml:"message"`
	Type     string   `xml:"type,attr"`
	From     string   `xml:"from,attr"`
	FromJid  string   `xml:"from_jid,attr"`
	To       string   `xml:"to,attr"`
	Id       string   `xml:"id,attr"`
	Body     string   `xml:"body"`
	RoomName string   `xml:"x>name,omitempty"`
	RoomId   string   `xml:"x>id,omitempty"`
}

var logger *prislog.PrisLog

func main() {

	user := flag.String("user", "", "hipchat username")
	pass := flag.String("pass", "", "<PASSWORD>")
	nick := flag.String("nick", "Priscilla", "hipchat full name")
	server := flag.String("server", "127.0.0.1", "priscilla server")
	port := flag.String("port", "4517", "priscilla server port")
	sourceid := flag.String("id", "priscilla-hipchat", "source id")
	loglevel := flag.String("loglevel", "warn", "loglevel")

	flag.Parse()

	var err error

	logger, err = prislog.NewLogger(os.Stdout, *loglevel)

	if err != nil {
		fmt.Println("Error initializing logger: ", err)
		os.Exit(-1)
	}

	conn, err := xmppConnect(hipchatHost)

	if err != nil {
		logger.Error.Println("Error connecting to priscilla:", err)
		os.Exit(1)
	}

	logger.Info.Println("Connected")

	hc := &hipchatClient{
		username: *user,
		password: <PASSWORD>,
		resource: "bot",
		id:       *user + "@" + hipchatHost,
		nick:     *nick,

		xmpp:            conn,
		usersByMention:  make(map[string]*hipchatUser),
		usersByJid:      make(map[string]*hipchatUser),
		usersByName:     make(map[string]*hipchatUser),
		usersByEmail:    make(map[string]*hipchatUser),
		receivedMessage: make(chan *message),
		host:            hipchatHost,
		roomsByName:     make(map[string]string),
		roomsById:       make(map[string]string),
	}

	err = hc.initialize()

	if err != nil {
		logger.Error.Fatal("Failed to initialize:", err)
	}
	logger.Info.Println("Authenticated")

	hc.xmpp.VCardRequest(hc.jid, "")
	self, err := hc.xmpp.VCardDecode(nil)

	if err != nil {
		logger.Error.Fatal("Failed to retrieve info on myself:", err)
	}

	hc.mention = self.Mention
	hc.aMention = "@" + self.Mention

	self.Jid = hc.jid

	hc.updateUserInfo(self)

	priscilla, err := prisclient.NewClient(*server, *port, logger)

	if err != nil {
		logger.Error.Println("Failed to create priscilla-hipchate:", err)
		os.Exit(2)
	}

	err = priscilla.Engage("adapter", *sourceid)

	if err != nil {
		logger.Error.Println("Failed to engage:", err)
		os.Exit(3)
	}

	logger.Info.Println("Priscilla engaged")

	// quit := make(chan int)

	rooms := hc.xmpp.Discover(hc.jid, hc.mucHost)

	autojoin := make([]string, 0, len(rooms))

	for _, room := range rooms {
		hc.roomsByName[room.Name] = room.Id
		hc.roomsById[room.Id] = room.Name
		autojoin = append(autojoin, room.Id)
	}

	hc.xmpp.Join(hc.jid, hc.nick, autojoin)<commit_msg>new client initialization function<commit_after>package main

import (
	"encoding/xml"
	"flag"
	"fmt"
	"github.com/priscillachat/prisclient"
	"github.com/priscillachat/prislog"
	"os"
	"regexp"
	"strings"
	"time"
)

const (
	hipchatHost = "chat.hipchat.com"
	hipchatConf = "conf.hipchat.com"
)

type hipchatClient struct {
	username string
	password string
	resource string
	id       string
	nick     string

	// private
	usersByMention  map[string]*hipchatUser
	usersByName     map[string]*hipchatUser
	usersByJid      map[string]*hipchatUser
	usersByEmail    map[string]*hipchatUser
	xmpp            *xmppConn
	receivedMessage chan *message
	roomsByName     map[string]string
	roomsById       map[string]string
	host            string
	jid             string
	accountId       string
	apiHost         string
	chatHost        string
	mucHost         string
	webHost         string
	token           string
	mention         string
	aMention        string
}

type message struct {
	From        string
	To          string
	Body        string
	MentionName string
}

type xmppMessage struct {
	XMLName  xml.Name `xml:"message"`
	Type     string   `xml:"type,attr"`
	From     string   `xml:"from,attr"`
	FromJid  string   `xml:"from_jid,attr"`
	To       string   `xml:"to,attr"`
	Id       string   `xml:"id,attr"`
	Body     string   `xml:"body"`
	RoomName string   `xml:"x>name,omitempty"`
	RoomId   string   `xml:"x>id,omitempty"`
}

var logger *prislog.PrisLog

func main() {

	user := flag.String("user", "", "hipchat username")
	pass := flag.String("pass", "", "<PASSWORD>")
	nick := flag.String("nick", "Priscilla", "hipchat full name")
	server := flag.String("server", "127.0.0.1", "priscilla server")
	port := flag.String("port", "4517", "priscilla server port")
	sourceid := flag.String("id", "priscilla-hipchat", "source id")
	loglevel := flag.String("loglevel", "warn", "loglevel")

	flag.Parse()

	var err error

	logger, err = prislog.NewLogger(os.Stdout, *loglevel)

	if err != nil {
		fmt.Println("Error initializing logger: ", err)
		os.Exit(-1)
	}

	conn, err := xmppConnect(hipchatHost)

	if err != nil {
		logger.Error.Println("Error connecting to priscilla:", err)
		os.Exit(1)
	}

	logger.Info.Println("Connected")

	hc := &hipchatClient{
		username: *user,
		password: <PASSWORD>,
		resource: "bot",
		id:       *user + "@" + hipchatHost,
		nick:     *nick,

		xmpp:            conn,
		usersByMention:  make(map[string]*hipchatUser),
		usersByJid:      make(map[string]*hipchatUser),
		usersByName:     make(map[string]*hipchatUser),
		usersByEmail:    make(map[string]*hipchatUser),
		receivedMessage: make(chan *message),
		host:            hipchatHost,
		roomsByName:     make(map[string]string),
		roomsById:       make(map[string]string),
	}

	err = hc.initialize()

	if err != nil {
		logger.Error.Fatal("Failed to initialize:", err)
	}
	logger.Info.Println("Authenticated")

	hc.xmpp.VCardRequest(hc.jid, "")
	self, err := hc.xmpp.VCardDecode(nil)

	if err != nil {
		logger.Error.Fatal("Failed to retrieve info on myself:", err)
	}

	hc.mention = self.Mention
	hc.aMention = "@" + self.Mention

	self.Jid = hc.jid

	hc.updateUserInfo(self)

	priscilla, err :=
		prisclient.NewClient(*server, *port, "adapter", *sourceid, logger)

	if err != nil {
		logger.Error.Println("Failed to create priscilla-hipchate:", err)
		os.Exit(2)
	}

	err = priscilla.Engage()

	if err != nil {
		logger.Error.Println("Failed to engage:", err)
		os.Exit(3)
	}

	logger.Info.Println("Priscilla engaged")

	// quit := make(chan int)

	rooms := hc.xmpp.Discover(hc.jid, hc.mucHost)

	autojoin := make([]string, 0, len(rooms))

	for _, room := range rooms {
		hc.roomsByName[room.Name] = room.Id
		hc.roomsById[room.Id] = room.Name
		autojoin = append(autojoin, room.Id)
	}

	hc.xmpp.Join(hc.jid, hc.nick, autojoin)
{'fraction_non_alphanumeric': 0.13906064991448494, 'fraction_numerical': 0.003946849098802789, 'mean_word_length': 3.331623931623932, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 22}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6919096', 'n_tokens_mistral': 2854, 'n_tokens_neox': 2729, 'n_words': 583}