Skip to content

Commit

Permalink
Merge pull request #54 from Code4GovTech/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
KDwevedi authored Jan 29, 2024
2 parents 81b2b77 + f2c9288 commit 27567ea
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 203 deletions.
6 changes: 3 additions & 3 deletions cogs/badges.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ def get_user_badges(self, discord_id):
github_id = contributorData[0]["github_id"]
prData = {
"raised": SupabaseClient().read(
table="pull_requests", query_key="raised_by", query_value=github_id
table="connected_prs", query_key="raised_by", query_value=github_id
),
"merged": SupabaseClient(table="pull_requests").read(
table="pull_requests", query_key="merged_by", query_value=github_id
"merged": SupabaseClient(table="connected_prs").read(
table="connected_prs", query_key="merged_by", query_value=github_id
),
}
points = 0
Expand Down
61 changes: 31 additions & 30 deletions cogs/discordDataScraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,37 @@ def __init__(self, bot) -> None:

@commands.Cog.listener()
async def on_message(self, message):
contributor = SupabaseClient().read(
"discord_engagement", "contributor", message.author.id
)
print("message", len(message.content))
if not contributor:
SupabaseClient().insert(
"discord_engagement",
{
"contributor": message.author.id,
"has_introduced": False,
"total_message_count": 1,
"total_reaction_count": 0,
},
)
return
if len(message.content) > 20:
if message.channel.id == INTRODUCTIONS_CHANNEL_ID:
print("intro")
SupabaseClient().update(
"discord_engagement",
{"has_introduced": True},
"contributor",
message.author.id,
)
SupabaseClient("discord_engagement").update(
"discord_engagement",
{"total_message_count": contributor[0]["total_message_count"] + 1},
"contributor",
message.author.id,
)
pass
# contributor = SupabaseClient().read(
# "discord_engagement", "contributor", message.author.id
# )
# print("message", len(message.content))
# if not contributor:
# SupabaseClient().insert(
# "discord_engagement",
# {
# "contributor": message.author.id,
# "has_introduced": False,
# "total_message_count": 1,
# "total_reaction_count": 0,
# },
# )
# return
# if len(message.content) > 20:
# if message.channel.id == INTRODUCTIONS_CHANNEL_ID:
# print("intro")
# SupabaseClient().update(
# "discord_engagement",
# {"has_introduced": True},
# "contributor",
# message.author.id,
# )
# SupabaseClient("discord_engagement").update(
# "discord_engagement",
# {"total_message_count": contributor[0]["total_message_count"] + 1},
# "contributor",
# message.author.id,
# )

@commands.Cog.listener()
async def on_reaction_add(self, reaction, user):
Expand Down
64 changes: 42 additions & 22 deletions cogs/serverManagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,61 @@ def validUser(self, ctx):
return ctx.author.id in authorised_users

@commands.command(aliaes=["initiate"])
async def initiateServerData(self, ctx):
async def getServerData(self, ctx):
# add all chapters
chapterRoles = []
guild = self.bot.get_guild(serverConfig.SERVER)
## Clear Error
oldRole = guild.get_role(973852365188907048)
print("started")
print(f"{len(oldRole.members)} have the old contributor role")
for member in oldRole.members:
print(member.joined_at)
if member.joined_at.timestamp() > datetime(2022, 12, 25).timestamp():
await member.remove_roles(oldRole, reason="mistakenly given")
print("Member removed")

for role in guild.roles:
if role.name.startswith("College:"):
orgName = role.name[len("College: ") :]
chapterRoles.append(role)
SupabaseClient().addChapter(orgName=orgName, type="COLLEGE")
elif role.name.startswith("Corporate:"):
orgName = role.name[len("Corporate: ") :]
chapterRoles.append(role)
SupabaseClient().addChapter(orgName=orgName, type="CORPORATE")

async for member in guild.fetch_members(
after=datetime(2023, 12, 1, 0, 0, 0), limit=None
):
print(member.name)
SupabaseClient().updateContributor(member)
print("Done")
print("added chapters")

contributorsGithub = SupabaseClient().read_all("contributors_registration")
contributorsDiscord = SupabaseClient().read_all("contributors_discord")

# async def notifs_on(self,ctx,channel: discord.TextChannel):
# try:
# SupabaseClient("discord_channels").update({"should_notify": True}, "channel_id", channel.id)
# await ctx.send(f"Notifications have been turned on for {channel.name}")
# except Exception as e:
# print(e)
# await ctx.send("An unexpected error occured")
## Give contributor role
contributorIds = [
contributor["discord_id"] for contributor in contributorsGithub
]
contributorRole = guild.get_role(serverConfig.Roles.CONTRIBUTOR_ROLE)
count = [0, 0, 0]
for member in guild.members:
count[0] += 1
if member.id in contributorIds:
count[1] += 1
if contributorRole not in member.roles:
count[2] += 1
await member.add_roles(contributorRole)

# async def notifs_off(self, ctx, channel: discord.TextChannel):
# try:
# SupabaseClient("discord_channels").update({"should_notify": False}, "channel_id", channel.id)
# await ctx.send(f"Notifications have been turned on for {channel.name}")
# except Exception as e:
# print(e)
# await ctx.send("An unexpected error occured")
print(count)

# async def
SupabaseClient().updateContributors(guild.members)
recordedMembers = [
contributor["discord_id"] for contributor in contributorsDiscord
]
print(f"{len(recordedMembers)} have their data saved")
currentMembers = [member.id for member in guild.members]
membersWhoLeft = list(set(recordedMembers) - set(currentMembers))
print(f"{len(membersWhoLeft)} members left")
SupabaseClient().deleteContributorDiscord(membersWhoLeft)
print("Updated Contributors")


async def setup(bot):
Expand Down
20 changes: 4 additions & 16 deletions cogs/userInteractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def __init__(self, discord_userdata):
class UserHandler(commands.Cog):
def __init__(self, bot) -> None:
self.bot = bot
self.update_contributors.start()
# self.update_contributors.start()

# Executing this command sends a link to Github OAuth App via a Flask Server in the DM channel of the one executing the command
# @commands.command(aliases=['join'])
Expand Down Expand Up @@ -238,7 +238,7 @@ async def update_contributors(self):
# Give Contributor Role
print(member.name)
await member.add_roles(contributor_role)
print("Given Roles")
print(f"Given Roles to {member.name if member else 'None'}")
# add to discord engagement
# SupabaseClient("discord_engagement").insert({"contributor": member.id})

Expand Down Expand Up @@ -332,18 +332,6 @@ async def github_profile(self, ctx):
```[![C4GTGithubDisplay](https://kcavhjwafgtoqkqbbqrd.supabase.co/storage/v1/object/public/c4gt-github-profile/{ctx.author.id}githubdisplay.jpg)](https://github.com/Code4GovTech)
Know more about: Code For GovTech ([Website](https://www.codeforgovtech.in) | [GitHub](https://github.com/Code4GovTech/C4GT/wiki)) | [Digital Public Goods (DPGs)](https://digitalpublicgoods.net/digital-public-goods/) | [India & DPGs](https://government.economictimes.indiatimes.com/blog/digital-public-goods-digital-public-infrastructure-an-evolving-india-story/99532036)```"""
)
# githubProfileInfoEmbed.set_footer(text="Respond with 🏆 to get the link")
# message = await ctx.send(embed=githubProfileInfoEmbed)
# await message.add_reaction("🏆")
# def check(reaction, user):
# return user == ctx.message.author and str(reaction.emoji) in ['🏆']
# try:
# reaction, user = await self.bot.wait_for('reaction_add', timeout=60.0, check=check)
# except asyncio.TimeoutError:
# await ctx.send("You took too long to respond.")
# else:
# if str(reaction.emoji) == '🏆':
# await ctx.send(f'[![C4GTGithubDisplay](https://kcavhjwafgtoqkqbbqrd.supabase.co/storage/v1/object/public/c4gt-github-profile/{ctx.author.id}githubdisplay.jpg?maxAge=10)](https://github.com/Code4GovTech)')

@update_contributors.before_loop
async def before_update_loop(self):
Expand Down Expand Up @@ -406,10 +394,10 @@ async def get_points(self, ctx):
print(contributor)
github_id = contributor[0]["github_id"]
prs_raised = SupabaseClient().read(
table="pull_requests", query_key="raised_by", query_value=github_id
table="connected_prs", query_key="raised_by", query_value=github_id
)
prs_merged = SupabaseClient().read(
table="pull_requests", query_key="merged_by", query_value=github_id
table="connected_prs", query_key="merged_by", query_value=github_id
)
raise_points = 0
merge_points = 0
Expand Down
2 changes: 1 addition & 1 deletion config/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Channels:

@dataclass
class Roles:
CONTRIBUTOR_ROLE: int = 973852365188907048
CONTRIBUTOR_ROLE: int = 1123967402175119482

@classmethod
def isCollegeChapter(roleName: str) -> bool:
Expand Down
26 changes: 26 additions & 0 deletions helpers/supabaseClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,29 @@ def updateContributor(self, contributor: Member):
},
on_conflict="discord_id",
).execute()

def updateContributors(self, contributors: [Member]):
table = "contributors_discord"
data = []
for contributor in contributors:
chapters = lookForChapterRoles(contributor.roles)
gender = lookForGenderRoles(contributor.roles)
data.append(
{
"discord_id": contributor.id,
"discord_username": contributor.name,
"chapter": chapters[0] if chapters else None,
"gender": gender,
"joined_at": contributor.joined_at.isoformat(),
}
)

self.client.table(table).upsert(
data,
on_conflict="discord_id",
).execute()

def deleteContributorDiscord(self, contributorDiscordIds):
table = "contributors_discord"
for id in contributorDiscordIds:
self.client.table(table).delete().eq("discord_id", id).execute()
Empty file removed models/__init__.py
Empty file.
59 changes: 0 additions & 59 deletions models/product.py

This file was deleted.

39 changes: 0 additions & 39 deletions models/project.py

This file was deleted.

33 changes: 0 additions & 33 deletions models/user.py

This file was deleted.

0 comments on commit 27567ea

Please sign in to comment.