func onFriendRequest(t *golibtox.Tox, publicKey []byte, data []byte, length uint16) { name, _ := t.GetSelfName() fmt.Printf("[%s] New friend request from %s\n", name, hex.EncodeToString(publicKey)) // Auto-accept friend request t.AddFriendNorequest(publicKey) }
func onFileSendRequest(t *golibtox.Tox, friendnumber int32, filenumber uint8, filesize uint64, filename []byte, filenameLength uint16) { // Accept any file send request t.FileSendControl(friendnumber, true, filenumber, golibtox.FILECONTROL_ACCEPT, nil) // Init *File handle f, _ := os.Create("example_" + string(filename)) // Append f to the map[uint8]*os.File transfers[filenumber] = f }
func onFileControl(t *golibtox.Tox, friendnumber int32, sending bool, filenumber uint8, fileControl golibtox.FileControl, data []byte, length uint16) { // Finished receiving file if fileControl == golibtox.FILECONTROL_FINISHED { f := transfers[filenumber] f.Sync() f.Close() delete(transfers, filenumber) fmt.Println("Written file", filenumber) t.SendMessage(friendnumber, []byte("Thanks!")) } }
func saveData(t *golibtox.Tox, filepath string) error { if len(filepath) == 0 { return errors.New("Empty path") } data, err := t.Save() if err != nil { return err } err = ioutil.WriteFile(filepath, data, 0644) return err }
func loadData(t *golibtox.Tox, filepath string) error { if len(filepath) == 0 { return errors.New("Empty path") } data, err := ioutil.ReadFile(filepath) if err != nil { return err } err = t.Load(data) return err }
func onFriendMessage(t *golibtox.Tox, friendnumber int32, message []byte, length uint16) { fmt.Printf("New message from %d : %s\n", friendnumber, string(message)) // Echo back t.SendMessage(friendnumber, message) }
func onFriendRequest(t *golibtox.Tox, publicKey []byte, data []byte, length uint16) { fmt.Printf("New friend request from %s\n", hex.EncodeToString(publicKey)) fmt.Printf("With message: %v\n", string(data)) // Auto-accept friend request t.AddFriendNorequest(publicKey) }
func onFriendMessage(t *golibtox.Tox, friendnumber int32, message []byte, length uint16) { name, _ := t.GetSelfName() friend, _ := t.GetName(friendnumber) fmt.Printf("[%s] New message from %s : %s\n", name, friend, string(message)) }