build for arm, disable ufw for now, move bot to single package
This commit is contained in:
parent
97fbe7bd5e
commit
cbc5b11dca
8 changed files with 140 additions and 97 deletions
2
Makefile
2
Makefile
|
@ -1,5 +1,5 @@
|
|||
build:
|
||||
go get ./... && env GOOS=linux GOARCH=amd64 go build
|
||||
go get ./... && env GOOS=linux GOARCH=arm go build
|
||||
|
||||
deploy: build
|
||||
ssh root@apollo.gempir.com systemctl stop justlog.service
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
- name: create log directory
|
||||
file:
|
||||
path: /var/justlog
|
||||
path: /mnt/data/justlog
|
||||
state: directory
|
||||
owner: justlog
|
||||
group: justlog
|
||||
|
|
|
@ -1,23 +1,23 @@
|
|||
{
|
||||
"admin": "gempir",
|
||||
"logsDirectory": "/var/justlog",
|
||||
"logsDirectory": "/mnt/data/justlog",
|
||||
"clientID": "{{ clientID }}",
|
||||
"username": "{{ username }}",
|
||||
"oauth": "{{ oauth }}",
|
||||
"channels": [
|
||||
"gempir",
|
||||
"pajlada",
|
||||
"gempbot",
|
||||
"forsen",
|
||||
"jaxerie",
|
||||
"nymn",
|
||||
"nani",
|
||||
"trizze",
|
||||
"chancu",
|
||||
"tearon",
|
||||
"thiccanimegrili",
|
||||
"razq",
|
||||
"krakenbul",
|
||||
"infinitegachi"
|
||||
"11148817",
|
||||
"77829817",
|
||||
"99659894",
|
||||
"22484632",
|
||||
"42426044",
|
||||
"62300805",
|
||||
"93031467",
|
||||
"14824099",
|
||||
"133554225",
|
||||
"36396364",
|
||||
"134551603",
|
||||
"43689956",
|
||||
"41015858",
|
||||
"74844182"
|
||||
]
|
||||
}
|
|
@ -1,28 +1,28 @@
|
|||
---
|
||||
- name: Install ufw
|
||||
apt: package=ufw state=present
|
||||
# - name: Install ufw
|
||||
# apt: package=ufw state=present
|
||||
|
||||
- name: Configure ufw defaults
|
||||
ufw: direction={{ item.direction }} policy={{ item.policy }}
|
||||
with_items:
|
||||
- { direction: 'incoming', policy: 'deny' }
|
||||
- { direction: 'outgoing', policy: 'allow' }
|
||||
notify:
|
||||
- restart ufw
|
||||
# - name: Configure ufw defaults
|
||||
# ufw: direction={{ item.direction }} policy={{ item.policy }}
|
||||
# with_items:
|
||||
# - { direction: 'incoming', policy: 'deny' }
|
||||
# - { direction: 'outgoing', policy: 'allow' }
|
||||
# notify:
|
||||
# - restart ufw
|
||||
|
||||
- name: Configure ufw rules
|
||||
ufw: rule={{ item.rule }} port={{ item.port }} proto={{ item.proto }}
|
||||
with_items:
|
||||
- { rule: 'limit', port: '{{ ssh_port | default("22") }}', proto: 'tcp' }
|
||||
- { rule: 'allow', port: '80', proto: 'tcp' }
|
||||
- { rule: 'allow', port: '443', proto: 'tcp' }
|
||||
notify:
|
||||
- restart ufw
|
||||
# - name: Configure ufw rules
|
||||
# ufw: rule={{ item.rule }} port={{ item.port }} proto={{ item.proto }}
|
||||
# with_items:
|
||||
# - { rule: 'limit', port: '{{ ssh_port | default("22") }}', proto: 'tcp' }
|
||||
# - { rule: 'allow', port: '80', proto: 'tcp' }
|
||||
# - { rule: 'allow', port: '443', proto: 'tcp' }
|
||||
# notify:
|
||||
# - restart ufw
|
||||
|
||||
- name: Enable ufw logging
|
||||
ufw: logging=on
|
||||
notify:
|
||||
- restart ufw
|
||||
# - name: Enable ufw logging
|
||||
# ufw: logging=on
|
||||
# notify:
|
||||
# - restart ufw
|
||||
|
||||
- name: Enable ufw
|
||||
ufw: state=enabled
|
||||
# - name: Enable ufw
|
||||
# ufw: state=enabled
|
|
@ -18,7 +18,7 @@ type Archiver struct {
|
|||
|
||||
func (a *Archiver) Boot() {
|
||||
go a.startScanner()
|
||||
go a.startConsumer()
|
||||
a.startConsumer()
|
||||
}
|
||||
|
||||
func (a *Archiver) startConsumer() {
|
||||
|
|
94
bot/main.go
Normal file
94
bot/main.go
Normal file
|
@ -0,0 +1,94 @@
|
|||
package bot
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gempir/justlog/filelog"
|
||||
|
||||
"github.com/gempir/go-twitch-irc"
|
||||
"github.com/gempir/justlog/helix"
|
||||
"github.com/gempir/justlog/humanize"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type Bot struct {
|
||||
admin string
|
||||
username string
|
||||
oauth string
|
||||
startTime *time.Time
|
||||
helixClient *helix.Client
|
||||
fileLogger *filelog.Logger
|
||||
}
|
||||
|
||||
func NewBot(admin, username, oauth string, startTime *time.Time, helixClient *helix.Client, fileLogger *filelog.Logger) *Bot {
|
||||
return &Bot{
|
||||
admin: admin,
|
||||
username: username,
|
||||
oauth: oauth,
|
||||
startTime: startTime,
|
||||
helixClient: helixClient,
|
||||
fileLogger: fileLogger,
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Bot) Connect(channelIds []string) {
|
||||
twitchClient := twitch.NewClient(b.username, "oauth:"+b.oauth)
|
||||
|
||||
if strings.HasPrefix(b.username, "justinfan") {
|
||||
log.Info("Bot joining anonymous")
|
||||
} else {
|
||||
log.Info("Bot joining as user " + b.username)
|
||||
}
|
||||
|
||||
channels, err := b.helixClient.GetUsersByUserIds(channelIds)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to load configured channels %s", err.Error())
|
||||
}
|
||||
|
||||
for _, channel := range channels {
|
||||
log.Info("Joining " + channel.Login)
|
||||
twitchClient.Join(channel.Login)
|
||||
}
|
||||
|
||||
twitchClient.OnNewMessage(func(channel string, user twitch.User, message twitch.Message) {
|
||||
|
||||
go func() {
|
||||
err := b.fileLogger.LogMessageForUser(channel, user, message)
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
err := b.fileLogger.LogMessageForChannel(channel, user, message)
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
}
|
||||
}()
|
||||
|
||||
if user.Username == b.admin && strings.HasPrefix(message.Text, "!status") {
|
||||
uptime := humanize.TimeSince(*b.startTime)
|
||||
twitchClient.Say(channel, user.DisplayName+", uptime: "+uptime)
|
||||
}
|
||||
})
|
||||
|
||||
twitchClient.OnNewClearchatMessage(func(channel string, user twitch.User, message twitch.Message) {
|
||||
|
||||
go func() {
|
||||
err := b.fileLogger.LogMessageForUser(channel, user, message)
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
err := b.fileLogger.LogMessageForChannel(channel, user, message)
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
}
|
||||
}()
|
||||
})
|
||||
|
||||
log.Fatal(twitchClient.Connect())
|
||||
}
|
|
@ -26,6 +26,7 @@ func NewFileLogger(logPath string) Logger {
|
|||
func (l *Logger) LogMessageForUser(channel string, user twitch.User, message twitch.Message) error {
|
||||
year := message.Time.Year()
|
||||
month := int(message.Time.Month())
|
||||
|
||||
err := os.MkdirAll(fmt.Sprintf(l.logPath+"/%s/%d/%d/", message.Tags["room-id"], year, month), 0740)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
60
main.go
60
main.go
|
@ -8,12 +8,11 @@ import (
|
|||
|
||||
"strings"
|
||||
|
||||
"github.com/gempir/go-twitch-irc"
|
||||
"github.com/gempir/justlog/api"
|
||||
"github.com/gempir/justlog/archiver"
|
||||
"github.com/gempir/justlog/bot"
|
||||
"github.com/gempir/justlog/filelog"
|
||||
"github.com/gempir/justlog/helix"
|
||||
"github.com/gempir/justlog/humanize"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
@ -41,67 +40,16 @@ func main() {
|
|||
cfg = loadConfiguration(*configFile)
|
||||
|
||||
setupLogger(cfg)
|
||||
twitchClient := twitch.NewClient(cfg.Username, "oauth:"+cfg.OAuth)
|
||||
fileLogger := filelog.NewFileLogger(cfg.LogsDirectory)
|
||||
helixClient := helix.NewClient(cfg.ClientID)
|
||||
archiver := archiver.NewArchiver(cfg.LogsDirectory)
|
||||
archiver.Boot()
|
||||
|
||||
if strings.HasPrefix(cfg.Username, "justinfan") {
|
||||
log.Info("Bot joining anonymous")
|
||||
} else {
|
||||
log.Info("Bot joining as user " + cfg.Username)
|
||||
}
|
||||
go archiver.Boot()
|
||||
|
||||
apiServer := api.NewServer(cfg.LogsDirectory, cfg.ListenAddress, &fileLogger, &helixClient)
|
||||
go apiServer.Init()
|
||||
|
||||
for _, channel := range cfg.Channels {
|
||||
log.Info("Joining " + channel)
|
||||
twitchClient.Join(channel)
|
||||
apiServer.AddChannel(channel)
|
||||
}
|
||||
|
||||
twitchClient.OnNewMessage(func(channel string, user twitch.User, message twitch.Message) {
|
||||
|
||||
go func() {
|
||||
err := fileLogger.LogMessageForUser(channel, user, message)
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
err := fileLogger.LogMessageForChannel(channel, user, message)
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
}
|
||||
}()
|
||||
|
||||
if user.Username == cfg.Admin && strings.HasPrefix(message.Text, "!status") {
|
||||
uptime := humanize.TimeSince(startTime)
|
||||
twitchClient.Say(channel, cfg.Admin+", uptime: "+uptime)
|
||||
}
|
||||
})
|
||||
|
||||
twitchClient.OnNewClearchatMessage(func(channel string, user twitch.User, message twitch.Message) {
|
||||
|
||||
go func() {
|
||||
err := fileLogger.LogMessageForUser(channel, user, message)
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
err := fileLogger.LogMessageForChannel(channel, user, message)
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
}
|
||||
}()
|
||||
})
|
||||
|
||||
log.Fatal(twitchClient.Connect())
|
||||
bot := bot.NewBot(cfg.Admin, cfg.Username, cfg.OAuth, &startTime, &helixClient, &fileLogger)
|
||||
bot.Connect(cfg.Channels)
|
||||
}
|
||||
|
||||
func setupLogger(cfg config) {
|
||||
|
|
Loading…
Reference in a new issue