Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Commit

Permalink
command(token): send token to user channel
Browse files Browse the repository at this point in the history
  • Loading branch information
sarisia committed Sep 30, 2020
1 parent 749930f commit ca0cea0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
24 changes: 21 additions & 3 deletions aria/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,16 +353,34 @@ func (b *bot) deleteMessageAfter(m *discordgo.Message, t time.Duration, force bo
}
}

func (b *bot) deleteAfterChannelMessageSend(
d time.Duration,
ignoreKeepMsgChannel bool,
channelID string,
content string,
) (*discordgo.Message, error) {
m, err := b.ChannelMessageSend(channelID, content)
if err != nil {
return nil, err
}

go b.deleteMessageAfter(m, d, ignoreKeepMsgChannel)
return m, nil
}

// send MessageEmbed to channel then delete message after d
// Returns Message and error immidiately after message is sent
func (b *bot) deleteAfterChannelMessageSendEmbed(
d time.Duration, force bool,
channelID string, embed *discordgo.MessageEmbed,
d time.Duration,
ignoreKeepMsgChannel bool,
channelID string,
embed *discordgo.MessageEmbed,
) (*discordgo.Message, error) {
m, err := b.ChannelMessageSendEmbed(channelID, embed)
if err != nil {
return nil, err
}
go b.deleteMessageAfter(m, d, force)

go b.deleteMessageAfter(m, d, ignoreKeepMsgChannel)
return m, nil
}
2 changes: 1 addition & 1 deletion aria/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ func (b *bot) cmdInvite(m *discordgo.Message, _ []string) {
func (b *bot) cmdToken(m *discordgo.Message, _ []string) {
b.sendAriaRequest(&request{
OP: "token",
Postback: m.ChannelID,
Postback: m.Author.ID,
})
}

Expand Down
23 changes: 16 additions & 7 deletions aria/packets.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func onInvite(b *bot, pb string, d *inviteData) {
uc, err := b.UserChannelCreate(pb)
if err != nil {
log.Printf("failed to create user channel: %v", err)
return
}

e := newEmbed()
Expand All @@ -133,15 +134,23 @@ func onToken(b *bot, pb string, d *tokenData) {
return
}

e := newEmbed()
e.Color = 0x57ffae
e.Title = "New token"
e.Description = fmt.Sprintf("Your token is:\n`%s`", d.Token)

if _, err := b.deleteAfterChannelMessageSendEmbed(msgTimeout, true, pb, e); err != nil {
log.Printf("failed to send token embed: %v\n", err)
uc, err := b.UserChannelCreate(pb)
if err != nil {
log.Printf("failed to create user channel: %v", err)
return
}

contents := []string{
"Your new token is:",
d.Token,
}

for _, content := range contents {
if _, err := b.deleteAfterChannelMessageSend(msgTimeout, true, uc.ID, content); err != nil {
log.Printf("failed to send token embed: %v\n", err)
return
}
}
}

func onStateEvent(b *bot, pb string, ed *stateEventData) {
Expand Down

0 comments on commit ca0cea0

Please sign in to comment.