Skip to content

barbarbar338/go-lanyard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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