8000 Merge from develop by ikafly144 · Pull Request #162 · sabafly/gobot · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Merge from develop #162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
go-version: '1.22'
- name: Code
uses: actions/checkout@v3
- name: Check diff between gofmt and code
Expand All @@ -20,7 +20,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ['1.21']
go-version: ['1.22']
steps:
- name: Install Go
uses: actions/setup-go@v4
Expand All @@ -39,7 +39,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
go-version: '1.22'
- name: Code
uses: actions/checkout@v4
- name: Go vet
Expand Down
2 changes: 2 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/watcherTasks.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ package bot
import (
"context"
"fmt"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"io"
"log/slog"
"net/http"
"net/url"
"os"
"os/signal"
"syscall"
Expand Down Expand Up @@ -111,6 +116,8 @@ func run() error {
role.ImportCommand(component),
)

ready := make(chan *events.Ready)

token := os.Getenv("TOKEN")
if token == "" {
return fmt.Errorf("TOKEN が空です")
Expand All @@ -129,6 +136,9 @@ func run() error {
),
bot.WithEventManagerConfigOpts(
bot.WithAsyncEventsEnabled(),
bot.WithListeners(
bot.NewListenerChan(ready),
),
),
)
if err != nil {
Expand All @@ -144,6 +154,27 @@ func run() error {
}
defer client.Close(context.Background())

<-ready

// set default webhook
bot.WebhookDefaultName = "gobot-webhook"
self, ok := client.Caches().SelfUser()
if !ok {
return fmt.Errorf("cannot cache self user")
}
if avatarURL, err := url.Parse(self.EffectiveAvatarURL(discord.WithFormat(discord.FileFormatPNG))); err != nil {
resp, err := http.Get(avatarURL.String())
if err != nil {
return fmt.Errorf("error on get: %w", err)
}
defer resp.Body.Close()
buf, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("error on read all: %w", err)
}
bot.WebhookDefaultAvatar = discord.NewIconRaw(discord.IconTypePNG, buf)
}

s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.Signal(0x13), syscall.Signal(0x14))
<-s
Expand Down
15 changes: 9 additions & 6 deletions bot/commands/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ func Command(c *components.Components) *generic.Command {
Private: true,
CommandCreate: []discord.ApplicationCommandCreate{
discord.SlashCommandCreate{
Name: "debug",
Description: "debug",
DMPermission: builtin.Ptr(false),
Name: "debug",
Description: "debug",
DMPermission: builtin.Ptr(false),
Contexts: []discord.InteractionContextType{
discord.InteractionContextTypeGuild,
},
DefaultMemberPermissions: json.NewNullablePtr(discord.PermissionAdministrator),
Options: []discord.ApplicationCommandOption{
discord.ApplicationCommandOptionSubCommandGroup{
Expand Down Expand Up @@ -110,7 +113,7 @@ func Command(c *components.Components) *generic.Command {
if err := event.CreateMessage(
discord.NewMessageBuilder().
SetContent(translate.Message(locale, key)).
Create(),
BuildCreate(),
); err != nil {
return errors.NewError(err)
}
Expand All @@ -124,7 +127,7 @@ func Command(c *components.Components) *generic.Command {
if err := event.CreateMessage(
discord.NewMessageBuilder().
SetContent("OK").
Create(),
BuildCreate(),
); err != nil {
return errors.NewError(err)
}
Expand All @@ -138,7 +141,7 @@ func Command(c *components.Components) *generic.Command {
if err := event.CreateMessage(
discord.NewMessageBuilder().
SetContent("OK").
Create(),
BuildCreate(),
); err != nil {
return errors.NewError(err)
}
Expand Down
Loading
0