Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2d029f918 | ||
|
|
293102c1c6 | ||
|
|
de04d6069b | ||
|
|
b249a495a4 | ||
|
|
f4d324da9b | ||
|
|
fff73cfe44 | ||
|
|
31885d76f0 | ||
|
|
fec21a0045 | ||
|
|
d721112738 | ||
|
|
dd51f7fd59 | ||
|
|
42e6ca8f26 |
+75
-18
@@ -1,21 +1,78 @@
|
|||||||
workspace:
|
name: logbot3
|
||||||
base: /go
|
|
||||||
path: src/git.aiterp.net/rpdata/logbot3
|
|
||||||
|
|
||||||
pipeline:
|
kind: pipeline
|
||||||
docker-release:
|
type: docker
|
||||||
image: plugins/docker
|
|
||||||
repo: vmaple/rpdata-logbot3
|
steps:
|
||||||
auto_tag: true
|
- name: go-build-1.11
|
||||||
secrets: [ docker_username, docker_password ]
|
image: golang:1.11
|
||||||
|
commands:
|
||||||
|
- go mod download
|
||||||
|
- CGO_ENABLED=0 go build -ldflags "-w -s" .
|
||||||
when:
|
when:
|
||||||
event: tag
|
event:
|
||||||
ref: refs/tags/*
|
exclude:
|
||||||
docker-release-latest:
|
- tag
|
||||||
image: plugins/docker
|
|
||||||
repo: vmaple/rpdata-logbot3
|
- name: go-build-1.12
|
||||||
tags: latest
|
image: golang:1.12
|
||||||
secrets: [ docker_username, docker_password ]
|
commands:
|
||||||
|
- go mod download
|
||||||
|
- CGO_ENABLED=0 go build -ldflags "-w -s" .
|
||||||
when:
|
when:
|
||||||
event: tag
|
event:
|
||||||
ref: refs/tags/*
|
exclude:
|
||||||
|
- tag
|
||||||
|
|
||||||
|
- name: go-build-1.13
|
||||||
|
image: golang:1.13
|
||||||
|
commands:
|
||||||
|
- go mod download
|
||||||
|
- CGO_ENABLED=0 go build -ldflags "-w -s" .
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
exclude:
|
||||||
|
- tag
|
||||||
|
|
||||||
|
- name: go-build-1.14
|
||||||
|
image: golang:1.14
|
||||||
|
commands:
|
||||||
|
- go mod download
|
||||||
|
- CGO_ENABLED=0 go build -ldflags "-w -s" .
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
exclude:
|
||||||
|
- tag
|
||||||
|
|
||||||
|
- name: go-test
|
||||||
|
image: golang:1.14
|
||||||
|
commands:
|
||||||
|
- go test -v ./...
|
||||||
|
|
||||||
|
- name: docker-release-tag
|
||||||
|
image: plugins/docker
|
||||||
|
settings:
|
||||||
|
auto_tag: true
|
||||||
|
username:
|
||||||
|
from_secret: docker_username
|
||||||
|
password:
|
||||||
|
from_secret: docker_password
|
||||||
|
repo: r.vmaple.dev/rpdata/logbot3
|
||||||
|
registry: r.vmaple.dev
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- tag
|
||||||
|
|
||||||
|
- name: docker-release-latest
|
||||||
|
image: plugins/docker
|
||||||
|
settings:
|
||||||
|
auto_tag: false
|
||||||
|
username:
|
||||||
|
from_secret: docker_username
|
||||||
|
password:
|
||||||
|
from_secret: docker_password
|
||||||
|
repo: r.vmaple.dev/rpdata/logbot3
|
||||||
|
registry: r.vmaple.dev
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- tag
|
||||||
+3
-1
@@ -3,4 +3,6 @@ debug
|
|||||||
debug.exe
|
debug.exe
|
||||||
logbot3
|
logbot3
|
||||||
logbot3.exe
|
logbot3.exe
|
||||||
vendor/
|
|
||||||
|
# Idea
|
||||||
|
/.idea
|
||||||
|
|||||||
+7
-9
@@ -1,29 +1,27 @@
|
|||||||
## 1. Build Server
|
## 1. Build Server
|
||||||
# Use Go 1.11
|
# Use Go 1.14
|
||||||
FROM golang:1.11 AS build
|
FROM golang:1.14 AS build
|
||||||
|
|
||||||
# Load repository into docker
|
# Load repository into docker
|
||||||
WORKDIR /go/src/git.aiterp.net/rpdata/logbot3/
|
WORKDIR /project
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN rm -rf ./vendor
|
|
||||||
|
|
||||||
# Load and run dependencies
|
# Load and run dependencies
|
||||||
RUN go get -u github.com/golang/dep/cmd/dep
|
RUN go get
|
||||||
RUN dep ensure
|
|
||||||
|
|
||||||
# Build server and tools (CGO disabled to make them 100% static)
|
# Build server and tools (CGO disabled to make them 100% static)
|
||||||
ENV CGO_ENABLED 0
|
ENV CGO_ENABLED 0
|
||||||
RUN go build -a -installsuffix cgo -ldflags="-s -w" -o /binaries/logbot3 .
|
RUN go build -a -installsuffix cgo -ldflags="-s -w" -o logbot3 .
|
||||||
|
|
||||||
## 2. Distribute
|
## 2. Distribute
|
||||||
# Use alpine linux
|
# Use alpine linux
|
||||||
FROM alpine:3.8 as main-dist
|
FROM alpine:3.12 as main-dist
|
||||||
|
|
||||||
# Install certificates to enable HTTPS GET requests
|
# Install certificates to enable HTTPS GET requests
|
||||||
RUN apk add --no-cache ca-certificates
|
RUN apk add --no-cache ca-certificates
|
||||||
|
|
||||||
# Copy build files into final container
|
# Copy build files into final container
|
||||||
COPY --from=build /binaries/* /usr/local/bin/
|
COPY --from=build /project/logbot3 /usr/local/bin/
|
||||||
|
|
||||||
# The server is the main entry point
|
# The server is the main entry point
|
||||||
CMD ["/usr/local/bin/logbot3"]
|
CMD ["/usr/local/bin/logbot3"]
|
||||||
|
|||||||
Generated
-26
@@ -1,26 +0,0 @@
|
|||||||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
|
||||||
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "git.aiterp.net/gisle/irc"
|
|
||||||
packages = [
|
|
||||||
".",
|
|
||||||
"ircutil",
|
|
||||||
"isupport",
|
|
||||||
"list"
|
|
||||||
]
|
|
||||||
revision = "c1e97eb9d2e383147662ddd649fcab1bdaf295b4"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/dgrijalva/jwt-go"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "06ea1031745cb8b3dab3f6a236daf2b0aa468b7e"
|
|
||||||
version = "v3.2.0"
|
|
||||||
|
|
||||||
[solve-meta]
|
|
||||||
analyzer-name = "dep"
|
|
||||||
analyzer-version = 1
|
|
||||||
inputs-digest = "7ef4c9d0736b7eb8e596036446cae5d12a8d7485db1559cfa8ade7ba1bf74263"
|
|
||||||
solver-name = "gps-cdcl"
|
|
||||||
solver-version = 1
|
|
||||||
-38
@@ -1,38 +0,0 @@
|
|||||||
# Gopkg.toml example
|
|
||||||
#
|
|
||||||
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
|
|
||||||
# for detailed Gopkg.toml documentation.
|
|
||||||
#
|
|
||||||
# required = ["github.com/user/thing/cmd/thing"]
|
|
||||||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
|
|
||||||
#
|
|
||||||
# [[constraint]]
|
|
||||||
# name = "github.com/user/project"
|
|
||||||
# version = "1.0.0"
|
|
||||||
#
|
|
||||||
# [[constraint]]
|
|
||||||
# name = "github.com/user/project2"
|
|
||||||
# branch = "dev"
|
|
||||||
# source = "github.com/myfork/project2"
|
|
||||||
#
|
|
||||||
# [[override]]
|
|
||||||
# name = "github.com/x/y"
|
|
||||||
# version = "2.4.0"
|
|
||||||
#
|
|
||||||
# [prune]
|
|
||||||
# non-go = false
|
|
||||||
# go-tests = true
|
|
||||||
# unused-packages = true
|
|
||||||
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
branch = "master"
|
|
||||||
name = "git.aiterp.net/gisle/irc"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
name = "github.com/dgrijalva/jwt-go"
|
|
||||||
version = "3.2.0"
|
|
||||||
|
|
||||||
[prune]
|
|
||||||
go-tests = true
|
|
||||||
unused-packages = true
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
module git.aiterp.net/rpdata/logbot3
|
||||||
|
|
||||||
|
go 1.13
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
||||||
|
github.com/gissleh/irc v0.0.0-20200720191144-af5dc31ff33d
|
||||||
|
)
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
|
||||||
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||||
|
github.com/gissleh/irc v0.0.0-20200720173331-512ba5aa6fca h1:vTL3kM7PkVnTy77i2/ewaC0VDmSEF7sAOMDTNIs6rKY=
|
||||||
|
github.com/gissleh/irc v0.0.0-20200720173331-512ba5aa6fca/go.mod h1:h2/fPlbnb11gFpitk0HGxYLgK+bCKGh55QSYNo36X8M=
|
||||||
|
github.com/gissleh/irc v0.0.0-20200720191144-af5dc31ff33d h1:PbjXoijU290Y6qTD/LM9yyFTWgX8iJtPMQ4Adwsn954=
|
||||||
|
github.com/gissleh/irc v0.0.0-20200720191144-af5dc31ff33d/go.mod h1:h2/fPlbnb11gFpitk0HGxYLgK+bCKGh55QSYNo36X8M=
|
||||||
+41
-40
@@ -6,9 +6,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.aiterp.net/gisle/irc"
|
|
||||||
"git.aiterp.net/rpdata/logbot3/internal/models"
|
|
||||||
"git.aiterp.net/rpdata/logbot3/internal/models/channels"
|
"git.aiterp.net/rpdata/logbot3/internal/models/channels"
|
||||||
|
"github.com/gissleh/irc"
|
||||||
)
|
)
|
||||||
|
|
||||||
var botKey = "git.aiterp.net/rpdata/logbot.Bot.key"
|
var botKey = "git.aiterp.net/rpdata/logbot.Bot.key"
|
||||||
@@ -34,6 +33,8 @@ func New(ctx context.Context, nick string, alternatives []string, user string, r
|
|||||||
SkipSSLVerification: false,
|
SkipSSLVerification: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
client.AddHandler(handler)
|
||||||
|
|
||||||
bot := &Bot{
|
bot := &Bot{
|
||||||
client: client,
|
client: client,
|
||||||
channels: make(map[string]*Channel),
|
channels: make(map[string]*Channel),
|
||||||
@@ -52,6 +53,8 @@ func (bot *Bot) Connect(server string, ssl bool, maxRetries int) (err error) {
|
|||||||
}
|
}
|
||||||
bot.ctx, bot.ctxCancel = context.WithCancel(bot.client.Context())
|
bot.ctx, bot.ctxCancel = context.WithCancel(bot.client.Context())
|
||||||
|
|
||||||
|
bot.channels = make(map[string]*Channel)
|
||||||
|
|
||||||
retries := 0
|
retries := 0
|
||||||
for maxRetries == 0 || retries < maxRetries {
|
for maxRetries == 0 || retries < maxRetries {
|
||||||
err = bot.client.Connect(server, ssl)
|
err = bot.client.Connect(server, ssl)
|
||||||
@@ -74,6 +77,10 @@ func (bot *Bot) Connect(server string, ssl bool, maxRetries int) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bot *Bot) ClientState() irc.ClientState {
|
||||||
|
return bot.client.State()
|
||||||
|
}
|
||||||
|
|
||||||
func (bot *Bot) addChannel(channelName string) *Channel {
|
func (bot *Bot) addChannel(channelName string) *Channel {
|
||||||
if bot.channels[channelName] != nil {
|
if bot.channels[channelName] != nil {
|
||||||
return bot.channels[channelName]
|
return bot.channels[channelName]
|
||||||
@@ -112,54 +119,48 @@ func (bot *Bot) runCommands(commands []string, target irc.Target, replacers map[
|
|||||||
func (bot *Bot) loop() {
|
func (bot *Bot) loop() {
|
||||||
bot.loopCtx, bot.loopCancel = context.WithCancel(bot.ctx)
|
bot.loopCtx, bot.loopCancel = context.WithCancel(bot.ctx)
|
||||||
|
|
||||||
channelChanges, err := channels.SubscribeLogged(bot.ctx)
|
ticker := time.NewTicker(time.Second * 10)
|
||||||
if err != nil {
|
defer ticker.Stop()
|
||||||
log.Println("Failed to get channel changes:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case channel := <-channelChanges:
|
case <-ticker.C:
|
||||||
{
|
{
|
||||||
channels := []models.Channel{channel}
|
loggedChannels, err := channels.ListLogged(bot.ctx)
|
||||||
deadline := time.After(time.Second * 1)
|
if err != nil {
|
||||||
buffering := true
|
log.Println("Failed to list logged channels:", err)
|
||||||
for buffering {
|
continue
|
||||||
select {
|
}
|
||||||
case channel := <-channelChanges:
|
loggedMap := make(map[string]bool)
|
||||||
channels = append(channels, channel)
|
for _, channel := range loggedChannels {
|
||||||
case <-deadline:
|
loggedMap[channel.Name] = true
|
||||||
buffering = false
|
}
|
||||||
|
clientMap := make(map[string]bool)
|
||||||
|
for _, channel := range bot.client.Channels() {
|
||||||
|
clientMap[channel.Name()] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
joins := make([]string, 0, len(loggedMap))
|
||||||
|
parts := make([]string, 0, len(clientMap))
|
||||||
|
for key := range loggedMap {
|
||||||
|
if !clientMap[key] {
|
||||||
|
joins = append(joins, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for key := range clientMap {
|
||||||
|
if !loggedMap[key] {
|
||||||
|
parts = append(parts, key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
decisions := make(map[string]bool)
|
|
||||||
for _, channel := range channels {
|
|
||||||
decisions[channel.Name] = channel.Logged
|
|
||||||
}
|
|
||||||
joins := make([]string, 0, len(decisions))
|
|
||||||
parts := make([]string, 0, len(decisions))
|
|
||||||
for channelName, logged := range decisions {
|
|
||||||
if logged {
|
|
||||||
if bot.client.Channel(channelName) != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
joins = append(joins, channelName)
|
|
||||||
} else {
|
|
||||||
if bot.client.Channel(channelName) == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
parts = append(parts, channelName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(joins) > 0 {
|
|
||||||
bot.client.Join(joins...)
|
|
||||||
}
|
|
||||||
if len(parts) > 0 {
|
if len(parts) > 0 {
|
||||||
|
log.Println("Leaving", strings.Join(parts, ", "))
|
||||||
bot.client.Part(parts...)
|
bot.client.Part(parts...)
|
||||||
}
|
}
|
||||||
|
if len(joins) > 0 {
|
||||||
|
log.Println("Joining", strings.Join(joins, ", "))
|
||||||
|
bot.client.Join(joins...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case <-bot.loopCtx.Done():
|
case <-bot.loopCtx.Done():
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.aiterp.net/gisle/irc"
|
"github.com/gissleh/irc"
|
||||||
"git.aiterp.net/rpdata/logbot3/internal/config"
|
"git.aiterp.net/rpdata/logbot3/internal/config"
|
||||||
"git.aiterp.net/rpdata/logbot3/internal/models/channels"
|
"git.aiterp.net/rpdata/logbot3/internal/models/channels"
|
||||||
"git.aiterp.net/rpdata/logbot3/internal/models/logs"
|
"git.aiterp.net/rpdata/logbot3/internal/models/logs"
|
||||||
@@ -29,7 +29,7 @@ type Channel struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newChannel(parent *Bot, name string, client *irc.Client) *Channel {
|
func newChannel(parent *Bot, name string, client *irc.Client) *Channel {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(parent.ctx)
|
||||||
|
|
||||||
return &Channel{
|
return &Channel{
|
||||||
name: name,
|
name: name,
|
||||||
@@ -132,7 +132,7 @@ func (channel *Channel) loop() {
|
|||||||
if target != nil {
|
if target != nil {
|
||||||
me, ok := target.UserList().User(channel.client.Nick())
|
me, ok := target.UserList().User(channel.client.Nick())
|
||||||
if !ok || !strings.ContainsRune(me.Modes, 'o') {
|
if !ok || !strings.ContainsRune(me.Modes, 'o') {
|
||||||
channel.client.Say(channel.name, "This unit require operator privileges to serve this request.")
|
channel.client.Say(channel.name, "This unit has insufficient privileges.")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,7 +266,7 @@ func (channel *Channel) loop() {
|
|||||||
channel.lastPostSessionID = ""
|
channel.lastPostSessionID = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
case <-channel.parentCtx.Done():
|
case <-channel.ctx.Done():
|
||||||
{
|
{
|
||||||
// Time to pack up shop.
|
// Time to pack up shop.
|
||||||
return
|
return
|
||||||
|
|||||||
+17
-7
@@ -5,10 +5,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.aiterp.net/rpdata/logbot3/internal/util"
|
"github.com/gissleh/irc"
|
||||||
|
|
||||||
"git.aiterp.net/gisle/irc"
|
|
||||||
"git.aiterp.net/rpdata/logbot3/internal/config"
|
"git.aiterp.net/rpdata/logbot3/internal/config"
|
||||||
|
"git.aiterp.net/rpdata/logbot3/internal/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func handler(event *irc.Event, client *irc.Client) {
|
func handler(event *irc.Event, client *irc.Client) {
|
||||||
@@ -32,7 +31,17 @@ func handler(event *irc.Event, client *irc.Client) {
|
|||||||
bot.stopLoop()
|
bot.stopLoop()
|
||||||
|
|
||||||
conf := config.Get().Server
|
conf := config.Get().Server
|
||||||
go bot.Connect(conf.Address, conf.SSL, 0)
|
go bot.Connect(conf.Address, conf.SSL, 100)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log Connections
|
||||||
|
case "client.connecting":
|
||||||
|
{
|
||||||
|
log.Println("Client is connecting...")
|
||||||
|
}
|
||||||
|
case "client.connect":
|
||||||
|
{
|
||||||
|
log.Println("Client connected!")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log joins and leaves
|
// Log joins and leaves
|
||||||
@@ -134,12 +143,13 @@ func handler(event *irc.Event, client *irc.Client) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if event.Kind() == "error" {
|
||||||
|
log.Printf("Client Error (%s) %s\n", event.Verb(), event.Text)
|
||||||
|
}
|
||||||
|
|
||||||
// Always log error numerics.
|
// Always log error numerics.
|
||||||
if len(event.Verb()) == 3 && event.Verb()[0] == '4' || event.Verb()[0] == '9' {
|
if len(event.Verb()) == 3 && event.Verb()[0] == '4' || event.Verb()[0] == '9' {
|
||||||
log.Printf("(%s) %s %s\n", event.Verb(), strings.Join(event.Args, " "), event.Text)
|
log.Printf("(%s) %s %s\n", event.Verb(), strings.Join(event.Args, " "), event.Text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
|
||||||
irc.Handle(handler)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -14,10 +14,14 @@ type Config struct {
|
|||||||
User string `json:"user"`
|
User string `json:"user"`
|
||||||
RealName string `json:"realName"`
|
RealName string `json:"realName"`
|
||||||
} `json:"bot"`
|
} `json:"bot"`
|
||||||
|
Debug struct {
|
||||||
|
Enabled bool `json:"enabled"`
|
||||||
|
Listen string `json:"listen"`
|
||||||
|
} `json:"debug"`
|
||||||
Server struct {
|
Server struct {
|
||||||
Address string `json:"server"`
|
Address string `json:"server"`
|
||||||
SSL bool `json:"ssl"`
|
SSL bool `json:"ssl"`
|
||||||
}
|
} `json:"server"`
|
||||||
API struct {
|
API struct {
|
||||||
Endpoint string `json:"endpoint"`
|
Endpoint string `json:"endpoint"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
@@ -32,7 +36,7 @@ type Config struct {
|
|||||||
} `json:"commands"`
|
} `json:"commands"`
|
||||||
Names struct {
|
Names struct {
|
||||||
ChanServ string `json:"chanserv"`
|
ChanServ string `json:"chanserv"`
|
||||||
}
|
} `json:"names"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var mutex sync.Mutex
|
var mutex sync.Mutex
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"log"
|
"log"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -10,7 +12,6 @@ import (
|
|||||||
|
|
||||||
"git.aiterp.net/rpdata/logbot3/internal/bot"
|
"git.aiterp.net/rpdata/logbot3/internal/bot"
|
||||||
"git.aiterp.net/rpdata/logbot3/internal/config"
|
"git.aiterp.net/rpdata/logbot3/internal/config"
|
||||||
|
|
||||||
"git.aiterp.net/rpdata/logbot3/internal/models/users"
|
"git.aiterp.net/rpdata/logbot3/internal/models/users"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -32,6 +33,23 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if conf.Debug.Enabled {
|
||||||
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
|
mux.HandleFunc("/state", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(200)
|
||||||
|
_ = json.NewEncoder(w).Encode(bot.ClientState())
|
||||||
|
})
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
err := http.ListenAndServe(conf.Debug.Listen, mux)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Failed to setup debug listener", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
// Listen for a quit signal.
|
// Listen for a quit signal.
|
||||||
interrupt := make(chan os.Signal, 1)
|
interrupt := make(chan os.Signal, 1)
|
||||||
signal.Notify(interrupt, os.Interrupt)
|
signal.Notify(interrupt, os.Interrupt)
|
||||||
|
|||||||
Reference in New Issue
Block a user