Skip to content

Latest commit

 

History

History
146 lines (105 loc) · 3.3 KB

README.md

File metadata and controls

146 lines (105 loc) · 3.3 KB

stars license supportServer forks issues

🚀 Go Lanyard

Use Lanyard API easily in your Go app!

📦 Installation

  • Initialize your project (go mod init example.com/example)
  • Add package (go get github.com/barbarbar338/go-lanyard)

🤓 Usage

Using without websocket:

package main

import (
	"fmt"

	"github.com/barbarbar338/go-lanyard"
)

func main() {
	//                              User ID here 👇
	res, err := lanyard.FetchUser("952574663916154960")

	// Handle error
	if err != nil {
		// ...
		panic(err)
	}

	// Handle presence data here
	fmt.Println(res.Data.DiscordStatus)
}

Using with websocket:

package main

import (
	"fmt"
	"os"
	"os/signal"
	"syscall"

	"github.com/barbarbar338/go-lanyard"
)

func main() {
	//                          User ID here 👇
	ws := lanyard.ListenUser("952574663916154960", func(data *lanyard.LanyardData) {
		// Handle presence data here
		fmt.Println(data.DiscordStatus)
	})

	sc := make(chan os.Signal, 1)
	signal.Notify(
		sc,
		syscall.SIGINT,
		syscall.SIGTERM,
		os.Interrupt,
	)
	<-sc

	fmt.Println("Closing client.")

	// Destroy WS before exit
	ws.Destroy()
}

Using websocket for watching multiple users:

package main

import (
	"fmt"
	"os"
	"os/signal"
	"syscall"

	"github.com/barbarbar338/go-lanyard"
)

func main() {
	//                                                     User IDs here 👇
	ws := lanyard.ListenMultipleUsers([]string{"866849747603816468", "952574663916154960"}, func(data *lanyard.LanyardData) {
		fmt.Println(data.DiscordStatus)
	})

	sc := make(chan os.Signal, 1)
	signal.Notify(
		sc,
		syscall.SIGINT,
		syscall.SIGTERM,
		os.Interrupt,
	)
	<-sc

	fmt.Println("Closing client.")

	// Destroy WS before exit
	ws.Destroy()
}

📄 License

Copyright © 2021 Barış DEMİRCİ.

Distributed under the GPL-3.0 License. See LICENSE for more information.

🧦 Contributing

Feel free to use GitHub's features.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/my-feature)
  3. Commit your Changes (git commit -m 'my awesome feature my-feature')
  4. Push to the Branch (git push origin feature/my-feature)
  5. Open a Pull Request

🔥 Show your support

Give a ⭐️ if this project helped you!

📞 Contact

✨ Special Thanks