Skip to content

Commit

Permalink
Merge pull request #126 from lazybytez/feature/no-ping-handlers
Browse files Browse the repository at this point in the history
Update ping module to be less disturbing
  • Loading branch information
pascal-zarrad authored Dec 19, 2022
2 parents 3844752 + 93f3766 commit 2ec506f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 42 deletions.
2 changes: 2 additions & 0 deletions components/pingpong/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func handlePing(s *discordgo.Session, i *discordgo.InteractionCreate) {
_ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Flags: discordgo.MessageFlagsEphemeral,
Content: "Pong!",
},
})
Expand All @@ -52,6 +53,7 @@ func handlePong(s *discordgo.Session, i *discordgo.InteractionCreate) {
_ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Flags: discordgo.MessageFlagsEphemeral,
Content: "Ping!",
},
})
Expand Down
42 changes: 0 additions & 42 deletions components/pingpong/pingpong.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,50 +52,8 @@ func init() {

// LoadComponent loads the Ping-Pong Component
func LoadComponent(_ *discordgo.Session) error {
// Register the messageCreate func as a callback for MessageCreate events.
_, _ = C.HandlerManager().Register("ping", onPingMessageCreate)
_, _ = C.HandlerManager().Register("pong", onPongMessageCreate)

_ = C.SlashCommandManager().Register(pingCommand)
_ = C.SlashCommandManager().Register(pongCommand)

return nil
}

// onPingMessageCreate listens for new messages and replies with
// "Pong!".
func onPingMessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.ID == s.State.User.ID || m.Author.Bot {
return
}

if m.Content != "ping" {
return
}

_, err := s.ChannelMessageSend(m.ChannelID, "Pong!")
if nil != err {
C.Logger().Warn("Failed to deliver \"Pong!\" message: %v", err.Error())

return
}
}

// onPingMessageCreate listens for new messages and replies with
// "Ping!".
func onPongMessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.ID == s.State.User.ID || m.Author.Bot {
return
}

if m.Content != "pong" {
return
}

_, err := s.ChannelMessageSend(m.ChannelID, "Ping!")
if nil != err {
C.Logger().Warn("Failed to deliver \"Ping!\" message: %v", err.Error())

return
}
}

0 comments on commit 2ec506f

Please sign in to comment.