+43
-10
main.go
+43
-10
main.go
···
14
14
"github.com/bluesky-social/indigo/api/atproto"
15
15
"github.com/bluesky-social/indigo/atproto/auth/oauth"
16
16
"github.com/bluesky-social/indigo/atproto/client"
17
+
"github.com/bluesky-social/indigo/atproto/identity"
18
+
"github.com/bluesky-social/indigo/atproto/syntax"
17
19
"github.com/bluesky-social/indigo/lex/util"
18
20
"github.com/teal-fm/piper/api/teal"
19
21
)
···
137
139
}
138
140
139
141
type envData struct {
140
-
ciderToken string
142
+
ciderToken string
143
+
appPassword string
144
+
handle string
141
145
}
142
146
143
147
func getEnvData() envData {
144
148
return envData{
145
-
ciderToken: os.Getenv("CIDER_TOKEN"),
149
+
ciderToken: os.Getenv("CIDER_TOKEN"),
150
+
appPassword: os.Getenv("APP_PASSWORD"),
151
+
handle: os.Getenv("HANDLE"),
146
152
}
147
153
}
148
154
···
152
158
}
153
159
}
154
160
161
+
func (e envData) HasAppPassword() bool {
162
+
return e.appPassword != ""
163
+
}
164
+
165
+
func (e envData) Login() *client.APIClient {
166
+
handle, err := syntax.ParseHandle(e.handle)
167
+
if err != nil {
168
+
panic(err)
169
+
}
170
+
171
+
ident := syntax.AtIdentifier{
172
+
Inner: handle,
173
+
}
174
+
c, err := client.LoginWithPassword(context.Background(), identity.DefaultDirectory(), ident, e.appPassword, "", nil)
175
+
if err != nil {
176
+
panic(err)
177
+
}
178
+
return c
179
+
}
180
+
155
181
func createPlay(client *client.APIClient, playRecord teal.AlphaFeedPlay) error {
156
182
entry := atproto.RepoCreateRecord_Input{
157
183
Collection: "fm.teal.alpha.feed.play",
···
168
194
return nil
169
195
}
170
196
197
+
func getClient() *client.APIClient {
198
+
if ENV_DATA.HasAppPassword() {
199
+
return ENV_DATA.Login()
200
+
} else {
201
+
authChan := make(chan *oauth.ClientSession)
202
+
go auth.StartServer(authChan)
203
+
session := <-authChan
204
+
if session == nil {
205
+
panic("Could not connect to ATProto")
206
+
}
207
+
return session.APIClient()
208
+
}
209
+
}
210
+
171
211
func main() {
172
212
ENV_DATA = getEnvData()
173
-
174
-
authChan := make(chan *oauth.ClientSession)
175
-
go auth.StartServer(authChan)
176
-
session := <-authChan
177
-
if session == nil {
178
-
panic("Could not connect to ATProto")
179
-
}
180
-
client := session.APIClient()
213
+
client := getClient()
181
214
182
215
// LOGIC
183
216
var lastPlaying string
+2
readme.md
+2
readme.md