Skip to content

Commit

Permalink
Merge pull request #90 from Code4GovTech/feature/shared-migrations-clean
Browse files Browse the repository at this point in the history
Deploy ready branch
  • Loading branch information
Shreyash-work-em authored Dec 30, 2024
2 parents 7319844 + ef2c35d commit 0c2be2d
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "shared_migrations"]
path = shared_migrations
url = https://github.com/Code4GovTech/shared-models-migrations.git
4 changes: 2 additions & 2 deletions cogs/badges.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import discord
from discord.ext import commands

from helpers.supabaseClient import PostgresClient
from shared_migrations.db.discord_bot import DiscordBotQueries


class BadgeModal(discord.ui.Modal, title="Your Badges"):
Expand All @@ -17,7 +17,7 @@ async def on_timeout(self, interaction):

class BadgeContents:
def __init__(self, name) -> None:
self.postgres_client = PostgresClient()
self.postgres_client = DiscordBotQueries()
apprentinceDesc = f"""Welcome *{name}*!!
Expand Down
4 changes: 2 additions & 2 deletions cogs/discordDataScraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from discord.channel import TextChannel
from discord.ext import commands, tasks

from helpers.supabaseClient import PostgresClient
from shared_migrations.db.discord_bot import DiscordBotQueries

with open("config.json") as config_file:
config_data = json.load(config_file)
Expand All @@ -24,7 +24,7 @@
class DiscordDataScaper(commands.Cog):
def __init__(self, bot) -> None:
self.bot = bot
self.postgres_client = PostgresClient()
self.postgres_client = DiscordBotQueries()

@commands.Cog.listener()
async def on_message(self, message):
Expand Down
5 changes: 2 additions & 3 deletions cogs/listeners/member_events_cog.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import discord
from discord.ext import commands

from helpers.supabaseClient import PostgresClient

from shared_migrations.db.discord_bot import DiscordBotQueries

class MemberEventsListener(commands.Cog):
def __init__(self, bot) -> None:
self.bot = bot
self.postgres_client = PostgresClient()
self.postgres_client = DiscordBotQueries()
super().__init__()

@commands.Cog.listener("on_member_join")
Expand Down
5 changes: 2 additions & 3 deletions cogs/listeners/message_events_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
from discord.ext import commands

from config.server import ServerConfig
from helpers.supabaseClient import PostgresClient

from shared_migrations.db.discord_bot import DiscordBotQueries
serverConfig = ServerConfig()
postgresClient = PostgresClient()
postgresClient = DiscordBotQueries()


async def grantVerifiedRole(member: discord.Member):
Expand Down
5 changes: 2 additions & 3 deletions cogs/listeners/role_events_cog.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import discord
from discord.ext import commands

from helpers.supabaseClient import PostgresClient

from shared_migrations.db.discord_bot import DiscordBotQueries

class RoleEventsListener(commands.Cog):
def __init__(self, bot) -> None:
self.bot = bot
self.postgres_client = PostgresClient()
self.postgres_client = DiscordBotQueries()
super().__init__()

@commands.Cog.listener()
Expand Down
5 changes: 2 additions & 3 deletions cogs/serverManagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
from discord.ext import commands, tasks

from config.server import ServerConfig
from helpers.supabaseClient import PostgresClient

from shared_migrations.db.discord_bot import DiscordBotQueries
serverConfig = ServerConfig()


class ServerManagement(commands.Cog):
def __init__(self, bot):
self.bot: commands.Bot = bot
self.postgres_client = PostgresClient()
self.postgres_client = DiscordBotQueries()

def validUser(self, ctx):
authorised_users = [
Expand Down
4 changes: 2 additions & 2 deletions cogs/userInteractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from discord.ext import commands, tasks
from dotenv import find_dotenv, load_dotenv

from helpers.supabaseClient import PostgresClient
from shared_migrations.db.discord_bot import DiscordBotQueries

load_dotenv(find_dotenv())

Expand All @@ -16,7 +16,7 @@ class UserHandler(commands.Cog):
def __init__(self, bot) -> None:
self.bot = bot
self.update_contributors.start()
self.postgres_client = PostgresClient()
self.postgres_client = DiscordBotQueries()

@tasks.loop(minutes=60)
async def update_contributors(self):
Expand Down
7 changes: 3 additions & 4 deletions cogs/vcCog.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
from discord.ext import commands

from config.server import ServerConfig
from helpers.supabaseClient import PostgresClient

from shared_migrations.db.discord_bot import DiscordBotQueries
"""
with io.BytesIO(image_bytes) as image_file:
# Create a discord.File object from this file-like object
Expand All @@ -21,7 +20,7 @@
class CommunityVCView(ui.View):
def __init__(self, *, timeout=None):
super().__init__(timeout=timeout)
self.postgres_client = PostgresClient()
self.postgres_client = DiscordBotQueries()

def isCommunityContributor(self, roles: list[Role]):
CommunityContributorRoleID = ServerConfig.Roles.CONTRIBUTOR_ROLE
Expand Down Expand Up @@ -215,7 +214,7 @@ async def serveCertificateLink(self, interaction: Interaction, button: ui.Button

class VCProgramSelection(ui.View):
def __init__(self, *, timeout=None):
self.postgres_client = PostgresClient()
self.postgres_client = DiscordBotQueries()
super().__init__(timeout=timeout)

async def resetSelectMenu(self, interaction):
Expand Down
2 changes: 1 addition & 1 deletion helpers/supabaseClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dotenv import load_dotenv
from sqlalchemy import create_engine,select,desc,update,delete
from sqlalchemy.orm import sessionmaker
from models import *
from shared_migrations.db.models import *
from sqlalchemy.ext.declarative import DeclarativeMeta
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession

Expand Down
6 changes: 3 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from discord.ext import commands

from cogs.vcCog import VCProgramSelection
from helpers.supabaseClient import PostgresClient
from shared_migrations.db.discord_bot import DiscordBotQueries
from dotenv import load_dotenv, find_dotenv


Expand Down Expand Up @@ -70,7 +70,7 @@ async def on_submit(self, interaction: discord.Interaction):
except Exception as e:
print('exception e ', e)
try:
response = await PostgresClient().updateContributor(user_data)
response = await DiscordBotQueries().updateContributor(user_data)
print("DB updated for user:", user_data["discord_id"])
except Exception as e:
print("Failed to update credentials for user: "+e)
Expand All @@ -96,7 +96,7 @@ async def hasIntroduced():
while not authentication:
print("Not authenticated. Waiting")
await asyncio.sleep(15)
authentication = await PostgresClient().read("contributors_registration", "discord_id", user.id)
authentication = await DiscordBotQueries().read("contributors_registration", "discord_id", user.id)
print("User has authenticated")
return True

Expand Down
1 change: 1 addition & 0 deletions shared_migrations
Submodule shared_migrations added at 0dedd5

0 comments on commit 0c2be2d

Please sign in to comment.