Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,9 @@ def airtable_token(self) -> str:
@property
def slow_repeat_interval(self) -> int:
return self.get("slow_repeat_interval")

@property
def wants_to_help_role_id(self) -> int:
return self.get("wants_to_help_role_id")

CONFIG = Config("config.yml", "secrets.yml")
5 changes: 4 additions & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ admin_user_ids:
- 232972493957103618 # Pato
- 346706777305251840 # Chris G
staging:
- 252771041464680449 # Maxime F
- 252771041464680449 # Maxime F
wants_to_help_role_id:
prod: 1247238509064880218
staging: 0
21 changes: 21 additions & 0 deletions onboarding/onboarding_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from messages.m_onboarding import *
from airtable_client import TABLES
from config import CONFIG

# -------------
# STANDARD CONDITIONS
Expand Down Expand Up @@ -336,6 +337,18 @@
{
"type": "database set onboarder"
},
{
"type": "database update tick",
"condition": {
"type": "discord has role",
"role_id": CONFIG.wants_to_help_role_id
},
"field_name": "Wants to help"
},
{
"type": "discord remove role",
"role_id": CONFIG.wants_to_help_role_id
},
{
"type": "message",
"condition": DATABASE_WEBSITE,
Expand Down Expand Up @@ -373,6 +386,14 @@
"type": "database update untick",
"field_name": "Check In"
},
{
"type": "discord add role",
"condition": {
"type": "database check ticked",
"field_name": "Wants to help"
},
"role_id": CONFIG.wants_to_help_role_id
},
{
"type": "message",
"message": M_UNDO_START_ONBOARDING
Expand Down
14 changes: 10 additions & 4 deletions onboarding/onboarding_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import discord
from airtable import Airtable

from onboarding.utils import reset_onboarder, reset_researcher, update_onboarder, update_researcher
from onboarding.utils import reset_onboarder, reset_researcher, update_onboarder, update_researcher, remove_role, add_role
from onboarding.onboarding_config import CONFIG

class ConditionException(Exception):
Expand Down Expand Up @@ -102,7 +102,7 @@ async def command_trigger(self, command: str, subcommand: str, user: discord.Use
signature = self.trigger_signature_from_command(command, subcommand)
await self.handle_stage(signature, user, message, None, record, table, params)

def solve_condition(self, condition: Dict, record: Dict, user: discord.User, params: Dict) -> bool:
def solve_condition(self, condition: Dict, record: Dict, user: discord.User, message: discord.Message, params: Dict) -> bool:
satisfied = False
if condition["type"] == "database check ticked":
satisfied = record["fields"].get(condition["field_name"], False)
Expand All @@ -116,6 +116,8 @@ def solve_condition(self, condition: Dict, record: Dict, user: discord.User, par
satisfied = record["fields"].get("Researcher Id", "") == str(user.id)
elif condition["type"] == "database check is onboarder":
satisfied = record["fields"].get("Onboarder Id", "") == str(user.id)
elif condition["type"] == "discord has role":
satisfied = not not message.author.get_role(condition["role_id"])
elif condition["type"] == "check param value":
satisfied = params[condition["param_name"]] == condition["param_value"]
else:
Expand All @@ -135,7 +137,7 @@ async def handle_stage(self, signature: str, user: discord.User, message: discor
for condition in stage.get("conditions", []):
print(f"Condition: {condition['type']}")
try:
satisfied = self.solve_condition(condition, record, user, params)
satisfied = self.solve_condition(condition, record, user, message, params)
except ConditionException:
print(f"Error: unknown condition type: {condition['type']}")
return
Expand All @@ -151,7 +153,7 @@ async def handle_stage(self, signature: str, user: discord.User, message: discor
condition = action["condition"]
print(f"Evaluating condition attached to action: {condition['type']}")
try:
satisfied = self.solve_condition(condition, record, user, params)
satisfied = self.solve_condition(condition, record, user, message, params)
except ConditionException:
print(f"Error: unknown condition type: {condition['type']}")
return
Expand Down Expand Up @@ -181,6 +183,10 @@ async def handle_stage(self, signature: str, user: discord.User, message: discor
table.update(record["id"], {action["field_name"]: params[action["param_name"]]}, typecast=True)
elif action["type"] == "message":
await user.send(format_message(action["message"], record, params))
elif action["type"] == "discord remove role":
await remove_role(message.author, action["role_id"])
elif action["type"] == "discord add role":
await add_role(message.author, action["role_id"])
else:
print(f"Error: unknown action type: {action['type']}")
return
Expand Down
10 changes: 9 additions & 1 deletion onboarding/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,12 @@ def format_message_discord(message: str, record: Dict, **kwargs) -> str:
name=record["fields"].get("Newcomer Name"),
user_id=record["fields"].get("Newcomer Id"),
**kwargs
)
)

async def remove_role(member: discord.Member, role_id: int):
role = member.guild.get_role(role_id)
await member.remove_roles(role)

async def add_role(member: discord.Member, role_id):
role = member.guild.get_role(role_id)
await member.add_roles(role)