package main

import (
	"fmt"

	"github.com/bwmarrin/discordgo"
)

// This function will be called (due to AddHandler in main) every time a new
// message is created on any channel that the authenticated bot has access to.
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
	// Ignore all messages created by the bot itself
	// This isn't required in this specific example but it's a good practice.
	if m.Author.ID == s.State.User.ID {
		return
	}

	// If the message is "ping" reply with "Pong!"
	if m.Content == "ping" {
		s.ChannelMessageSend(m.ChannelID, "Pong!")
	}

	// If the message is "pong" reply with "Ping!"
	if m.Content == "pong" {
		s.ChannelMessageSend(m.ChannelID, "Ping!")
	}
}

func userJoin(s *discordgo.Session, m *discordgo.MessageCreate) {
	// Check if the message is a guild member add event
	if m.Type == discordgo.MessageTypeGuildMemberJoin {
		// Get the guild ID and user ID
		guildID := m.GuildID
		userID := m.Author.ID

		// Replace "YOUR_ROLE_ID" with the actual role ID you want to assign to the user
		roleID := "738764170446503956"

		// Assign the role to the user
		err := s.GuildMemberRoleAdd(guildID, userID, roleID)
		if err != nil {
			fmt.Println("Error assigning role to user: ", err)
		} else {
			fmt.Println("Role assigned to user on join.")
		}
	}
}

func setBotStatus(s *discordgo.Session) {
	// Replace "Playing Game" with the status you want to set
	err := s.UpdateGameStatus(0, "with Golang!")
	if err != nil {
		fmt.Println("Error setting bot status: ", err)
	} else {
		fmt.Println("Bot status updated.")
	}
}
