Skip to content

Commit 27567ea

Browse files
authored
Merge pull request #54 from Code4GovTech/development
Development
2 parents 81b2b77 + f2c9288 commit 27567ea

File tree

10 files changed

+107
-203
lines changed

10 files changed

+107
-203
lines changed

cogs/badges.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ def get_user_badges(self, discord_id):
160160
github_id = contributorData[0]["github_id"]
161161
prData = {
162162
"raised": SupabaseClient().read(
163-
table="pull_requests", query_key="raised_by", query_value=github_id
163+
table="connected_prs", query_key="raised_by", query_value=github_id
164164
),
165-
"merged": SupabaseClient(table="pull_requests").read(
166-
table="pull_requests", query_key="merged_by", query_value=github_id
165+
"merged": SupabaseClient(table="connected_prs").read(
166+
table="connected_prs", query_key="merged_by", query_value=github_id
167167
),
168168
}
169169
points = 0

cogs/discordDataScraper.py

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,37 @@ def __init__(self, bot) -> None:
2727

2828
@commands.Cog.listener()
2929
async def on_message(self, message):
30-
contributor = SupabaseClient().read(
31-
"discord_engagement", "contributor", message.author.id
32-
)
33-
print("message", len(message.content))
34-
if not contributor:
35-
SupabaseClient().insert(
36-
"discord_engagement",
37-
{
38-
"contributor": message.author.id,
39-
"has_introduced": False,
40-
"total_message_count": 1,
41-
"total_reaction_count": 0,
42-
},
43-
)
44-
return
45-
if len(message.content) > 20:
46-
if message.channel.id == INTRODUCTIONS_CHANNEL_ID:
47-
print("intro")
48-
SupabaseClient().update(
49-
"discord_engagement",
50-
{"has_introduced": True},
51-
"contributor",
52-
message.author.id,
53-
)
54-
SupabaseClient("discord_engagement").update(
55-
"discord_engagement",
56-
{"total_message_count": contributor[0]["total_message_count"] + 1},
57-
"contributor",
58-
message.author.id,
59-
)
30+
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+
# )
6061

6162
@commands.Cog.listener()
6263
async def on_reaction_add(self, reaction, user):

cogs/serverManagement.py

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,61 @@ def validUser(self, ctx):
2323
return ctx.author.id in authorised_users
2424

2525
@commands.command(aliaes=["initiate"])
26-
async def initiateServerData(self, ctx):
26+
async def getServerData(self, ctx):
2727
# add all chapters
28+
chapterRoles = []
2829
guild = self.bot.get_guild(serverConfig.SERVER)
30+
## Clear Error
31+
oldRole = guild.get_role(973852365188907048)
32+
print("started")
33+
print(f"{len(oldRole.members)} have the old contributor role")
34+
for member in oldRole.members:
35+
print(member.joined_at)
36+
if member.joined_at.timestamp() > datetime(2022, 12, 25).timestamp():
37+
await member.remove_roles(oldRole, reason="mistakenly given")
38+
print("Member removed")
39+
2940
for role in guild.roles:
3041
if role.name.startswith("College:"):
3142
orgName = role.name[len("College: ") :]
43+
chapterRoles.append(role)
3244
SupabaseClient().addChapter(orgName=orgName, type="COLLEGE")
3345
elif role.name.startswith("Corporate:"):
3446
orgName = role.name[len("Corporate: ") :]
47+
chapterRoles.append(role)
3548
SupabaseClient().addChapter(orgName=orgName, type="CORPORATE")
3649

37-
async for member in guild.fetch_members(
38-
after=datetime(2023, 12, 1, 0, 0, 0), limit=None
39-
):
40-
print(member.name)
41-
SupabaseClient().updateContributor(member)
42-
print("Done")
50+
print("added chapters")
51+
52+
contributorsGithub = SupabaseClient().read_all("contributors_registration")
53+
contributorsDiscord = SupabaseClient().read_all("contributors_discord")
4354

44-
# async def notifs_on(self,ctx,channel: discord.TextChannel):
45-
# try:
46-
# SupabaseClient("discord_channels").update({"should_notify": True}, "channel_id", channel.id)
47-
# await ctx.send(f"Notifications have been turned on for {channel.name}")
48-
# except Exception as e:
49-
# print(e)
50-
# await ctx.send("An unexpected error occured")
55+
## Give contributor role
56+
contributorIds = [
57+
contributor["discord_id"] for contributor in contributorsGithub
58+
]
59+
contributorRole = guild.get_role(serverConfig.Roles.CONTRIBUTOR_ROLE)
60+
count = [0, 0, 0]
61+
for member in guild.members:
62+
count[0] += 1
63+
if member.id in contributorIds:
64+
count[1] += 1
65+
if contributorRole not in member.roles:
66+
count[2] += 1
67+
await member.add_roles(contributorRole)
5168

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

60-
# async def
71+
SupabaseClient().updateContributors(guild.members)
72+
recordedMembers = [
73+
contributor["discord_id"] for contributor in contributorsDiscord
74+
]
75+
print(f"{len(recordedMembers)} have their data saved")
76+
currentMembers = [member.id for member in guild.members]
77+
membersWhoLeft = list(set(recordedMembers) - set(currentMembers))
78+
print(f"{len(membersWhoLeft)} members left")
79+
SupabaseClient().deleteContributorDiscord(membersWhoLeft)
80+
print("Updated Contributors")
6181

6282

6383
async def setup(bot):

cogs/userInteractions.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def __init__(self, discord_userdata):
177177
class UserHandler(commands.Cog):
178178
def __init__(self, bot) -> None:
179179
self.bot = bot
180-
self.update_contributors.start()
180+
# self.update_contributors.start()
181181

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

@@ -332,18 +332,6 @@ async def github_profile(self, ctx):
332332
```[![C4GTGithubDisplay](https://kcavhjwafgtoqkqbbqrd.supabase.co/storage/v1/object/public/c4gt-github-profile/{ctx.author.id}githubdisplay.jpg)](https://github.com/Code4GovTech)
333333
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)```"""
334334
)
335-
# githubProfileInfoEmbed.set_footer(text="Respond with 🏆 to get the link")
336-
# message = await ctx.send(embed=githubProfileInfoEmbed)
337-
# await message.add_reaction("🏆")
338-
# def check(reaction, user):
339-
# return user == ctx.message.author and str(reaction.emoji) in ['🏆']
340-
# try:
341-
# reaction, user = await self.bot.wait_for('reaction_add', timeout=60.0, check=check)
342-
# except asyncio.TimeoutError:
343-
# await ctx.send("You took too long to respond.")
344-
# else:
345-
# if str(reaction.emoji) == '🏆':
346-
# 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)')
347335

348336
@update_contributors.before_loop
349337
async def before_update_loop(self):
@@ -406,10 +394,10 @@ async def get_points(self, ctx):
406394
print(contributor)
407395
github_id = contributor[0]["github_id"]
408396
prs_raised = SupabaseClient().read(
409-
table="pull_requests", query_key="raised_by", query_value=github_id
397+
table="connected_prs", query_key="raised_by", query_value=github_id
410398
)
411399
prs_merged = SupabaseClient().read(
412-
table="pull_requests", query_key="merged_by", query_value=github_id
400+
table="connected_prs", query_key="merged_by", query_value=github_id
413401
)
414402
raise_points = 0
415403
merge_points = 0

config/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Channels:
1111

1212
@dataclass
1313
class Roles:
14-
CONTRIBUTOR_ROLE: int = 973852365188907048
14+
CONTRIBUTOR_ROLE: int = 1123967402175119482
1515

1616
@classmethod
1717
def isCollegeChapter(roleName: str) -> bool:

helpers/supabaseClient.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,29 @@ def updateContributor(self, contributor: Member):
9393
},
9494
on_conflict="discord_id",
9595
).execute()
96+
97+
def updateContributors(self, contributors: [Member]):
98+
table = "contributors_discord"
99+
data = []
100+
for contributor in contributors:
101+
chapters = lookForChapterRoles(contributor.roles)
102+
gender = lookForGenderRoles(contributor.roles)
103+
data.append(
104+
{
105+
"discord_id": contributor.id,
106+
"discord_username": contributor.name,
107+
"chapter": chapters[0] if chapters else None,
108+
"gender": gender,
109+
"joined_at": contributor.joined_at.isoformat(),
110+
}
111+
)
112+
113+
self.client.table(table).upsert(
114+
data,
115+
on_conflict="discord_id",
116+
).execute()
117+
118+
def deleteContributorDiscord(self, contributorDiscordIds):
119+
table = "contributors_discord"
120+
for id in contributorDiscordIds:
121+
self.client.table(table).delete().eq("discord_id", id).execute()

models/__init__.py

Whitespace-only changes.

models/product.py

Lines changed: 0 additions & 59 deletions
This file was deleted.

models/project.py

Lines changed: 0 additions & 39 deletions
This file was deleted.

models/user.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)