Skip to content

Commit 3c27e37

Browse files
committed
feat: Implement gift subscription notifications and update Supabase types
- Add new gift_subscriptions and notifications tables to Supabase types - Implement notification handling for gift subscriptions in Twitch chat - Enhance runner.sh to check for Colima and Docker status before generating types - Update translation file to include a message for gifted subscriptions
1 parent a566beb commit 3c27e37

File tree

6 files changed

+401
-6
lines changed

6 files changed

+401
-6
lines changed

packages/dota/locales/en/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"giftSub": "A gift sub for Dotabod Pro was just gifted by {{- senderName}}!",
23
"2mdelay": "(2m delay)",
34
"aegis": {
45
"denied": "{{- heroName}} denied the aegis {{emote}}",

packages/dota/src/db/supabase-types.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,47 @@ export type Database = {
239239
}
240240
Relationships: []
241241
}
242+
gift_subscriptions: {
243+
Row: {
244+
created_at: string
245+
giftMessage: string | null
246+
giftQuantity: number
247+
giftType: string
248+
id: string
249+
senderName: string
250+
subscriptionId: string
251+
updated_at: string
252+
}
253+
Insert: {
254+
created_at?: string
255+
giftMessage?: string | null
256+
giftQuantity?: number
257+
giftType?: string
258+
id?: string
259+
senderName?: string
260+
subscriptionId: string
261+
updated_at?: string
262+
}
263+
Update: {
264+
created_at?: string
265+
giftMessage?: string | null
266+
giftQuantity?: number
267+
giftType?: string
268+
id?: string
269+
senderName?: string
270+
subscriptionId?: string
271+
updated_at?: string
272+
}
273+
Relationships: [
274+
{
275+
foreignKeyName: 'gift_subscriptions_subscriptionId_fkey'
276+
columns: ['subscriptionId']
277+
isOneToOne: false
278+
referencedRelation: 'subscriptions'
279+
referencedColumns: ['id']
280+
},
281+
]
282+
}
242283
MessageDelivery: {
243284
Row: {
244285
createdAt: string
@@ -326,6 +367,51 @@ export type Database = {
326367
},
327368
]
328369
}
370+
notifications: {
371+
Row: {
372+
created_at: string
373+
giftSubscriptionId: string | null
374+
id: string
375+
isRead: boolean
376+
type: string
377+
updated_at: string
378+
userId: string
379+
}
380+
Insert: {
381+
created_at?: string
382+
giftSubscriptionId?: string | null
383+
id?: string
384+
isRead?: boolean
385+
type?: string
386+
updated_at?: string
387+
userId: string
388+
}
389+
Update: {
390+
created_at?: string
391+
giftSubscriptionId?: string | null
392+
id?: string
393+
isRead?: boolean
394+
type?: string
395+
updated_at?: string
396+
userId?: string
397+
}
398+
Relationships: [
399+
{
400+
foreignKeyName: 'notifications_giftSubscriptionId_fkey'
401+
columns: ['giftSubscriptionId']
402+
isOneToOne: false
403+
referencedRelation: 'gift_subscriptions'
404+
referencedColumns: ['id']
405+
},
406+
{
407+
foreignKeyName: 'notifications_userId_fkey'
408+
columns: ['userId']
409+
isOneToOne: false
410+
referencedRelation: 'users'
411+
referencedColumns: ['id']
412+
},
413+
]
414+
}
329415
ScheduledMessage: {
330416
Row: {
331417
createdAt: string
@@ -502,6 +588,7 @@ export type Database = {
502588
created_at: string
503589
currentPeriodEnd: string | null
504590
id: string
591+
isGift: boolean
505592
status: Database['public']['Enums']['SubscriptionStatus'] | null
506593
stripeCustomerId: string | null
507594
stripePriceId: string | null
@@ -516,6 +603,7 @@ export type Database = {
516603
created_at?: string
517604
currentPeriodEnd?: string | null
518605
id?: string
606+
isGift?: boolean
519607
status?: Database['public']['Enums']['SubscriptionStatus'] | null
520608
stripeCustomerId?: string | null
521609
stripePriceId?: string | null
@@ -530,6 +618,7 @@ export type Database = {
530618
created_at?: string
531619
currentPeriodEnd?: string | null
532620
id?: string
621+
isGift?: boolean
533622
status?: Database['public']['Enums']['SubscriptionStatus'] | null
534623
stripeCustomerId?: string | null
535624
stripePriceId?: string | null

packages/dota/src/db/watcher.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import getDBUser from './getDBUser.js'
1212
import { handleUserOnlineMessages } from './handleScheduledMessages'
1313
import type { Tables } from './supabase-types.js'
1414
import supabase from './supabase.js'
15+
import { chatClient } from '../twitch/chatClient'
16+
import { t } from 'i18next'
1517

1618
class SetupSupabase {
1719
channel: any // ReturnType<typeof supabase.channel>
@@ -261,6 +263,40 @@ class SetupSupabase {
261263
}
262264
},
263265
)
266+
.on(
267+
'postgres_changes',
268+
{ event: 'INSERT', schema: 'public', table: 'gift_subscriptions' },
269+
async (payload: { new: Tables<'gift_subscriptions'> }) => {
270+
const newObj = payload.new
271+
const userId = await supabase
272+
.from('subscriptions')
273+
.select('userId')
274+
.eq('id', newObj.subscriptionId)
275+
.single()
276+
277+
if (!userId) return
278+
const client = findUser(userId.data?.userId)
279+
280+
if (!client || !client.stream_online) return
281+
282+
try {
283+
// Send notification message to chat
284+
chatClient.say(
285+
client.name,
286+
t('giftSub', {
287+
senderName: newObj.senderName,
288+
giftMessage: newObj.giftMessage,
289+
lng: client.locale,
290+
}) + (newObj.giftMessage ? `" ${newObj.giftMessage}"` : ''),
291+
)
292+
} catch (e) {
293+
logger.error('Error sending notification to chat', {
294+
error: e,
295+
userId: client.token,
296+
})
297+
}
298+
},
299+
)
264300
.on(
265301
'postgres_changes',
266302
{ event: '*', schema: 'public', table: 'settings' },

packages/twitch-chat/src/db/supabase-types.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,47 @@ export type Database = {
239239
}
240240
Relationships: []
241241
}
242+
gift_subscriptions: {
243+
Row: {
244+
created_at: string
245+
giftMessage: string | null
246+
giftQuantity: number
247+
giftType: string
248+
id: string
249+
senderName: string
250+
subscriptionId: string
251+
updated_at: string
252+
}
253+
Insert: {
254+
created_at?: string
255+
giftMessage?: string | null
256+
giftQuantity?: number
257+
giftType?: string
258+
id?: string
259+
senderName?: string
260+
subscriptionId: string
261+
updated_at?: string
262+
}
263+
Update: {
264+
created_at?: string
265+
giftMessage?: string | null
266+
giftQuantity?: number
267+
giftType?: string
268+
id?: string
269+
senderName?: string
270+
subscriptionId?: string
271+
updated_at?: string
272+
}
273+
Relationships: [
274+
{
275+
foreignKeyName: 'gift_subscriptions_subscriptionId_fkey'
276+
columns: ['subscriptionId']
277+
isOneToOne: false
278+
referencedRelation: 'subscriptions'
279+
referencedColumns: ['id']
280+
},
281+
]
282+
}
242283
MessageDelivery: {
243284
Row: {
244285
createdAt: string
@@ -326,6 +367,51 @@ export type Database = {
326367
},
327368
]
328369
}
370+
notifications: {
371+
Row: {
372+
created_at: string
373+
giftSubscriptionId: string | null
374+
id: string
375+
isRead: boolean
376+
type: string
377+
updated_at: string
378+
userId: string
379+
}
380+
Insert: {
381+
created_at?: string
382+
giftSubscriptionId?: string | null
383+
id?: string
384+
isRead?: boolean
385+
type?: string
386+
updated_at?: string
387+
userId: string
388+
}
389+
Update: {
390+
created_at?: string
391+
giftSubscriptionId?: string | null
392+
id?: string
393+
isRead?: boolean
394+
type?: string
395+
updated_at?: string
396+
userId?: string
397+
}
398+
Relationships: [
399+
{
400+
foreignKeyName: 'notifications_giftSubscriptionId_fkey'
401+
columns: ['giftSubscriptionId']
402+
isOneToOne: false
403+
referencedRelation: 'gift_subscriptions'
404+
referencedColumns: ['id']
405+
},
406+
{
407+
foreignKeyName: 'notifications_userId_fkey'
408+
columns: ['userId']
409+
isOneToOne: false
410+
referencedRelation: 'users'
411+
referencedColumns: ['id']
412+
},
413+
]
414+
}
329415
ScheduledMessage: {
330416
Row: {
331417
createdAt: string
@@ -502,6 +588,7 @@ export type Database = {
502588
created_at: string
503589
currentPeriodEnd: string | null
504590
id: string
591+
isGift: boolean
505592
status: Database['public']['Enums']['SubscriptionStatus'] | null
506593
stripeCustomerId: string | null
507594
stripePriceId: string | null
@@ -516,6 +603,7 @@ export type Database = {
516603
created_at?: string
517604
currentPeriodEnd?: string | null
518605
id?: string
606+
isGift?: boolean
519607
status?: Database['public']['Enums']['SubscriptionStatus'] | null
520608
stripeCustomerId?: string | null
521609
stripePriceId?: string | null
@@ -530,6 +618,7 @@ export type Database = {
530618
created_at?: string
531619
currentPeriodEnd?: string | null
532620
id?: string
621+
isGift?: boolean
533622
status?: Database['public']['Enums']['SubscriptionStatus'] | null
534623
stripeCustomerId?: string | null
535624
stripePriceId?: string | null

0 commit comments

Comments
 (0)