partial user account support, fix presences for user accounts
This commit is contained in:
		
							parent
							
								
									e3fc322980
								
							
						
					
					
						commit
						1a667b43d4
					
				
					 2 changed files with 28 additions and 10 deletions
				
			
		| 
						 | 
				
			
			@ -19,18 +19,18 @@ type ActivityMetadata struct {
 | 
			
		|||
type Activity struct {
 | 
			
		||||
  Name          string                 `json:"name"`
 | 
			
		||||
	Type          discordgo.ActivityType `json:"type"`
 | 
			
		||||
	URL           string                 `json:"url,omitempty"`
 | 
			
		||||
	//URL           string                 `json:"url,omitempty"`
 | 
			
		||||
	CreatedAt     time.Time              `json:"created_at"`
 | 
			
		||||
	ApplicationID string                 `json:"application_id,omitempty"`
 | 
			
		||||
	State         string                 `json:"state,omitempty"`
 | 
			
		||||
	Details       string                 `json:"details,omitempty"`
 | 
			
		||||
	Timestamps    discordgo.TimeStamps   `json:"timestamps,omitempty"`
 | 
			
		||||
	Emoji         discordgo.Emoji        `json:"emoji,omitempty"`
 | 
			
		||||
	Party         discordgo.Party        `json:"party,omitempty"`
 | 
			
		||||
	//Emoji         discordgo.Emoji        `json:"emoji,omitempty"`
 | 
			
		||||
	//Party         discordgo.Party        `json:"party,omitempty"`
 | 
			
		||||
	Assets        discordgo.Assets       `json:"assets,omitempty"`
 | 
			
		||||
	Secrets       discordgo.Secrets      `json:"secrets,omitempty"`
 | 
			
		||||
	Instance      bool                   `json:"instance,omitempty"`
 | 
			
		||||
	Flags         int                    `json:"flags,omitempty"`
 | 
			
		||||
	//Secrets       discordgo.Secrets      `json:"secrets,omitempty"`
 | 
			
		||||
	//Instance      bool                   `json:"instance,omitempty"`
 | 
			
		||||
	//Flags         int                    `json:"flags,omitempty"`
 | 
			
		||||
  Buttons       []string               `json:"buttons,omitempty"`
 | 
			
		||||
  Metadata      ActivityMetadata       `json:"metadata,omitempty"`
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -53,6 +53,13 @@ func getUnexportedField(field reflect.Value) interface{} {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
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)
 | 
			
		||||
  fieldWsConn := reflect.Indirect(values).FieldByName("wsConn")
 | 
			
		||||
  fieldWsMutex := reflect.Indirect(values).FieldByName("wsMutex")
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										19
									
								
								main.go
									
										
									
									
									
								
							
							
						
						
									
										19
									
								
								main.go
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -63,8 +63,15 @@ func main() {
 | 
			
		|||
  state.Setup(config)
 | 
			
		||||
  commands.Setup()
 | 
			
		||||
 | 
			
		||||
  // TODO: user account support
 | 
			
		||||
  client, err := discordgo.New("Bot " + token)
 | 
			
		||||
  allowUserAccounts := config["allowUserAccounts"] == "true"
 | 
			
		||||
  tokenPrefix := "Bot "
 | 
			
		||||
  if allowUserAccounts {
 | 
			
		||||
    tokenPrefix = ""
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  fullToken := tokenPrefix + token
 | 
			
		||||
 | 
			
		||||
  client, err := discordgo.New(fullToken)
 | 
			
		||||
  if err != nil {
 | 
			
		||||
    fmt.Println("% Failed to create client:", err)
 | 
			
		||||
    fmt.Print("\r")
 | 
			
		||||
| 
						 | 
				
			
			@ -72,7 +79,8 @@ func main() {
 | 
			
		|||
    return
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // TODO: dont set for user accounts(? never really tested if it matters)
 | 
			
		||||
  //client.LogLevel = discordgo.LogDebug
 | 
			
		||||
 | 
			
		||||
  client.Identify.Intents = discordgo.IntentsAll
 | 
			
		||||
 | 
			
		||||
  if config["useMobile"] == "true" {
 | 
			
		||||
| 
						 | 
				
			
			@ -82,7 +90,8 @@ func main() {
 | 
			
		|||
      Device: "Pixel, raven",
 | 
			
		||||
    }
 | 
			
		||||
  } 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{
 | 
			
		||||
      OS: runtime.GOOS,
 | 
			
		||||
      Browser: "comcord",
 | 
			
		||||
| 
						 | 
				
			
			@ -96,11 +105,13 @@ func main() {
 | 
			
		|||
    status = defaultStatus
 | 
			
		||||
  }
 | 
			
		||||
  startTime := state.GetStartTime()
 | 
			
		||||
 | 
			
		||||
  client.Identify.Presence = discordgo.GatewayStatusUpdate{
 | 
			
		||||
    Since: 0,
 | 
			
		||||
    Status: status,
 | 
			
		||||
    AFK: false,
 | 
			
		||||
    Game: discordgo.Activity{
 | 
			
		||||
      Type: 0,
 | 
			
		||||
      Name: "comcord",
 | 
			
		||||
      ApplicationID: "1026163285877325874",
 | 
			
		||||
      CreatedAt: startTime,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue