Skip to content

itschip/guildedgo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

guildedgo

A guilded.gg library in Go

Getting started

go get github.com/itschip/guildedgo

Examples

Listen to events

package main

import (
        "fmt"

        "github.com/itschip/guildedgo"
)

func main() {
        guildedClient := guildedgo.NewClient(&guildedgo.Config{
                Token:    "YOUR_TOKEN",
                ServerID: "YOUR_SERVER_ID",
        })

        // Listen to the ChatMessageCreated event
        guildedClient.On("ChatMessageCreated", func(client *guildedgo.Client, v any) {
                data, ok := v.(*guildedgo.ChatMessageCreated)

                if ok {
                        fmt.Println(data.Message.Content)

                        if data.Message.Content == "!ping" {
                                guildedClient.Channel.SendMessage(data.Message.ChannelID, &guildedgo.MessageObject{
                                        Content: "pong!",
                                })
                        }

                }
        })

        // Open socket
        guildedClient.Open()
}

Command builder

serverID := internal.GetEnv("SERVER_ID")
	token := internal.GetEnv("TOKEN")

	config := &guildedgo.Config{
		ServerID: serverID,
		Token:    token,
	}

	c := guildedgo.NewClient(config)

	commands := &guildedgo.CommandsBuilder{
		Commands: []Command{
			{
				CommandName: "!test",
				Action: func(client *Client, v *ChatMessageCreated) {
					client.Channel.SendMessage(v.Message.ChannelID, &MessageObject{
						Content: "Test",
					})

					fmt.Println("Test working")
				},
			},
			{
				CommandName: "!party",
				Action: func(client *Client, v *ChatMessageCreated) {
					client.Channel.SendMessage(v.Message.ChannelID, &MessageObject{
						Content: "Yeah!!! Let's party",
					})

					fmt.Println("Party working")
				},
			},
		},
	}

	c.CommandService.AddCommands(commands)

	c.Open()