From d1986be68a2f76503407d3e8a62024284b66f116 Mon Sep 17 00:00:00 2001 From: Chris Sexton <3216719+chrissexton@users.noreply.github.com> Date: Sun, 5 Mar 2023 15:26:41 -0500 Subject: [PATCH] gpt: make gpt the catchall --- connectors/discord/discord.go | 22 +++++++++++++++++++++- main.go | 4 ++-- plugins/fact/factoid.go | 13 +------------ plugins/gpt/gpt3.go | 5 +++++ 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/connectors/discord/discord.go b/connectors/discord/discord.go index 6e5109a..8f1b3a1 100644 --- a/connectors/discord/discord.go +++ b/connectors/discord/discord.go @@ -151,7 +151,27 @@ func (d *Discord) sendMessage(channel, message string, meMessage bool, args ...a Interface("data", data). Msg("sending message") - st, err := d.client.ChannelMessageSendComplex(channel, data) + maxLen := 2000 + chunkSize := maxLen - 100 + var st *discordgo.Message + var err error + if len(data.Content) > maxLen { + tmp := data.Content + data.Content = tmp[:chunkSize] + st, err = d.client.ChannelMessageSendComplex(channel, data) + if err != nil { + return "", err + } + for i := chunkSize; i < len(data.Content); i += chunkSize { + data := &discordgo.MessageSend{Content: tmp[i : i+chunkSize]} + st, err = d.client.ChannelMessageSendComplex(channel, data) + if err != nil { + break + } + } + } else { + st, err = d.client.ChannelMessageSendComplex(channel, data) + } //st, err := d.client.ChannelMessageSend(channel, message) if err != nil { diff --git a/main.go b/main.go index b134a0e..296ce88 100644 --- a/main.go +++ b/main.go @@ -135,7 +135,6 @@ func main() { b.AddPlugin(roles.New(b)) b.AddPlugin(twitch.New(b)) b.AddPlugin(pagecomment.New(b)) - b.AddPlugin(gpt.New(b)) b.AddPlugin(secrets.New(b)) b.AddPlugin(mayi.New(b)) b.AddPlugin(giphy.New(b)) @@ -179,8 +178,9 @@ func main() { b.AddPlugin(cowboy.New(b)) b.AddPlugin(topic.New(b)) b.AddPlugin(talker.New(b)) - // catches anything left, will always return true b.AddPlugin(fact.New(b)) + // catches anything left, will always return true + b.AddPlugin(gpt.New(b)) if err := client.Serve(); err != nil { log.Fatal().Err(err) diff --git a/plugins/fact/factoid.go b/plugins/fact/factoid.go index d4098e8..9a68f68 100644 --- a/plugins/fact/factoid.go +++ b/plugins/fact/factoid.go @@ -485,18 +485,7 @@ func (p *FactoidPlugin) register() { return true } - notFound := p.c.GetArray("fact.notfound", []string{ - "I don't know.", - "NONONONO", - "((", - "*pukes*", - "NOPE! NOPE! NOPE!", - "One time, I learned how to jump rope.", - }) - - // We didn't find anything, panic! - p.b.Send(c, bot.Message, message.Channel, notFound[rand.Intn(len(notFound))]) - return true + return false }}, } p.b.RegisterTable(p, p.handlers) diff --git a/plugins/gpt/gpt3.go b/plugins/gpt/gpt3.go index 8b3737b..4cba3f0 100644 --- a/plugins/gpt/gpt3.go +++ b/plugins/gpt/gpt3.go @@ -54,6 +54,11 @@ func (p *GPTPlugin) register() { HelpText: "set the ChatGPT prompt", Handler: p.setPromptMessage, }, + { + Kind: bot.Message, IsCmd: true, + Regex: regexp.MustCompile(`(?P.*)`), + Handler: p.chatMessage, + }, } log.Debug().Msg("Registering GPT3 handlers") p.b.RegisterTable(p, p.h)