-
Notifications
You must be signed in to change notification settings - Fork 0
/
tweet.go
64 lines (57 loc) · 2.03 KB
/
tweet.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// Tweeter module
//
package main
import (
"fmt"
"math/rand"
"strconv"
"github.com/bwmarrin/discordgo"
)
// Pueudorandom numbers
func randInt(min, max int) int {
return min + rand.Intn(max-min)
}
func tweet(s *discordgo.Session, i *discordgo.InteractionCreate) {
// Check if it's the right command or enabled
if i.Data.Name != "tweet" || config.Modules.Tweet != true {
return
}
// Set default endpoints for data (no selected user and no nickname)
author := fmt.Sprintf("@%s", i.Member.User.Username)
avatar := discordgo.EndpointUserAvatar(i.Member.User.ID, i.Member.User.Avatar)
// Handle user selection and nicknames
if len(i.Data.Options) == 2 {
// If there is a selected user, set the author and avatar to the selected user instead of default
author = fmt.Sprintf("@%s", i.Data.Options[1].UserValue(s).Username)
avatar = discordgo.EndpointUserAvatar(i.Data.Options[1].UserValue(s).ID, i.Data.Options[1].UserValue(s).Avatar)
} else if i.Member.Nick != "" {
// If there is no selected user, at least check if the command author has a nickname
author = fmt.Sprintf("%s (@%s)", i.Member.Nick, i.Member.User.Username)
}
// Respond to command event with embed
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionApplicationCommandResponseData{
// One entry in the array of embeds... Why did they make this a fucking array?
Embeds: []*discordgo.MessageEmbed{
{
Author: &discordgo.MessageEmbedAuthor{
Name: author,
IconURL: avatar,
},
Color: 1942002,
Description: i.Data.Options[0].StringValue(),
Footer: &discordgo.MessageEmbedFooter{
Text: "Twitter",
IconURL: "https://abs.twimg.com/icons/apple-touch-icon-192x192.png",
},
Fields: []*discordgo.MessageEmbedField{
{Name: "Retweets", Value: strconv.Itoa(randInt(5000, 50000)), Inline: true},
{Name: "Likes", Value: strconv.Itoa(randInt(25000, 150000)), Inline: true},
},
},
},
},
})
}