|
@ -7,6 +7,7 @@ import ( |
|
|
"time" |
|
|
"time" |
|
|
|
|
|
|
|
|
"git.aiterp.net/gisle/irc" |
|
|
"git.aiterp.net/gisle/irc" |
|
|
|
|
|
"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" |
|
|
"git.aiterp.net/rpdata/logbot3/internal/models/posts" |
|
|
"git.aiterp.net/rpdata/logbot3/internal/models/posts" |
|
@ -23,15 +24,17 @@ type Channel struct { |
|
|
|
|
|
|
|
|
name string |
|
|
name string |
|
|
parentCtx context.Context |
|
|
parentCtx context.Context |
|
|
|
|
|
parent *Bot |
|
|
client *irc.Client |
|
|
client *irc.Client |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func newChannel(parentCtx context.Context, 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(context.Background()) |
|
|
|
|
|
|
|
|
return &Channel{ |
|
|
return &Channel{ |
|
|
name: name, |
|
|
name: name, |
|
|
parentCtx: parentCtx, |
|
|
|
|
|
|
|
|
parent: parent, |
|
|
|
|
|
parentCtx: parent.ctx, |
|
|
client: client, |
|
|
client: client, |
|
|
ch: make(chan ChannelPost, 8), |
|
|
ch: make(chan ChannelPost, 8), |
|
|
|
|
|
|
|
@ -47,6 +50,7 @@ func (channel *Channel) loop() { |
|
|
defer channel.cancel() |
|
|
defer channel.cancel() |
|
|
defer minutely.Stop() |
|
|
defer minutely.Stop() |
|
|
|
|
|
|
|
|
|
|
|
// In case of a crash, it should take ownership of sessions when rejoining.
|
|
|
session, err := logs.FindOpen(channel.parentCtx, channel.name) |
|
|
session, err := logs.FindOpen(channel.parentCtx, channel.name) |
|
|
if err == nil { |
|
|
if err == nil { |
|
|
minsUntilDeadline := 1 + int(((time.Hour * 2) - time.Since(session.LatestTime())).Minutes()) |
|
|
minsUntilDeadline := 1 + int(((time.Hour * 2) - time.Since(session.LatestTime())).Minutes()) |
|
@ -60,6 +64,23 @@ func (channel *Channel) loop() { |
|
|
channel.lastPostTime = session.LatestTime() |
|
|
channel.lastPostTime = session.LatestTime() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// If the bot is op, run the commands from the configuration.
|
|
|
|
|
|
go func() { |
|
|
|
|
|
time.Sleep(time.Second) |
|
|
|
|
|
|
|
|
|
|
|
commands := config.Get().Commands.OnJoinOp |
|
|
|
|
|
target := channel.client.Channel(channel.name) |
|
|
|
|
|
|
|
|
|
|
|
if len(commands) > 0 && target != nil { |
|
|
|
|
|
me, ok := target.UserList().User(channel.client.Nick()) |
|
|
|
|
|
if ok && strings.ContainsRune(me.Modes, 'o') { |
|
|
|
|
|
channel.parent.runCommands(commands, target, map[string]string{ |
|
|
|
|
|
"chan": channel.name, |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}() |
|
|
|
|
|
|
|
|
for { |
|
|
for { |
|
|
select { |
|
|
select { |
|
|
case post := <-channel.ch: |
|
|
case post := <-channel.ch: |
|
|