partial user account support, fix presences for user accounts

This commit is contained in:
Cynthia Foxwell 2023-07-16 20:36:46 -06:00
parent e3fc322980
commit 1a667b43d4
2 changed files with 28 additions and 10 deletions

View file

@ -19,18 +19,18 @@ type ActivityMetadata struct {
type Activity struct { type Activity struct {
Name string `json:"name"` Name string `json:"name"`
Type discordgo.ActivityType `json:"type"` Type discordgo.ActivityType `json:"type"`
URL string `json:"url,omitempty"` //URL string `json:"url,omitempty"`
CreatedAt time.Time `json:"created_at"` CreatedAt time.Time `json:"created_at"`
ApplicationID string `json:"application_id,omitempty"` ApplicationID string `json:"application_id,omitempty"`
State string `json:"state,omitempty"` State string `json:"state,omitempty"`
Details string `json:"details,omitempty"` Details string `json:"details,omitempty"`
Timestamps discordgo.TimeStamps `json:"timestamps,omitempty"` Timestamps discordgo.TimeStamps `json:"timestamps,omitempty"`
Emoji discordgo.Emoji `json:"emoji,omitempty"` //Emoji discordgo.Emoji `json:"emoji,omitempty"`
Party discordgo.Party `json:"party,omitempty"` //Party discordgo.Party `json:"party,omitempty"`
Assets discordgo.Assets `json:"assets,omitempty"` Assets discordgo.Assets `json:"assets,omitempty"`
Secrets discordgo.Secrets `json:"secrets,omitempty"` //Secrets discordgo.Secrets `json:"secrets,omitempty"`
Instance bool `json:"instance,omitempty"` //Instance bool `json:"instance,omitempty"`
Flags int `json:"flags,omitempty"` //Flags int `json:"flags,omitempty"`
Buttons []string `json:"buttons,omitempty"` Buttons []string `json:"buttons,omitempty"`
Metadata ActivityMetadata `json:"metadata,omitempty"` Metadata ActivityMetadata `json:"metadata,omitempty"`
} }
@ -53,6 +53,13 @@ func getUnexportedField(field reflect.Value) interface{} {
} }
func UpdatePresence(session *discordgo.Session) { func UpdatePresence(session *discordgo.Session) {
// there is a way to send presence without reflecting to grab the websocket
// connection, but theres an issue with the serialization that because a value
// isn't being considered "null" that its trying to apply and failing because
// the default doesn't make sense in this context, even if omitempty is set
//
// this doesnt happen with bot accounts because they have certain fields
// stripped
values := reflect.ValueOf(session) values := reflect.ValueOf(session)
fieldWsConn := reflect.Indirect(values).FieldByName("wsConn") fieldWsConn := reflect.Indirect(values).FieldByName("wsConn")
fieldWsMutex := reflect.Indirect(values).FieldByName("wsMutex") fieldWsMutex := reflect.Indirect(values).FieldByName("wsMutex")

19
main.go
View file

@ -63,8 +63,15 @@ func main() {
state.Setup(config) state.Setup(config)
commands.Setup() commands.Setup()
// TODO: user account support allowUserAccounts := config["allowUserAccounts"] == "true"
client, err := discordgo.New("Bot " + token) tokenPrefix := "Bot "
if allowUserAccounts {
tokenPrefix = ""
}
fullToken := tokenPrefix + token
client, err := discordgo.New(fullToken)
if err != nil { if err != nil {
fmt.Println("% Failed to create client:", err) fmt.Println("% Failed to create client:", err)
fmt.Print("\r") fmt.Print("\r")
@ -72,7 +79,8 @@ func main() {
return return
} }
// TODO: dont set for user accounts(? never really tested if it matters) //client.LogLevel = discordgo.LogDebug
client.Identify.Intents = discordgo.IntentsAll client.Identify.Intents = discordgo.IntentsAll
if config["useMobile"] == "true" { if config["useMobile"] == "true" {
@ -82,7 +90,8 @@ func main() {
Device: "Pixel, raven", Device: "Pixel, raven",
} }
} else { } else {
// TODO: user account support // TODO: figure out how tempermental X-Super-Properties is, as in if it
// allows arbitrary values or not
client.Identify.Properties = discordgo.IdentifyProperties{ client.Identify.Properties = discordgo.IdentifyProperties{
OS: runtime.GOOS, OS: runtime.GOOS,
Browser: "comcord", Browser: "comcord",
@ -96,11 +105,13 @@ func main() {
status = defaultStatus status = defaultStatus
} }
startTime := state.GetStartTime() startTime := state.GetStartTime()
client.Identify.Presence = discordgo.GatewayStatusUpdate{ client.Identify.Presence = discordgo.GatewayStatusUpdate{
Since: 0, Since: 0,
Status: status, Status: status,
AFK: false, AFK: false,
Game: discordgo.Activity{ Game: discordgo.Activity{
Type: 0,
Name: "comcord", Name: "comcord",
ApplicationID: "1026163285877325874", ApplicationID: "1026163285877325874",
CreatedAt: startTime, CreatedAt: startTime,