Skip to content

Commit

Permalink
Merge pull request #10
Browse files Browse the repository at this point in the history
requesterfix
  • Loading branch information
IshaanRao authored Jul 14, 2023
2 parents 9c371fa + 3c85b77 commit 63e727b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
9 changes: 4 additions & 5 deletions fragbots/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ type BotData struct {
LogWebhook string `json:"logwebhook"`
ConsoleWebhook string `json:"consolewebhook"`
} `json:"discordInfo"`
Requester *Requester
}

type Bot string
Expand All @@ -48,7 +47,7 @@ const serverIP = "mc.hypixel.net" //current hypixel IP
var fragBot *FragBot

// StartClient uses credentials to set up and start the fragbot
func StartClient(data BotData) error {
func StartClient(data *BotData, backendUrl string, accessToken string) error {

c := bot.NewClient()

Expand All @@ -59,7 +58,7 @@ func StartClient(data BotData) error {
}

for {
err := joinHypixel(c, data)
err := joinHypixel(c, data, backendUrl, accessToken)
if strings.Contains(err.Error(), "kicked") || strings.Contains(err.Error(), "EOF") {
logging.Log("Kicked:", err.Error())

Expand All @@ -78,8 +77,8 @@ func StartClient(data BotData) error {

// joinHypixel joins the server
// blocks until client is disconnected
func joinHypixel(c *bot.Client, data BotData) error {
fragBot = newFragBot(c, data)
func joinHypixel(c *bot.Client, data *BotData, backendUrl string, accessToken string) error {
fragBot = newFragBot(c, data, backendUrl, accessToken)

player := basic.NewPlayer(c, basic.DefaultSettings, basic.EventsListener{SystemMsg: fragBot.onChat, Disconnect: fragBot.onDc, GameStart: fragBot.onStart}) //Registers all of fragbots hooks
msg.New(c, player, msg.EventsHandler{})
Expand Down
17 changes: 10 additions & 7 deletions fragbots/client/fragbot.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,20 @@ type FragBot struct {
waitTime int
sentJoin bool
requester *Requester
data BotData
data *BotData
}

// initBot sets up everything to run fragbot logic
func newFragBot(c *bot.Client, data BotData) *FragBot {
func newFragBot(c *bot.Client, data *BotData, backendUrl string, accessToken string) *FragBot {
fb := FragBot{
client: c,
Queue: newCmdQueue(),
sentJoin: false,
requester: data.Requester,
data: data,
client: c,
Queue: newCmdQueue(),
sentJoin: false,
requester: NewRequester(
backendUrl,
accessToken,
),
data: data,
}

switch data.BotType {
Expand Down
4 changes: 1 addition & 3 deletions fragbots/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ func main() {
logging.LogFatal("Failed to get fragbot data:", err)
}

data.BotInfo.Requester = requester

err = client.StartClient(data.BotInfo)
err = client.StartClient(&data.BotInfo, backendUrl, accessToken)
if err != nil {
logging.LogFatal("Client stopped:", err)
}
Expand Down

0 comments on commit 63e727b

Please sign in to comment.