Changed old way to send discord message to the new one

This commit is contained in:
Alex Vanin 2019-05-10 15:55:43 +03:00
parent a527849514
commit 1805fa64ea
4 changed files with 21 additions and 24 deletions

View file

@ -1,5 +1,13 @@
# Changelog # Changelog
## 3.0.1 - 2019-05-10
### Added
- Readme file
### Removed
- Removed redundant setting parameter for subday database dumping duration
### Changed
- Changed way of sending messages to the discord channel
## 3.0.0 - 2019-05-10 ## 3.0.0 - 2019-05-10
### Changed ### Changed
- Redesigned application with modular structure based on uber fx - Redesigned application with modular structure based on uber fx

View file

@ -2,7 +2,6 @@ package discord
import ( import (
"fmt" "fmt"
"log"
"strings" "strings"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
@ -53,10 +52,7 @@ func (h *HandlerProcessor) Process(s *discordgo.Session, m *discordgo.MessageCre
if strings.HasPrefix(m.Content, "!galched") { if strings.HasPrefix(m.Content, "!galched") {
LogMessage(m) LogMessage(m)
_, err := s.ChannelMessageSend(m.ChannelID, h.HelpMessage()) SendMessage(s, m, h.HelpMessage())
if err != nil {
log.Printf("discord: cannot send message [%s]: %v", h.HelpMessage(), err)
}
} }
for i := range h.handlers { for i := range h.handlers {

View file

@ -58,10 +58,7 @@ func (h *SubdayListHandler) Handle(s *discordgo.Session, m *discordgo.MessageCre
message += fmt.Sprintf(" **- %s** от _%s_\n", game, nickname) message += fmt.Sprintf(" **- %s** от _%s_\n", game, nickname)
} }
} }
_, err = s.ChannelMessageSend(m.ChannelID, strings.Trim(message, "\n")) SendMessage(s, m, strings.Trim(message, "\n"))
if err != nil {
log.Printf("discord: cannot send message [%s]: %v", message, err)
}
} }
type SubdayAddHandler struct { type SubdayAddHandler struct {

View file

@ -3,14 +3,12 @@ package settings
import ( import (
"io/ioutil" "io/ioutil"
"log" "log"
"time"
) )
const ( const (
version = "3.0.0" version = "3.0.1"
discordTokenPath = "./tokens/.discordtoken" discordTokenPath = "./tokens/.discordtoken"
subdayDataPath = "./backups/subday" subdayDataPath = "./backups/subday"
subdayDataDuration = 10 // in seconds
// Permitted roles in discord for subday // Permitted roles in discord for subday
subRole1 = "433672344737677322" subRole1 = "433672344737677322"
@ -21,11 +19,10 @@ const (
type ( type (
Settings struct { Settings struct {
Version string Version string
DiscordToken string DiscordToken string
SubdayDataPath string SubdayDataPath string
SubdayJobDuration time.Duration PermittedRoles []string
PermittedRoles []string
} }
) )
@ -36,10 +33,9 @@ func New() (*Settings, error) {
} }
return &Settings{ return &Settings{
Version: version, Version: version,
DiscordToken: string(discordToken), DiscordToken: string(discordToken),
SubdayDataPath: subdayDataPath, SubdayDataPath: subdayDataPath,
SubdayJobDuration: subdayDataDuration * time.Second, PermittedRoles: []string{subRole1, subRole2, galchedRole, smorcRole},
PermittedRoles: []string{subRole1, subRole2, galchedRole, smorcRole},
}, nil }, nil
} }