Skip to content

Commit

Permalink
Merge pull request #9 from altid/server/libs
Browse files Browse the repository at this point in the history
Server/libs
  • Loading branch information
halfwit authored May 18, 2023
2 parents 0e9ce6b + b8ee765 commit 502c508
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/altid/discordfs
go 1.19

require (
github.com/altid/libs v0.2.6
github.com/altid/libs v0.2.8
github.com/bwmarrin/discordgo v0.27.1
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
9fans.net/go v0.0.4/go.mod h1:lfPdxjq9v8pVQXUMBCx5EO5oLXWQFlKRQgs1kEkjoIM=
aqwari.net/retry v0.0.0-20180428204214-1281ce5d8df0 h1:BeD6U5TNwhMWxeydyi5xqpaNZx1MWl5QTcW4w7Mxf+Y=
aqwari.net/retry v0.0.0-20180428204214-1281ce5d8df0/go.mod h1:XSNyyoM+OSg3vRmROPrS1lEpV7q/I9J1HAKMMxdUkU4=
github.com/altid/libs v0.2.6 h1:x3jVhOB9EIJ0vM6WDK60U3xUqRMESERXnvG1MrNGHoY=
github.com/altid/libs v0.2.6/go.mod h1:zkLLaoU8rklnPoGTmFLzslnEK9dx6/DEc05jwDePejU=
github.com/altid/libs v0.2.8 h1:DekDpcBbc1qncRSMt8qcuRzUnzHW/BQfmtGgBS8zYN8=
github.com/altid/libs v0.2.8/go.mod h1:s9iFMxwmCWbHz0kks4L5F2fFV42n5pQ0NV9sBXS3GZg=
github.com/bwmarrin/discordgo v0.27.1 h1:ib9AIc/dom1E/fSIulrBwnez0CToJE113ZGt4HoliGY=
github.com/bwmarrin/discordgo v0.27.1/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
Expand Down
21 changes: 10 additions & 11 deletions internal/session/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ func (s *Session) msgCreate(ds *discordgo.Session, event *discordgo.MessageCreat
}

s.debug(ctlSucceed, "msg Callback")
// TODO: We could look for this in the recipients
name := c.Name

g, err := ds.State.Guild(event.GuildID)
if err == nil {
name = fmt.Sprintf("%s-%s", g.Name, c.Name)
Expand Down Expand Up @@ -77,16 +79,9 @@ func (s *Session) chanCreate(ds *discordgo.Session, event *discordgo.ChannelCrea
return
}
name = fmt.Sprintf("%s-%s", g.Name, event.Name)
case discordgo.ChannelTypeDM:
name = event.Name
case discordgo.ChannelTypeGroupDM:
// For now, grab the last message and get the channel name from that
m, err := ds.State.Message(event.LastMessageID, event.ID)
if err != nil {
s.debug(ctlErr, err)
return
}
c, _ := ds.State.Channel(m.ChannelID)
case discordgo.ChannelTypeDM, discordgo.ChannelTypeGroupDM:
// Use the state just in case
c, _ := s.Client.State.Channel(event.Channel.ID)
name = c.Name
case discordgo.ChannelTypeGuildVoice:
return
Expand All @@ -95,11 +90,15 @@ func (s *Session) chanCreate(ds *discordgo.Session, event *discordgo.ChannelCrea
s.debug(ctlErr, e)
return
}
if tw, err := s.ctrl.TitleWriter(name); err == nil {
fmt.Fprintf(tw, "%s\n", event.Channel.Topic)
}

s.debug(ctlSucceed, "creating buffer", name)
}

func (s *Session) chanUpdate(ds *discordgo.Session, event *discordgo.ChannelUpdate) {
//
// We have members here, etc
}

func (s *Session) chanDelete(ds *discordgo.Session, event *discordgo.ChannelDelete) {
Expand Down
4 changes: 4 additions & 0 deletions internal/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func (s *Session) Start(c controller.Controller) error {
client.AddHandler(s.chanCreate)
client.AddHandler(s.chanUpdate)
client.AddHandler(s.chanDelete)
client.AddHandler(s.guildDelete)
client.AddHandler(s.guildUpdate)
client.AddHandler(s.guildMemNew)
client.AddHandler(s.guildMemBye)
Expand All @@ -122,6 +123,9 @@ func (s *Session) Start(c controller.Controller) error {
if room.Type == discordgo.ChannelTypeGuildText {
name := fmt.Sprintf("%s-%s", guild.Name, room.Name)
s.ctrl.CreateBuffer(name)
if tw, e := s.ctrl.TitleWriter(name); e == nil {
fmt.Fprintf(tw, "%s\n", room.Topic)
}
}
}
}
Expand Down

0 comments on commit 502c508

Please sign in to comment.