99from discord .channel import TextChannel
1010from discord .ext import commands , tasks
1111
12- from helpers . supabaseClient import SupabaseClient
12+ from shared_migrations . db . discord_bot import DiscordBotQueries
1313
1414with open ("config.json" ) as config_file :
1515 config_data = json .load (config_file )
2424class DiscordDataScaper (commands .Cog ):
2525 def __init__ (self , bot ) -> None :
2626 self .bot = bot
27+ self .postgres_client = DiscordBotQueries ()
2728
2829 @commands .Cog .listener ()
2930 async def on_message (self , message ):
3031 pass
31- # contributor = SupabaseClient().read(
32- # "discord_engagement", "contributor", message.author.id
33- # )
34- # print("message", len(message.content))
35- # if not contributor:
36- # SupabaseClient().insert(
37- # "discord_engagement",
38- # {
39- # "contributor": message.author.id,
40- # "has_introduced": False,
41- # "total_message_count": 1,
42- # "total_reaction_count": 0,
43- # },
44- # )
45- # return
46- # if len(message.content) > 20:
47- # if message.channel.id == INTRODUCTIONS_CHANNEL_ID:
48- # print("intro")
49- # SupabaseClient().update(
50- # "discord_engagement",
51- # {"has_introduced": True},
52- # "contributor",
53- # message.author.id,
54- # )
55- # SupabaseClient("discord_engagement").update(
56- # "discord_engagement",
57- # {"total_message_count": contributor[0]["total_message_count"] + 1},
58- # "contributor",
59- # message.author.id,
60- # )
32+
6133
6234 @commands .Cog .listener ()
6335 async def on_reaction_add (self , reaction , user ):
6436 message = reaction .message
65- contributor = SupabaseClient () .read (
37+ contributor = self . postgres_client .read (
6638 "discord_engagement" , "contributor" , message .author .id
6739 )[0 ]
6840 if not contributor :
69- SupabaseClient () .insert (
41+ self . postgres_client .insert (
7042 "discord_engagement" ,
7143 {
7244 "contributor" : message .author .id ,
@@ -77,7 +49,7 @@ async def on_reaction_add(self, reaction, user):
7749 )
7850 return
7951 print ("reaction" )
80- SupabaseClient () .update (
52+ self . postgres_client .update (
8153 "discord_engagement" ,
8254 {"total_reaction_count" : contributor ["total_reaction_count" ] + 1 },
8355 "contributor" ,
@@ -89,7 +61,7 @@ async def add_engagement(self, ctx):
8961 await ctx .channel .send ("started" )
9062
9163 def addEngagmentData (data ):
92- client = SupabaseClient ()
64+ client = self . postgres_client
9365 client .insert ("discord_engagement" , data )
9466 return
9567
@@ -145,7 +117,7 @@ async def enable_webhook(self, ctx):
145117 channels = await guild .fetch_channels ()
146118 enabled = [
147119 channel ["channel_id" ]
148- for channel in SupabaseClient () .read_all ("discord_channels" )
120+ for channel in self . postgres_client .read_all ("discord_channels" )
149121 ]
150122 for channel in channels :
151123 try :
@@ -156,7 +128,7 @@ async def enable_webhook(self, ctx):
156128 webhook = await channel .create_webhook (name = "New Ticket Alert" )
157129 feedback = f"""URL: { webhook .url } \n Token:{ "Yes" if webhook .token else "No" } """
158130 await ctx .send (feedback )
159- SupabaseClient () .insert (
131+ self . postgres_client .insert (
160132 "discord_channels" ,
161133 {
162134 "channel_id" : channel .id ,
@@ -177,7 +149,7 @@ async def update_applicants(self, ctx):
177149 await ctx .send ("Member List Count: " + str (len (members )))
178150 for member in members :
179151 try :
180- SupabaseClient () .insert (
152+ self . postgres_client .insert (
181153 "applicant" ,
182154 {"sheet_username" : member .name , "discord_id" : member .id },
183155 )
@@ -216,12 +188,12 @@ async def collect_all_messages(self):
216188
217189 async def add_messages (self ):
218190 def addMessageData (data ):
219- client = SupabaseClient ()
191+ client = self . postgres_client
220192 client .insert ("unstructured discord data" , data )
221193 return
222194
223195 def getLastMessageObject (channelId ):
224- last_message = SupabaseClient () .read_by_order_limit (
196+ last_message = self . postgres_client .read_by_order_limit (
225197 table = "unstructured discord data" ,
226198 query_key = "channel" ,
227199 query_value = channelId ,
0 commit comments