+43
-10
main.go
+43
-10
main.go
···
14
"github.com/bluesky-social/indigo/api/atproto"
15
"github.com/bluesky-social/indigo/atproto/auth/oauth"
16
"github.com/bluesky-social/indigo/atproto/client"
17
"github.com/bluesky-social/indigo/lex/util"
18
"github.com/teal-fm/piper/api/teal"
19
)
···
137
}
138
139
type envData struct {
140
-
ciderToken string
141
}
142
143
func getEnvData() envData {
144
return envData{
145
-
ciderToken: os.Getenv("CIDER_TOKEN"),
146
}
147
}
148
···
152
}
153
}
154
155
func createPlay(client *client.APIClient, playRecord teal.AlphaFeedPlay) error {
156
entry := atproto.RepoCreateRecord_Input{
157
Collection: "fm.teal.alpha.feed.play",
···
168
return nil
169
}
170
171
func main() {
172
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()
181
182
// LOGIC
183
var lastPlaying string
···
14
"github.com/bluesky-social/indigo/api/atproto"
15
"github.com/bluesky-social/indigo/atproto/auth/oauth"
16
"github.com/bluesky-social/indigo/atproto/client"
17
+
"github.com/bluesky-social/indigo/atproto/identity"
18
+
"github.com/bluesky-social/indigo/atproto/syntax"
19
"github.com/bluesky-social/indigo/lex/util"
20
"github.com/teal-fm/piper/api/teal"
21
)
···
139
}
140
141
type envData struct {
142
+
ciderToken string
143
+
appPassword string
144
+
handle string
145
}
146
147
func getEnvData() envData {
148
return envData{
149
+
ciderToken: os.Getenv("CIDER_TOKEN"),
150
+
appPassword: os.Getenv("APP_PASSWORD"),
151
+
handle: os.Getenv("HANDLE"),
152
}
153
}
154
···
158
}
159
}
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
+
181
func createPlay(client *client.APIClient, playRecord teal.AlphaFeedPlay) error {
182
entry := atproto.RepoCreateRecord_Input{
183
Collection: "fm.teal.alpha.feed.play",
···
194
return nil
195
}
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
+
211
func main() {
212
ENV_DATA = getEnvData()
213
+
client := getClient()
214
215
// LOGIC
216
var lastPlaying string
+2
readme.md
+2
readme.md