subscribe update

This commit is contained in:
VinceC
2024-11-24 03:15:04 -06:00
parent 12722b6fd4
commit 1cee965d00
8 changed files with 447 additions and 72 deletions

View File

@@ -0,0 +1,58 @@
const { createClient } = require('@supabase/supabase-js');
class SupabaseService {
constructor() {
const supabaseUrl = process.env.SUPABASE_URL;
const supabaseKey = process.env.SUPABASE_KEY;
if (!supabaseUrl || !supabaseKey) {
console.error('Supabase URL or key is missing. Please check your .env file.');
this.supabase = null;
} else {
this.supabase = createClient(supabaseUrl, supabaseKey);
}
}
async getSubscriptions(guildId) {
if (!this.supabase) {
console.error('Supabase client is not initialized.');
return [];
}
const { data, error } = await this.supabase
.from('subscriptions')
.select('*')
.eq('guild_id', guildId);
if (error) throw error;
return data;
}
async addSubscription(guildId, gameName, channelId) {
if (!this.supabase) {
console.error('Supabase client is not initialized.');
return null;
}
const { data, error } = await this.supabase
.from('subscriptions')
.insert({ guild_id: guildId, game_name: gameName, channel_id: channelId });
if (error) throw error;
return data;
}
async removeSubscription(guildId, gameName) {
if (!this.supabase) {
console.error('Supabase client is not initialized.');
return null;
}
const { data, error } = await this.supabase
.from('subscriptions')
.delete()
.match({ guild_id: guildId, game_name: gameName });
if (error) throw error;
return data;
}
}
module.exports = SupabaseService;