-
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.
- Loading branch information
Showing
13 changed files
with
212 additions
and
4 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,22 @@ | ||
package discord | ||
|
||
import "github.com/bwmarrin/discordgo" | ||
|
||
type DiscordClient struct { | ||
*discordgo.Session | ||
} | ||
|
||
func NewDiscordClient(token string) (*DiscordClient, error) { | ||
client, err := discordgo.New(token) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
client.Identify.Intents = makeIntentFlags( | ||
discordgo.IntentsGuildMembers, | ||
discordgo.IntentsGuildMessages, | ||
discordgo.IntentsMessageContent, | ||
) | ||
|
||
return &DiscordClient{client}, nil | ||
} |
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,26 @@ | ||
package discord | ||
|
||
import "github.com/bwmarrin/discordgo" | ||
|
||
func messageCreateEvent(s *discordgo.Session, m *discordgo.MessageCreate) { | ||
if m.Author.ID == s.State.User.ID { | ||
return | ||
} | ||
s.ChannelMessageSend(m.ChannelID, m.Content) | ||
} | ||
|
||
func archiveReleaseHandler(s *discordgo.Session, m *discordgo.MessageCreate) { | ||
if m.ChannelID != "" { | ||
return | ||
} | ||
|
||
if reference := m.Reference(); reference != nil { | ||
referenceMsg, err := s.ChannelMessage(reference.ChannelID, reference.MessageID) | ||
if err == nil { | ||
s.ChannelMessageDelete(referenceMsg.ChannelID, referenceMsg.ID) | ||
return | ||
} | ||
} | ||
|
||
// content := m.Content | ||
} |
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,11 @@ | ||
package discord | ||
|
||
import "github.com/bwmarrin/discordgo" | ||
|
||
func makeIntentFlags(intents ...discordgo.Intent) discordgo.Intent { | ||
var result discordgo.Intent | ||
for _, intent := range intents { | ||
result |= intent | ||
} | ||
return result | ||
} |
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,9 @@ | ||
package hooks | ||
|
||
import "server/config" | ||
|
||
func New() *Service { | ||
return &Service{ | ||
Cfg: *config.Get(), | ||
} | ||
} |
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,7 @@ | ||
package hooks | ||
|
||
import "server/config" | ||
|
||
type Service struct { | ||
Cfg config.Config | ||
} |
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,5 @@ | ||
package mode | ||
|
||
import "errors" | ||
|
||
var ErrInvalidMode = errors.New("invalid mode") |
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,95 @@ | ||
package mode | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
const ( | ||
// Dev is used for development | ||
Dev = "dev" | ||
// Prod is used for production | ||
Prod = "prod" | ||
// TestDev is used for testing | ||
TestDev = "test_dev" | ||
// Default mode | ||
) | ||
|
||
var ( | ||
defaultMode = Dev | ||
mode = defaultMode | ||
) | ||
|
||
// parseMode parses the mode | ||
func parseMode(s string) (string, error) { | ||
switch s := strings.ToLower(s); s { | ||
case Dev, Prod, TestDev: | ||
return s, nil | ||
case "development": | ||
return Dev, nil | ||
case "release": | ||
return Prod, nil | ||
case "test": | ||
return TestDev, nil | ||
case "test-dev": | ||
return TestDev, nil | ||
default: | ||
return "", ErrInvalidMode | ||
} | ||
} | ||
|
||
// Get returns the mode | ||
func Get() string { | ||
return mode | ||
} | ||
|
||
// Set sets the mode | ||
func Set(newMode string) { | ||
if parseMode, err := parseMode(newMode); err == nil { | ||
mode = parseMode | ||
} else { | ||
mode = defaultMode | ||
} | ||
|
||
updateGinMode() | ||
} | ||
|
||
// GetDefault returns the default mode | ||
func GetDefault() string { | ||
return defaultMode | ||
} | ||
|
||
// SetDefaultMode sets the default mode | ||
func SetDefaultMode(newDefaultMode string) { | ||
if parseMode, err := parseMode(newDefaultMode); err == nil { | ||
mode = parseMode | ||
} else { | ||
mode = defaultMode | ||
} | ||
} | ||
|
||
// IsDev returns true if the mode is Dev or TestDev | ||
func IsDev() bool { | ||
mode := Get() | ||
|
||
return mode == Dev || mode == TestDev | ||
} | ||
|
||
// updateGinMode updates the gin mode | ||
func updateGinMode() { | ||
var mode string | ||
|
||
switch Get() { | ||
case Dev: | ||
mode = gin.DebugMode | ||
case TestDev: | ||
mode = gin.TestMode | ||
case Prod: | ||
mode = gin.ReleaseMode | ||
default: | ||
panic("unknown mode") | ||
} | ||
|
||
gin.SetMode(mode) | ||
} |
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,7 @@ | ||
package model | ||
|
||
type VersionInfo struct { | ||
Version string `json:"version"` | ||
BuildDate string `json:"build_date"` | ||
Commit string `json:"commit"` | ||
} |
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 @@ | ||
package router |