Skip to content

Commit

Permalink
Merge branch 'main' into voice-verify-pings
Browse files Browse the repository at this point in the history
  • Loading branch information
Xithrius authored Jun 21, 2021
2 parents 3b11890 + e74c6bf commit b6279c7
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 17 deletions.
2 changes: 1 addition & 1 deletion bot/exts/help_channels/_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ async def notify_session_participants(self, message: discord.Message) -> None:
await bot_commands_channel.send(
f"{message.author.mention} {constants.Emojis.cross_mark} "
"To receive updates on help channels you're active in, enable your DMs.",
delete_after=RedirectOutput.delete_after
delete_after=RedirectOutput.delete_delay
)
return

Expand Down
5 changes: 1 addition & 4 deletions bot/exts/info/information.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,6 @@ async def create_user_embed(self, ctx: Context, user: FetchedMember) -> Embed:
if is_set and (emoji := getattr(constants.Emojis, f"badge_{badge}", None)):
badges.append(emoji)

activity = await self.user_messages(user)

if on_server:
joined = time_since(user.joined_at, max_units=3)
roles = ", ".join(role.mention for role in user.roles[1:])
Expand Down Expand Up @@ -272,8 +270,7 @@ async def create_user_embed(self, ctx: Context, user: FetchedMember) -> Embed:

# Show more verbose output in moderation channels for infractions and nominations
if is_mod_channel(ctx.channel):
fields.append(activity)

fields.append(await self.user_messages(user))
fields.append(await self.expanded_user_infraction_counts(user))
fields.append(await self.user_nomination_counts(user))
else:
Expand Down
22 changes: 11 additions & 11 deletions bot/exts/recruitment/talentpool/_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def schedule_review(self, user_id: int) -> None:

async def post_review(self, user_id: int, update_database: bool) -> None:
"""Format the review of a user and post it to the nomination voting channel."""
review, seen_emoji = await self.make_review(user_id)
review, reviewed_emoji = await self.make_review(user_id)
if not review:
return

Expand All @@ -88,16 +88,16 @@ async def post_review(self, user_id: int, update_database: bool) -> None:
await pin_no_system_message(messages[0])

last_message = messages[-1]
if seen_emoji:
for reaction in (seen_emoji, "\N{THUMBS UP SIGN}", "\N{THUMBS DOWN SIGN}"):
if reviewed_emoji:
for reaction in (reviewed_emoji, "\N{THUMBS UP SIGN}", "\N{THUMBS DOWN SIGN}"):
await last_message.add_reaction(reaction)

if update_database:
nomination = self._pool.watched_users.get(user_id)
await self.bot.api_client.patch(f"{self._pool.api_endpoint}/{nomination['id']}", json={"reviewed": True})

async def make_review(self, user_id: int) -> typing.Tuple[str, Optional[Emoji]]:
"""Format a generic review of a user and return it with the seen emoji."""
"""Format a generic review of a user and return it with the reviewed emoji."""
log.trace(f"Formatting the review of {user_id}")

# Since `watched_users` is a defaultdict, we should take care
Expand Down Expand Up @@ -127,15 +127,15 @@ async def make_review(self, user_id: int) -> typing.Tuple[str, Optional[Emoji]]:

review_body = await self._construct_review_body(member)

seen_emoji = self._random_ducky(guild)
reviewed_emoji = self._random_ducky(guild)
vote_request = (
"*Refer to their nomination and infraction histories for further details*.\n"
f"*Please react {seen_emoji} if you've seen this post."
" Then react :+1: for approval, or :-1: for disapproval*."
f"*Please react {reviewed_emoji} once you have reviewed this user,"
" and react :+1: for approval, or :-1: for disapproval*."
)

review = "\n\n".join((opening, current_nominations, review_body, vote_request))
return review, seen_emoji
return review, reviewed_emoji

async def archive_vote(self, message: PartialMessage, passed: bool) -> None:
"""Archive this vote to #nomination-archive."""
Expand Down Expand Up @@ -163,7 +163,7 @@ async def archive_vote(self, message: PartialMessage, passed: bool) -> None:
user_id = int(MENTION_RE.search(content).group(1))

# Get reaction counts
seen = await count_unique_users_reaction(
reviewed = await count_unique_users_reaction(
messages[0],
lambda r: "ducky" in str(r) or str(r) == "\N{EYES}",
count_bots=False
Expand All @@ -188,7 +188,7 @@ async def archive_vote(self, message: PartialMessage, passed: bool) -> None:

embed_content = (
f"{result} on {timestamp}\n"
f"With {seen} {Emojis.ducky_dave} {upvotes} :+1: {downvotes} :-1:\n\n"
f"With {reviewed} {Emojis.ducky_dave} {upvotes} :+1: {downvotes} :-1:\n\n"
f"{stripped_content}"
)

Expand Down Expand Up @@ -357,7 +357,7 @@ async def _previous_nominations_review(self, member: Member) -> Optional[str]:

@staticmethod
def _random_ducky(guild: Guild) -> Union[Emoji, str]:
"""Picks a random ducky emoji to be used to mark the vote as seen. If no duckies found returns :eyes:."""
"""Picks a random ducky emoji. If no duckies found returns :eyes:."""
duckies = [emoji for emoji in guild.emojis if emoji.name.startswith("ducky")]
if not duckies:
return ":eyes:"
Expand Down
28 changes: 28 additions & 0 deletions bot/resources/tags/dunder-methods.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
**Dunder methods**

Double-underscore methods, or "dunder" methods, are special methods defined in a class that are invoked implicitly. Like the name suggests, they are prefixed and suffixed with dunders. You've probably already seen some, such as the `__init__` dunder method, also known as the "constructor" of a class, which is implicitly invoked when you instantiate an instance of a class.

When you create a new class, there will be default dunder methods inherited from the `object` class. However, we can override them by redefining these methods within the new class. For example, the default `__init__` method from `object` doesn't take any arguments, so we almost always override that to fit our needs.

Other common dunder methods to override are `__str__` and `__repr__`. `__repr__` is the developer-friendly string representation of an object - usually the syntax to recreate it - and is implicitly called on arguments passed into the `repr` function. `__str__` is the user-friendly string representation of an object, and is called by the `str` function. Note here that, if not overriden, the default `__str__` invokes `__repr__` as a fallback.

```py
class Foo:
def __init__(self, value): # constructor
self.value = value
def __str__(self):
return f"This is a Foo object, with a value of {self.value}!" # string representation
def __repr__(self):
return f"Foo({self.value!r})" # way to recreate this object


bar = Foo(5)

# print also implicitly calls __str__
print(bar) # Output: This is a Foo object, with a value of 5!

# dev-friendly representation
print(repr(bar)) # Output: Foo(5)
```

Another example: did you know that when you use the `<left operand> + <right operand>` syntax, you're implicitly calling `<left operand>.__add__(<right operand>)`? The same applies to other operators, and you can look at the [`operator` built-in module documentation](https://docs.python.org/3/library/operator.html) for more information!
2 changes: 1 addition & 1 deletion config-default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ anti_spam:

chars:
interval: 5
max: 3_000
max: 4_200

discord_emojis:
interval: 10
Expand Down

0 comments on commit b6279c7

Please sign in to comment.