Skip to content
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
1 change: 1 addition & 0 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ async def setup_hook(self) -> None:
"src.discord.staff.censor",
"src.discord.staff.tags",
"src.discord.staff.events",
"src.discord.staff.usercleanup",
"src.discord.embed",
"src.discord.membercommands",
"src.discord.devtools",
Expand Down
6 changes: 0 additions & 6 deletions src/discord/censor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
CATEGORY_STAFF,
CHANNEL_SUPPORT,
DISCORD_INVITE_ENDINGS,
ROLE_UC,
)

if TYPE_CHECKING:
Expand Down Expand Up @@ -241,11 +240,6 @@ async def on_message_edit(self, before: discord.Message, after: discord.Message)

@commands.Cog.listener()
async def on_member_join(self, member: discord.Member):
# Give new user confirmed role
unconfirmed_role = discord.utils.get(member.guild.roles, name=ROLE_UC)
assert isinstance(unconfirmed_role, discord.Role)
await member.add_roles(unconfirmed_role)

# Check to see if user's name is innapropriate
name = member.name
if await self.censor_needed(name):
Expand Down
5 changes: 3 additions & 2 deletions src/discord/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
##############
# CONSTANTS
##############
DISCORD_DEFAULT_INVITE_ENDING = "scioly"
DISCORD_INVITE_ENDINGS = [
"9Z5zKtV",
"C9PGV6h",
Expand All @@ -16,7 +17,7 @@
"gh3aXbq",
"skGQXd4",
"RnkqUbK",
"scioly",
DISCORD_DEFAULT_INVITE_ENDING,
]

# Roles
Expand All @@ -30,7 +31,6 @@
ROLE_AT = "All Invitationals"
ROLE_GAMES = "Games"
ROLE_MR = "Member"
ROLE_UC = "Unconfirmed"
ROLE_DIV_A = "Division A"
ROLE_DIV_B = "Division B"
ROLE_DIV_C = "Division C"
Expand Down Expand Up @@ -116,6 +116,7 @@
DISCORD_AUTOCOMPLETE_MAX_ENTRIES = 25
# The maximum number of options that can be passed into a discord.ui.Select
DISCORD_SELECT_MAX_OPTIONS = 20
DISCORD_LONG_TERM_RATE_LIMIT = 1 # 5 requests / 5 seconds, so might as well keep 1 request / 1 second for long running tasks

##############
# VARIABLES
Expand Down
152 changes: 82 additions & 70 deletions src/discord/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Logs actions that happened on the Scioly.org Discord server to specific information
buckets, such as a Discord channel or database log.
"""

from __future__ import annotations

import logging
Expand All @@ -19,7 +20,6 @@
CHANNEL_EDITEDM,
CHANNEL_LEAVE,
CHANNEL_LOUNGE,
ROLE_UC,
)

if TYPE_CHECKING:
Expand Down Expand Up @@ -54,9 +54,11 @@ async def send_to_dm_log(self, message: discord.Message):
# Create an embed containing the direct message info and send it to the log channel
message_embed = discord.Embed(
title=":speech_balloon: Incoming Direct Message to Pi-Bot",
description=message.content
if len(message.content) > 0
else "This message contained no content.",
description=(
message.content
if len(message.content) > 0
else "This message contained no content."
),
color=discord.Color.brand_green(),
)
message_embed.add_field(
Expand All @@ -72,11 +74,13 @@ async def send_to_dm_log(self, message: discord.Message):
)
message_embed.add_field(
name="Attachments",
value=" | ".join(
[f"**{a.filename}**: [Link]({a.url})" for a in message.attachments],
)
if len(message.attachments) > 0
else "None",
value=(
" | ".join(
[f"**{a.filename}**: [Link]({a.url})" for a in message.attachments],
)
if len(message.attachments) > 0
else "None"
),
inline=True,
)
await dm_channel.send(embed=message_embed)
Expand Down Expand Up @@ -117,16 +121,9 @@ async def on_member_remove(self, member: discord.Member):
member.guild.text_channels,
name=CHANNEL_LEAVE,
)
unconfirmed_role = discord.utils.get(member.guild.roles, name=ROLE_UC)
assert isinstance(leave_channel, discord.TextChannel)
assert isinstance(unconfirmed_role, discord.Role)

if unconfirmed_role in member.roles:
unconfirmed_statement = ":white_check_mark:"
embed = discord.Embed(color=discord.Color.yellow())
else:
unconfirmed_statement = ":x:"
embed = discord.Embed(color=discord.Color.brand_red())
embed = discord.Embed(color=discord.Color.brand_red())

embed.title = "Member Leave"

Expand All @@ -141,7 +138,6 @@ async def on_member_remove(self, member: discord.Member):
)

embed.add_field(name="Joined At", value=joined_at)
embed.add_field(name="Unconfirmed", value=unconfirmed_statement)
await leave_channel.send(embed=embed)

@commands.Cog.listener()
Expand Down Expand Up @@ -382,35 +378,41 @@ async def log_edit_message_payload(self, payload):
},
{
"name": "Attachments",
"value": " | ".join(
[
f"**{a.filename}**: [Link]({a.url})"
for a in message.attachments
],
)
if len(message.attachments) > 0
else "None",
"value": (
" | ".join(
[
f"**{a.filename}**: [Link]({a.url})"
for a in message.attachments
],
)
if len(message.attachments) > 0
else "None"
),
"inline": "False",
},
{
"name": "Past Content",
"value": message.content[:1024]
if len(message.content) > 0
else "None",
"value": (
message.content[:1024] if len(message.content) > 0 else "None"
),
"inline": "False",
},
{
"name": "New Content",
"value": message_now.content[:1024]
if len(message_now.content) > 0
else "None",
"value": (
message_now.content[:1024]
if len(message_now.content) > 0
else "None"
),
"inline": "False",
},
{
"name": "Embed",
"value": "\n".join([str(e.to_dict()) for e in message.embeds])
if len(message.embeds) > 0
else "None",
"value": (
"\n".join([str(e.to_dict()) for e in message.embeds])
if len(message.embeds) > 0
else "None"
),
"inline": "False",
},
]
Expand Down Expand Up @@ -454,37 +456,43 @@ async def log_edit_message_payload(self, payload):
},
{
"name": "Edited At",
"value": discord.utils.format_dt(message_now.edited_at, "R")
if message_now.edited_at is not None
else "Never",
"value": (
discord.utils.format_dt(message_now.edited_at, "R")
if message_now.edited_at is not None
else "Never"
),
"inline": True,
},
{
"name": "New Content",
"value": message_now.content[:1024]
if len(message_now.content) > 0
else "None",
"value": (
message_now.content[:1024]
if len(message_now.content) > 0
else "None"
),
"inline": "False",
},
{
"name": "Current Attachments",
"value": " | ".join(
[
f"**{a.filename}**: [Link]({a.url})"
for a in message_now.attachments
],
)
if len(message_now.attachments) > 0
else "None",
"value": (
" | ".join(
[
f"**{a.filename}**: [Link]({a.url})"
for a in message_now.attachments
],
)
if len(message_now.attachments) > 0
else "None"
),
"inline": "False",
},
{
"name": "Current Embed",
"value": "\n".join([str(e.to_dict()) for e in message_now.embeds])[
:1024
]
if len(message_now.embeds) > 0
else "None",
"value": (
"\n".join([str(e.to_dict()) for e in message_now.embeds])[:1024]
if len(message_now.embeds) > 0
else "None"
),
"inline": "False",
},
]
Expand Down Expand Up @@ -551,30 +559,34 @@ async def log_delete_message_payload(self, payload):
},
{
"name": "Attachments",
"value": " | ".join(
[
f"**{a.filename}**: [Link]({a.url})"
for a in message.attachments
],
)
if len(message.attachments) > 0
else "None",
"value": (
" | ".join(
[
f"**{a.filename}**: [Link]({a.url})"
for a in message.attachments
],
)
if len(message.attachments) > 0
else "None"
),
"inline": "False",
},
{
"name": "Content",
"value": str(message.content)[:1024]
if len(message.content) > 0
else "None",
"value": (
str(message.content)[:1024]
if len(message.content) > 0
else "None"
),
"inline": "False",
},
{
"name": "Embed",
"value": "\n".join([str(e.to_dict()) for e in message.embeds])[
:1024
]
if len(message.embeds) > 0
else "None",
"value": (
"\n".join([str(e.to_dict()) for e in message.embeds])[:1024]
if len(message.embeds) > 0
else "None"
),
"inline": "False",
},
]
Expand Down
6 changes: 5 additions & 1 deletion src/discord/membercommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Functionality for most member commands. These commands frequently help members manage
their state on the server, including allowing them to change their roles or subscriptions.
"""

from __future__ import annotations

import datetime
Expand All @@ -22,6 +23,7 @@
CATEGORY_STAFF,
CHANNEL_INVITATIONALS,
CHANNEL_UNSELFMUTE,
DISCORD_DEFAULT_INVITE_ENDING,
ROLE_LH,
ROLE_MR,
ROLE_SELFMUTE,
Expand Down Expand Up @@ -407,7 +409,9 @@ async def invite(self, interaction: discord.Interaction):
Args:
interaction (discord.Interaction): The interaction sent by Discord.
"""
await interaction.response.send_message("https://discord.gg/C9PGV6h")
await interaction.response.send_message(
f"https://discord.gg/{DISCORD_DEFAULT_INVITE_ENDING}",
)

@app_commands.command(
description="Returns a link to the Scioly.org forums.",
Expand Down
Loading
Loading