channel logs

This commit is contained in:
gempir 2017-03-11 11:06:50 +01:00
parent 32f3f55fc4
commit 181f2919ca
3 changed files with 38 additions and 3 deletions

33
filelog/channellog.go Normal file
View file

@ -0,0 +1,33 @@
package filelog
import (
"github.com/gempir/gempbotgo/twitch"
"strings"
"os"
"fmt"
)
func (l *Logger) LogMessageForChannel(msg twitch.Message) error {
year := msg.Timestamp.Year()
month := msg.Timestamp.Month()
channel := strings.Replace(msg.Channel, "#", "", 1)
err := os.MkdirAll(fmt.Sprintf(l.logPath+"%s/%d/%s/", channel, year, month), 0755)
if err != nil {
return err
}
filename := fmt.Sprintf(l.logPath+"%s/%d/%s/channel.txt", channel, year, month)
file, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0755)
if err != nil {
return err
}
defer file.Close()
contents := fmt.Sprintf("[%s] %s: %s\r\n", msg.Timestamp.Format("2006-01-2 15:04:05"), msg.User.Username, msg.Text)
if _, err = file.WriteString(contents); err != nil {
return err
}
return nil
}

View file

@ -17,7 +17,7 @@ func NewFileLogger(logPath string) Logger {
}
}
func (l *Logger) LogMessage(msg twitch.Message) error {
func (l *Logger) LogMessageForUser(msg twitch.Message) error {
year := msg.Timestamp.Year()
month := msg.Timestamp.Month()
channel := strings.Replace(msg.Channel, "#", "", 1)
@ -38,4 +38,5 @@ func (l *Logger) LogMessage(msg twitch.Message) error {
return err
}
return nil
}
}

View file

@ -61,7 +61,8 @@ func main() {
for msg := range bot.Messages {
go fileLogger.LogMessage(msg)
go fileLogger.LogMessageForUser(msg)
go fileLogger.LogMessageForChannel(msg)
go comboHandler.HandleMessage(msg)
if strings.HasPrefix(msg.Text, "!") {