Skip to content

Commit

Permalink
Recognized setup users
Browse files Browse the repository at this point in the history
  • Loading branch information
DeveloperAnonymous committed Feb 16, 2024
1 parent 29f82b4 commit 47a7475
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ min-public-methods=0
[MESSAGES CONTROL]
# Disable the message "C0114: Missing module docstring"
# Disabled the message "W0511: fixme"
disable=C0114, W0511
# Disabled the message "R0201: Method could be a function"
disable=C0114, W0511, R0201

[FORMAT]
# Disabled the message "W0603: Using the global statement"
Expand Down
13 changes: 7 additions & 6 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"recommendations": [
"ms-python.python",
"ms-python.pylint",
"sonarsource.sonarlint-vscode"
]
}
"recommendations": [
"ms-python.python",
"ms-python.pylint",
"ms-python.black",
"sonarsource.sonarlint-vscode"
]
}
16 changes: 5 additions & 11 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"python.analysis.importFormat": "absolute",
"python.formatting.provider": "black",
"python.formatting.blackArgs": [
"--line-length",
"120",
"--target-version",
"py11",
],
"python.linting.pylintEnabled": true,
"editor.formatOnSave": true,
}
"python.analysis.importFormat": "absolute",
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true,
"black-formatter.args": ["--line-length", "120", "--target-version", "py311"]
}
8 changes: 4 additions & 4 deletions bot/db/services/base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def conn(self) -> Database:
"""Return a connection to the database."""
if self.__conn is None:
self.__conn = MongoClient(
"mongodb+srv://" +
f"{configs.DB_USER}:{configs.DB_PASSWORD}" +
f"@{configs.DB_HOST}/" +
"?retryWrites=true&w=majority&ssl=true",
"mongodb+srv://"
+ f"{configs.DB_USER}:{configs.DB_PASSWORD}"
+ f"@{configs.DB_HOST}/"
+ "?retryWrites=true&w=majority&ssl=true",
).get_database(configs.DB_NAME)

return self.__conn
Expand Down
8 changes: 8 additions & 0 deletions bot/management/welcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@

import configs
from bot import util, welcome
from bot.db.services import UserService


class WelcomeCog(commands.Cog):
"""This class contains the events related to welcome."""

def __init__(self) -> None:
self.user_service = UserService()

@commands.command()
@commands.guild_only()
async def setup(self, ctx: commands.Context):
Expand All @@ -26,6 +30,10 @@ async def setup(self, ctx: commands.Context):
@commands.Cog.listener()
async def on_member_join(self, member: discord.Member):
"""This event is called when a member joins the server."""
adept_member = await self.user_service.find_by_id(member.id)
if adept_member:
return await welcome.process_welcome_result(member, adept_member)

await util.say(configs.WELCOME_CHANNEL, configs.WELCOME_SERVER.format(name=member.mention))
result = await welcome.walk_through_welcome(member)
await welcome.process_welcome_result(member, result)
1 change: 1 addition & 0 deletions bot/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(
) -> None:
self.channel = channel
self.message = message
super().__init__(self.message)


@total_ordering
Expand Down
14 changes: 11 additions & 3 deletions bot/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
CLIENT: discord.Client = None

logging.basicConfig(
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", datefmt="%Y-%m-%d %H:%M:%S"
level=logging.INFO,
format="%(asctime)s - %(levelname)s - %(name)s - %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
logger = logging.getLogger("ADEPT-BOT")

Expand All @@ -29,6 +31,7 @@ class AdeptBotException(Exception):

def __init__(self, message: str) -> None:
self.message = f":bangbang: **{message}**"
super().__init__(self.message)


def get_member(guild_id: int, member_id: int):
Expand Down Expand Up @@ -183,7 +186,10 @@ async def archive_ticket(member: discord.Member, channel: discord.TextChannel):
category = guild.get_channel(configs.TICKET_ARCHIVE_CATEGORY)

overwrites = discord.PermissionOverwrite(
view_channel=True, read_messages=True, send_messages=False, read_message_history=True
view_channel=True,
read_messages=True,
send_messages=False,
read_message_history=True,
)

await channel.set_permissions(member, overwrite=overwrites)
Expand All @@ -201,7 +207,9 @@ def get_welcome_instruction(instruction: str):
The instruction to display.
"""
welcome_embed = discord.Embed(
title=configs.WELCOME_TITLE, description=configs.WELCOME_MESSAGE.format(content=instruction), color=0x1DE203
title=configs.WELCOME_TITLE,
description=configs.WELCOME_MESSAGE.format(content=instruction),
color=0x1DE203,
)
welcome_embed.set_thumbnail(url="https://www.adeptinfo.ca/img/badge.png")
welcome_embed.set_footer(text=configs.WELCOME_FOOTER)
Expand Down
49 changes: 39 additions & 10 deletions bot/welcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from bot.db.models import AdeptMember
from bot.interactions import StudentInteraction, YesNoInteraction
from bot.interactions.errors import NoReplyException
from bot.db.services import UserService


class StudentProcessOutput:
Expand Down Expand Up @@ -68,7 +69,8 @@ async def walk_through_welcome(member: discord.Member):
"""
is_student_view = YesNoInteraction()
original_message: discord.Message = await member.send(
embed=util.get_welcome_instruction("Êtes-vous un étudiant?"), view=is_student_view
embed=util.get_welcome_instruction("Êtes-vous un étudiant?"),
view=is_student_view,
)
is_student = await is_student_view.start()

Expand All @@ -93,7 +95,11 @@ async def walk_through_welcome(member: discord.Member):
welcome_user.program = process_student_result.program
welcome_user.is_it_student = process_student_result.is_it_student

confirmation_embed.add_field(name="Numéro étudiant:", value=process_student_result.student_number, inline=False)
confirmation_embed.add_field(
name="Numéro étudiant:",
value=process_student_result.student_number,
inline=False,
)
if process_student_result.program is not None:
confirmation_embed.add_field(name="Programme:", value=process_student_result.program, inline=False)
else:
Expand Down Expand Up @@ -170,7 +176,10 @@ async def __process_email(member: discord.Member, original_message: discord.Mess

async def __process_teacher(member: discord.Member, original_message: discord.Message):
current_view = YesNoInteraction()
await original_message.edit(embed=util.get_welcome_instruction("Êtes-vous un professeur?"), view=current_view)
await original_message.edit(
embed=util.get_welcome_instruction("Êtes-vous un professeur?"),
view=current_view,
)
is_teacher = await current_view.start()

if is_teacher is None:
Expand Down Expand Up @@ -198,7 +207,8 @@ async def __process_student(member: discord.Member, original_message: discord.Me

is_info_view = YesNoInteraction()
await original_message.edit(
embed=util.get_welcome_instruction("Êtes-vous un étudiant en informatique?"), view=is_info_view
embed=util.get_welcome_instruction("Êtes-vous un étudiant en informatique?"),
view=is_info_view,
)
is_it_student = await is_info_view.start()

Expand All @@ -209,7 +219,10 @@ async def __process_student(member: discord.Member, original_message: discord.Me

if is_it_student:
student_view = StudentInteraction()
await original_message.edit(embed=util.get_welcome_instruction("Quel est votre programme?"), view=student_view)
await original_message.edit(
embed=util.get_welcome_instruction("Quel est votre programme?"),
view=student_view,
)
program = await student_view.start()

await original_message.edit(view=None)
Expand All @@ -233,16 +246,26 @@ async def create_welcome_embed(member: discord.User, adept_member: AdeptMember):
The new member's information.
"""
embed = discord.Embed(
title="Nouveau membre dans ADEPT-Informatique", color=0xF9E18B, timestamp=discord.utils.utcnow()
title="Nouveau membre dans ADEPT-Informatique",
color=0xF9E18B,
timestamp=discord.utils.utcnow(),
)
embed.add_field(name="Nom:", value=adept_member.name, inline=False)
embed.add_field(name="Email:", value=adept_member.email, inline=False)
embed.add_field(name="Numéro étudiant:", value=adept_member.student_id, inline=False)
embed.add_field(name="Étudiant:", value="Oui" if adept_member.is_student else "Non", inline=False)
embed.add_field(name="Professeur:", value="Oui" if adept_member.is_teacher else "Non", inline=False)
embed.add_field(
name="Étudiant:",
value="Oui" if adept_member.is_student else "Non",
inline=False,
)
embed.add_field(
name="Professeur:",
value="Oui" if adept_member.is_teacher else "Non",
inline=False,
)
embed.add_field(
name="Programme:",
value=adept_member.program if adept_member.is_it_student else "N'est pas en informatique",
value=(adept_member.program if adept_member.is_it_student else "N'est pas en informatique"),
inline=False,
)
embed.set_footer(text=f"ID: {member.id}")
Expand Down Expand Up @@ -279,7 +302,13 @@ async def process_welcome_result(member: discord.Member, result: AdeptMember):
roles = [
role
for role in member.roles
if role.id not in (configs.PROG_ROLE, configs.NETWORK_ROLE, configs.DECBAC_ROLE, configs.TEACHER_ROLE)
if role.id
not in (
configs.PROG_ROLE,
configs.NETWORK_ROLE,
configs.DECBAC_ROLE,
configs.TEACHER_ROLE,
)
]
if role is not None:
roles.append(role)
Expand Down
9 changes: 6 additions & 3 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
FROM python:3.11-slim
FROM python:3.12-slim

WORKDIR /usr/src/app

# Copy project files to the container
COPY . .
COPY requirements.txt .

# Install the dependencies
RUN python3 -m pip install -r ./requirements.txt

# Copy project files to the container
COPY . .

# Start the application
CMD ["python3", "run.py"]
CMD ["python3", "-O", "run.py"]

0 comments on commit 47a7475

Please sign in to comment.