mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-08 08:10:08 +00:00
Add method to send messages from within the bot without trigger
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
71c708570c
commit
0dc19d8eed
2 changed files with 8 additions and 0 deletions
2
irc.go
2
irc.go
|
@ -138,6 +138,8 @@ func (i ircHandler) Handle(c *irc.Client, m *irc.Message) {
|
|||
|
||||
func (i ircHandler) Run() error { return errors.Wrap(i.c.Run(), "running IRC client") }
|
||||
|
||||
func (i ircHandler) SendMessage(m *irc.Message) error { return i.c.WriteMessage(m) }
|
||||
|
||||
func (ircHandler) getChannel(m *irc.Message) string {
|
||||
if len(m.Params) > 0 {
|
||||
return m.Params[0]
|
||||
|
|
6
main.go
6
main.go
|
@ -7,6 +7,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/go-irc/irc"
|
||||
"github.com/pkg/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
|
@ -32,6 +33,8 @@ var (
|
|||
config *configFile
|
||||
configLock = new(sync.RWMutex)
|
||||
|
||||
sendMessage func(m *irc.Message) error
|
||||
|
||||
store = newStorageFile(false)
|
||||
|
||||
version = "dev"
|
||||
|
@ -102,6 +105,7 @@ func main() {
|
|||
|
||||
case <-ircDisconnected:
|
||||
if irc != nil {
|
||||
sendMessage = nil
|
||||
irc.Close()
|
||||
}
|
||||
|
||||
|
@ -110,9 +114,11 @@ func main() {
|
|||
}
|
||||
|
||||
go func() {
|
||||
sendMessage = irc.SendMessage
|
||||
if err := irc.Run(); err != nil {
|
||||
log.WithError(err).Error("IRC run exited unexpectedly")
|
||||
}
|
||||
sendMessage = nil
|
||||
time.Sleep(ircReconnectDelay)
|
||||
ircDisconnected <- struct{}{}
|
||||
}()
|
||||
|
|
Loading…
Reference in a new issue