-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathserverManagement.py
More file actions
86 lines (72 loc) · 3.17 KB
/
Copy pathserverManagement.py
File metadata and controls
86 lines (72 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from datetime import datetime
from discord.ext import commands, tasks
from config.server import ServerConfig
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 = DiscordBotQueries()
def validUser(self, ctx):
authorised_users = [
1120262151676895274,
1107555866422562926,
1059343450312544266,
] # devaraj, venkatesh, karn
return ctx.author.id in authorised_users
@commands.command(aliaes=["initiate"])
async def updateServerData(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)
self.postgres_client.addChapter(
roleId=role.id, orgName=orgName, type="COLLEGE"
)
elif role.name.startswith("Corporate:"):
orgName = role.name[len("Corporate: ") :]
chapterRoles.append(role)
self.postgres_client.addChapter(
roleId=role.id, orgName=orgName, type="CORPORATE"
)
print("added chapters")
contributorsGithub = self.postgres_client.read_all("contributors_registration")
contributorsDiscord = self.postgres_client.read_all_active("contributors_discord")
## 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)
print(count)
self.postgres_client.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")
self.postgres_client.invalidateContributorDiscord(membersWhoLeft)
print("Updated Contributors")
async def setup(bot):
await bot.add_cog(ServerManagement(bot))