-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
588 lines (485 loc) · 13.3 KB
/
types.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
package main
import (
"github.com/dofusdude/dodugo"
"github.com/google/uuid"
"github.com/mmcdole/gofeed"
"time"
)
const (
TwitterWebhookType string = "twitter"
RSSWebhookType = "rss"
AlmanaxWebhookType = "almanax"
)
type RssState struct {
LastHash uint64
}
type RssSend struct {
Item gofeed.Item
Webhooks []IHook
Feed IFeed
}
type TwitterState struct {
LastCheck time.Time
}
type TwitterSend struct {
Tweet Tweet
Webhooks []IHook
}
type PreparedHook struct {
Callback string
Body string
}
type SendCallbackReturn struct {
Callback string
Ok bool
}
type AlmanaxSend struct {
Feed AlmanaxFeed
BuildInfo AlmanaxHookBuildInfo
Webhooks []IHook
OnlyPreMentions []bool
IntervalType []string
TickTime time.Time
}
type ApiUserTweetResult struct {
Data []ApiUserTweet `json:"data"`
Includes ApiUserTweetIncludes `json:"includes"`
Meta ApiUserTweetMeta `json:"meta"`
}
type ApiUserTweetMeta struct {
ResultCount int `json:"result_count"`
}
type ApiUser struct {
Id string `json:"id"`
Name string `json:"name"`
Username string `json:"username"`
ProfileImageURL string `json:"profile_image_url"`
}
type ApiUserTweetMedia struct {
Type string `json:"type"`
Url string `json:"url"`
MediaKey string `json:"media_key"`
}
type ApiUserTweetIncludes struct {
Media []ApiUserTweetMedia `json:"media"`
Users []ApiUser `json:"users"`
}
type TweetAttachments struct {
MediaKeys []string `json:"media_keys"`
}
type ApiUserTweet struct {
AuthorId string `json:"author_id"`
Id string `json:"id"`
Text string `json:"text"`
CreatedAt time.Time `json:"created_at"`
Attachments TweetAttachments `json:"attachments"`
InReplyTo *string `json:"in_reply_to_user_id"`
}
type Tweet struct {
Author ApiUser `json:"author"`
Text string `json:"text"`
CreatedAt time.Time `json:"created_at"`
Attachments []string `json:"attachments"`
IsNew bool `json:"is_new"`
}
type DiscordImage struct {
Url string `json:"url"`
}
type DiscordEmbedField struct {
Name string `json:"name"`
Value string `json:"value"`
Inline bool `json:"inline"`
}
type DiscordEmbed struct {
Title *string `json:"title"`
Color int `json:"color"`
Image *DiscordImage `json:"image"`
Thumbnail *DiscordImage `json:"thumbnail"`
Fields []DiscordEmbedField `json:"fields"`
Url *string `json:"url"`
Description *string `json:"description"`
}
type DiscordWebhook struct {
Content *string `json:"content"`
Embeds []DiscordEmbed `json:"embeds"`
Username string `json:"username"`
AvatarUrl string `json:"avatar_url"`
Attachments []string `json:"attachments"`
}
type SocialWebhookPut struct {
Whitelist []string `json:"whitelist"`
Blacklist []string `json:"blacklist"`
Subscriptions []string `json:"subscriptions"`
PreviewLength *int `json:"preview_length"`
}
type WebhookJobs struct {
Jobs []WebhookJob `json:"jobs"`
}
type WebhookJob struct {
Url string `json:"url"`
Body string `json:"json_body"`
}
type HookMeta struct {
Subscriptions []string `json:"subscriptions"`
}
type DailySettings struct {
Timezone string `json:"timezone"`
MidnightOffset int `json:"midnight_offset"`
}
type AlmanaxHookDTO struct {
Id uuid.UUID `json:"id"`
DailySettings DailySettings `json:"daily_settings"`
LastFiredAt *time.Time `json:"last_fired_at"`
Subscriptions []Subscription `json:"subscriptions"`
BonusWhitelist []string `json:"bonus_whitelist"`
BonusBlacklist []string `json:"bonus_blacklist"`
Format string `json:"format"`
WantsIsoDate bool `json:"iso_date"`
Intervals []string `json:"intervals"`
WeeklyWeekday *string `json:"weekly_weekday"`
Mentions *map[string][]MentionDTO `json:"mentions"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type AlmanaxHookPost struct {
BonusWhitelist []string `json:"bonus_whitelist"`
BonusBlacklist []string `json:"bonus_blacklist"`
DailySettings *WebhookDailySettings `json:"daily_settings"`
Callback string `json:"callback"`
Subscriptions []string `json:"subscriptions"`
WantsIsoDate *bool `json:"iso_date"`
Format string `json:"format"`
Mentions *map[string][]MentionDTO `json:"mentions"`
Intervals []string `json:"intervals"`
WeeklyWeekday *string `json:"weekly_weekday"`
}
type AlmanaxHookBuildInfo struct {
almData map[string]dodugo.AlmanaxEntry
translations map[string]map[string]string
}
type IFeed interface {
GetId() uint64
GetTwitterId() uint64
GetRSSUrl() string
GetAlmanaxFeed() string
GetType() string
GetFeedName() string
}
type IHook interface {
GetId() uuid.UUID
GetCallback() string
GetPreviewLength() int
IsWantIsoDate() bool
GetTimezone() string
GetMentions() *map[string][]MentionDTO
}
type HasIdBlackWhiteList[T any] interface {
IHook
GetBlacklist() []T
GetWhitelist() []T
GetType() string
}
type TwitterFeed struct {
Id uint64
TwitterId uint64
IsOfficial bool
HumanReadableId string
CreatedAt time.Time
}
func (f TwitterFeed) GetId() uint64 {
return f.Id
}
func (f TwitterFeed) GetTwitterId() uint64 {
return f.TwitterId
}
func (f TwitterFeed) GetRSSUrl() string {
return ""
}
func (f TwitterFeed) GetAlmanaxFeed() string {
return ""
}
func (f TwitterFeed) GetType() string {
return TwitterWebhookType
}
func (f TwitterFeed) GetFeedName() string {
return f.HumanReadableId
}
type RssFeed struct {
Id uint64
Url string
ApiReadableId string
IsOfficial bool
CreatedAt time.Time
}
func (f RssFeed) GetId() uint64 {
return f.Id
}
func (f RssFeed) GetTwitterId() uint64 {
return 0
}
func (f RssFeed) GetRSSUrl() string {
return f.Url
}
func (f RssFeed) GetAlmanaxFeed() string {
return ""
}
func (f RssFeed) GetType() string {
return RSSWebhookType
}
func (f RssFeed) GetFeedName() string {
return f.ApiReadableId
}
type AlmanaxFeed struct {
Id uint64
HumanReadableId string
Language string
CreatedAt time.Time
}
func (f AlmanaxFeed) GetId() uint64 {
return f.Id
}
func (f AlmanaxFeed) GetTwitterId() uint64 {
return 0
}
func (f AlmanaxFeed) GetRSSUrl() string {
return ""
}
func (f AlmanaxFeed) GetFeedName() string {
return f.HumanReadableId
}
func (f AlmanaxFeed) GetAlmanaxFeed() string {
return f.HumanReadableId
}
func (f AlmanaxFeed) GetType() string {
return AlmanaxWebhookType
}
type Subscription struct {
Id string `json:"id"`
}
type WebhookDailySettings struct {
Timezone *string `json:"timezone"`
MidnightOffset *int `json:"midnight_offset"`
}
type AlmanaxWebhook struct {
Id uuid.UUID
DailySettings WebhookDailySettings
BonusBlacklist []string
BonusWhitelist []string
Subscriptions []Subscription
Callback string
Format string
WantsIsoDate bool
Mentions *map[string][]MentionDTO
Intervals []string
WeeklyWeekday *string
LastFiredAt *time.Time
CreatedAt time.Time
UpdatedAt time.Time
}
func (a AlmanaxWebhook) GetMentions() *map[string][]MentionDTO {
return a.Mentions
}
func (a AlmanaxWebhook) GetTimezone() string {
if a.DailySettings.Timezone == nil {
return ""
}
return *a.DailySettings.Timezone
}
func (a AlmanaxWebhook) GetId() uuid.UUID {
return a.Id
}
func (a AlmanaxWebhook) GetCallback() string {
return a.Callback
}
func (a AlmanaxWebhook) GetPreviewLength() int {
return 0
}
func (a AlmanaxWebhook) IsWantIsoDate() bool {
return a.WantsIsoDate
}
type TwitterWebhook struct {
Id uuid.UUID `json:"id"`
Callback string `json:"-"`
Whitelist []string `json:"bonus_whitelist"`
Blacklist []string `json:"bonus_blacklist"`
Format string `json:"format"`
LastFiredAt *time.Time `json:"last_fired_at"`
PreviewLength int `json:"preview_length"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (s TwitterWebhook) GetLastFiredAt() *time.Time {
return s.LastFiredAt
}
func (s TwitterWebhook) GetCreatedAt() time.Time {
return s.CreatedAt
}
func (s TwitterWebhook) GetUpdatedAt() time.Time {
return s.UpdatedAt
}
func (s TwitterWebhook) GetFormat() string {
return s.Format
}
func (s TwitterWebhook) GetMentions() *map[string][]MentionDTO {
return nil
}
func (s TwitterWebhook) GetTimezone() string {
return ServerTz
}
func (s TwitterWebhook) GetBlacklist() []string {
return s.Blacklist
}
func (s TwitterWebhook) GetWhitelist() []string {
return s.Whitelist
}
func (s TwitterWebhook) GetId() uuid.UUID {
return s.Id
}
func (s TwitterWebhook) GetType() string {
return TwitterWebhookType
}
func (s TwitterWebhook) GetCallback() string {
return s.Callback
}
func (s TwitterWebhook) GetPreviewLength() int {
return s.PreviewLength
}
func (s TwitterWebhook) IsWantIsoDate() bool {
return false
}
type RssWebhook struct {
Id uuid.UUID `json:"id"`
Callback string `json:"-"`
Whitelist []string `json:"bonus_whitelist"`
Blacklist []string `json:"bonus_blacklist"`
Format string `json:"format"`
LastFiredAt *time.Time `json:"last_fired_at"`
PreviewLength int `json:"preview_length"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (s RssWebhook) GetLastFiredAt() *time.Time {
return s.LastFiredAt
}
func (s RssWebhook) GetCreatedAt() time.Time {
return s.CreatedAt
}
func (s RssWebhook) GetUpdatedAt() time.Time {
return s.UpdatedAt
}
func (s RssWebhook) GetFormat() string {
return s.Format
}
func (s RssWebhook) GetMentions() *map[string][]MentionDTO {
return nil
}
func (s RssWebhook) GetTimezone() string {
return ServerTz
}
func (s RssWebhook) GetBlacklist() []string {
return s.Blacklist
}
func (s RssWebhook) GetWhitelist() []string {
return s.Whitelist
}
func (s RssWebhook) GetId() uuid.UUID {
return s.Id
}
func (s RssWebhook) GetType() string {
return RSSWebhookType
}
func (s RssWebhook) GetCallback() string {
return s.Callback
}
func (s RssWebhook) GetPreviewLength() int {
return s.PreviewLength
}
func (s RssWebhook) IsWantIsoDate() bool {
return false
}
type ISocialHook interface {
GetId() uuid.UUID
GetLastFiredAt() *time.Time
GetCallback() string
GetCreatedAt() time.Time
GetUpdatedAt() time.Time
GetFormat() string
GetPreviewLength() int
GetBlacklist() []string
GetWhitelist() []string
}
type ISocialHookUpdate interface {
GetId() uuid.UUID
GetBlacklist() []string
GetWhitelist() []string
GetSubscriptions() []string
GetPreviewLength() *int
}
type SocialHookCreate struct {
Whitelist []string `json:"whitelist"`
Blacklist []string `json:"blacklist"`
Subscriptions []string `json:"subscriptions"`
PreviewLength *int `json:"preview_length"`
Callback string `json:"callback"`
Format string `json:"format"`
}
type MentionDTO struct {
DiscordId uint64 `json:"discord_id"`
IsRole bool `json:"is_role"`
PingDaysBefore *int `json:"ping_days_before"`
}
type AlmanaxHookPut struct {
BonusWhitelist []string `json:"bonus_whitelist"`
BonusBlacklist []string `json:"bonus_blacklist"`
DailySettings *WebhookDailySettings `json:"daily_settings"`
Subscriptions []string `json:"subscriptions"`
WantsIsoDate *bool `json:"iso_date"`
Mentions *map[string][]MentionDTO `json:"mentions"`
Intervals []string `json:"intervals"`
WeeklyWeekday *string `json:"weekly_weekday"`
}
type CreateAlmanaxHook struct {
BonusWhitelist []string
BonusBlacklist []string
DailySettings WebhookDailySettings
Callback string
Subscriptions []string
WantsIsoDate bool
Format string
Mentions *map[string][]MentionDTO
Intervals []string
WeeklyWeekday *string
}
type SocialWebhookDTO struct {
Id uuid.UUID `json:"id"`
Whitelist []string `json:"whitelist"`
Blacklist []string `json:"blacklist"`
Subscriptions []string `json:"subscriptions"`
Format string `json:"format"`
PreviewLength int `json:"preview_length"`
CreatedAt time.Time `json:"created_at"`
LastFiredAt *time.Time `json:"last_fired_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type SocialWebhookPutDb struct {
Id uuid.UUID
Whitelist []string `json:"whitelist"`
Blacklist []string `json:"blacklist"`
Subscriptions []string `json:"subscriptions"`
PreviewLength *int `json:"preview_length"`
}
func (hook SocialWebhookPutDb) GetId() uuid.UUID {
return hook.Id
}
func (hook SocialWebhookPutDb) GetBlacklist() []string {
return hook.Blacklist
}
func (hook SocialWebhookPutDb) GetWhitelist() []string {
return hook.Whitelist
}
func (hook SocialWebhookPutDb) GetSubscriptions() []string {
return hook.Subscriptions
}
func (hook SocialWebhookPutDb) GetPreviewLength() *int {
return hook.PreviewLength
}