-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Migrates deployment to fly.io * Astral now opt-in AI features * Removes TL.net StarCraft2 feeds (also Telegram/Discord Channel Push). 🙏 R.I.P StarCraft2 * bump Go to 1.21 * bump telegram bot to support v5 APIs * Refactor PluginHub * 再见啦,7年前的自己 Signed-off-by: scbizu <[email protected]>
- Loading branch information
Showing
22 changed files
with
250 additions
and
458 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# flyctl launch added from .gitignore | ||
**/.env | ||
fly.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
|
||
FROM golang:1.17 AS BUILDER | ||
FROM golang:1.21 AS BUILDER | ||
|
||
WORKDIR /project/Astral | ||
|
||
ADD . /project/Astral | ||
|
||
RUN export GO11MODULE="on" && go build -o astral . | ||
RUN go build -o astral . | ||
|
||
FROM golang:1.17 | ||
FROM golang:1.21 | ||
|
||
WORKDIR /Astral | ||
|
||
COPY --from=BUILDER /project/Astral/astral /Astral/astral | ||
|
||
EXPOSE 8443 | ||
|
||
ENTRYPOINT [ "/Astral/astral" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# fly.toml app configuration file generated for astral-on-telegram on 2023-10-08T23:30:09+08:00 | ||
# | ||
# See https://fly.io/docs/reference/configuration/ for information about how to use this file. | ||
# | ||
|
||
app = "astral-on-telegram" | ||
primary_region = "hkg" | ||
|
||
[build] | ||
|
||
[http_service] | ||
internal_port = 8443 | ||
force_https = true | ||
auto_stop_machines = true | ||
auto_start_machines = true | ||
min_machines_running = 0 | ||
processes = ["app"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package openai | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/rakyll/openai-go" | ||
"github.com/rakyll/openai-go/chat" | ||
"github.com/scbizu/Astral/internal/config" | ||
) | ||
|
||
var ( | ||
openAIClientOnce sync.Once | ||
openAIChatClient *chat.Client | ||
) | ||
|
||
func GetOpenAIClient() *chat.Client { | ||
openAIClientOnce.Do(func() { | ||
openAISession := openai.NewSession(config.OpenAIAPIKEy) | ||
c := chat.NewClient(openAISession, "") | ||
c.CreateCompletionEndpoint = config.OpenAIAPIEndpoint | ||
openAIChatClient = c | ||
}) | ||
return openAIChatClient | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package ai | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
|
||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" | ||
"github.com/rakyll/openai-go/chat" | ||
"github.com/scbizu/Astral/internal/openai" | ||
"github.com/scbizu/Astral/internal/plugin" | ||
"github.com/scbizu/Astral/internal/telegram/command" | ||
) | ||
|
||
var _ plugin.IPlugin = (*AICommands)(nil) | ||
|
||
type AICommands struct{} | ||
|
||
func (ai *AICommands) Name() command.CommanderName { | ||
return command.CommandAIChat | ||
} | ||
|
||
func (ai *AICommands) Enable() bool { | ||
return true | ||
} | ||
|
||
func (ai *AICommands) Process(msg *tgbotapi.Message) tgbotapi.MessageConfig { | ||
cmd := command.NewCommand( | ||
command.CommandAIChat, | ||
"chat with openAI", | ||
func(msg *tgbotapi.Message) tgbotapi.MessageConfig { | ||
resp, err := openai.GetOpenAIClient().CreateCompletion(context.TODO(), &chat.CreateCompletionParams{ | ||
Messages: []*chat.Message{ | ||
{Role: "user", Content: msg.Text}, | ||
}, | ||
}) | ||
if err != nil { | ||
return tgbotapi.NewMessage(msg.Chat.ID, err.Error()) | ||
} | ||
msgBuffer := bytes.NewBuffer(nil) | ||
for _, choice := range resp.Choices { | ||
fmt.Fprintf(msgBuffer, "%s\n", choice.Message.Content) | ||
} | ||
return tgbotapi.NewMessage(msg.Chat.ID, msgBuffer.String()) | ||
}, | ||
) | ||
return cmd.Do(msg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.