Skip to content

Commit

Permalink
d.py 2.3 / pomelo changes (#6130)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Oliveira <34169552+Flame442@users.noreply.github.com>
  • Loading branch information
Jackenmen and Flame442 committed Jun 14, 2023
1 parent 3abf4ca commit 10e09d6
Show file tree
Hide file tree
Showing 20 changed files with 216 additions and 173 deletions.
18 changes: 9 additions & 9 deletions docs/cog_guides/mod.rst
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@ modset deletenames
**Description**

Delete all stored usernames and nicknames.
Delete all stored usernames, global display names, and server nicknames.

**Arguments**

- ``<confirmation>``: Whether to delete all stored usernames and nicknames. |bool-input|
- ``<confirmation>``: Whether to delete all stored usernames, global display names, and server nicknames. |bool-input|

.. _mod-command-modset-deleterepeats:

Expand Down Expand Up @@ -469,7 +469,7 @@ modset tracknicknames
**Description**

Toggle whether nickname changes should be tracked.
Toggle whether server nickname changes should be tracked.

This setting will be overridden if trackallnames is disabled.

Expand Down Expand Up @@ -527,7 +527,7 @@ names
**Description**

Show previous names and nicknames of a member.
Show previous usernames, global display names, and server nicknames of a member.

**Arguments**

Expand All @@ -549,14 +549,14 @@ rename
**Description**

Change a member's nickname.
Change a member's server nickname.

Leaving the nickname empty will remove it.
Leaving the nickname argument empty will remove it.

**Arguments**

* ``<member>``: |member-input|
* ``[nickname]``: The new nickname for the member.
* ``[nickname]``: The new server nickname for the member.

.. _mod-command-slowmode:

Expand Down Expand Up @@ -684,9 +684,9 @@ userinfo
Show information about a user.

This includes fields for status, discord join date, server
join date, voice state and previous names/nicknames.
join date, voice state and previous usernames/global display names/nicknames.

If the user has no roles, previous names or previous nicknames,
If the user has no roles, previous usernames, global display names, or server nicknames,
these fields will be omitted.

**Arguments**
Expand Down
10 changes: 6 additions & 4 deletions redbot/cogs/admin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ async def editrole_colour(
`[p]editrole colour Test #ff9900`
"""
author = ctx.author
reason = "{}({}) changed the colour of role '{}'".format(author.name, author.id, role.name)
reason = _("{author} ({author.id}) changed the colour of role '{role.name}'").format(
author=author, role=role.name
)

if not self.pass_user_hierarchy_check(ctx, role):
await ctx.send(_(ROLE_USER_HIERARCHY_ISSUE).format(role=role))
Expand Down Expand Up @@ -303,9 +305,9 @@ async def edit_role_name(self, ctx: commands.Context, role: discord.Role, name:
"""
author = ctx.message.author
old_name = role.name
reason = "{}({}) changed the name of role '{}' to '{}'".format(
author.name, author.id, old_name, name
)
reason = _(
"{author} ({author.id}) changed the name of role '{old_name}' to '{name}'"
).format(author=author, old_name=old_name, name=name)

if not self.pass_user_hierarchy_check(ctx, role):
await ctx.send(_(ROLE_USER_HIERARCHY_ISSUE).format(role=role))
Expand Down
4 changes: 3 additions & 1 deletion redbot/cogs/audio/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ async def global_unique_user_finder(
return user

maybe_matches = []
async for user in AsyncIter(bot.users).filter(lambda u: u.name == arg or f"{u}" == arg):
async for user in AsyncIter(bot.users).filter(
lambda u: u.name == arg or u.global_name == arg or f"{u}" == arg
):
maybe_matches.append(user)

if guild is not None:
Expand Down
26 changes: 12 additions & 14 deletions redbot/cogs/audio/core/commands/miscellaneous.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,32 +105,30 @@ async def command_percent(self, ctx: commands.Context):
queue_tracks = player.queue
requesters = {"total": 0, "users": {}}

async def _usercount(req_username):
if req_username in requesters["users"]:
requesters["users"][req_username]["songcount"] += 1
async def _usercount(req_user_handle):
if req_user_handle in requesters["users"]:
requesters["users"][req_user_handle]["songcount"] += 1
requesters["total"] += 1
else:
requesters["users"][req_username] = {}
requesters["users"][req_username]["songcount"] = 1
requesters["users"][req_user_handle] = {}
requesters["users"][req_user_handle]["songcount"] = 1
requesters["total"] += 1

async for track in AsyncIter(queue_tracks):
req_username = "{}#{}".format(track.requester.name, track.requester.discriminator)
await _usercount(req_username)
req_user_handle = str(track.requester)
await _usercount(req_user_handle)

try:
req_username = "{}#{}".format(
player.current.requester.name, player.current.requester.discriminator
)
await _usercount(req_username)
req_user_handle = str(player.current.requester)
await _usercount(req_user_handle)
except AttributeError:
return await self.send_embed_msg(ctx, title=_("There's nothing in the queue."))

async for req_username in AsyncIter(requesters["users"]):
percentage = float(requesters["users"][req_username]["songcount"]) / float(
async for req_user_handle in AsyncIter(requesters["users"]):
percentage = float(requesters["users"][req_user_handle]["songcount"]) / float(
requesters["total"]
)
requesters["users"][req_username]["percent"] = round(percentage * 100, 1)
requesters["users"][req_user_handle]["percent"] = round(percentage * 100, 1)

top_queue_users = heapq.nlargest(
20,
Expand Down
6 changes: 5 additions & 1 deletion redbot/cogs/audio/core/events/dpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"manage_nicknames": _("Manage Nicknames"),
"manage_roles": _("Manage Roles"),
"manage_webhooks": _("Manage Webhooks"),
"manage_emojis": _("Manage Emojis"),
"manage_expressions": _("Manage Expressions"),
"use_application_commands": _("Use Application Commands"),
"request_to_speak": _("Request to Speak"),
"manage_events": _("Manage Events"),
Expand All @@ -72,6 +72,10 @@
"send_messages_in_threads": _("Send Messages in Threads"),
"start_embedded_activities": _("Start Activities"),
"moderate_members": _("Moderate Member"),
"use_soundboard": _("Use Soundboard"),
"create_expressions": _("Create Expressions"),
"use_external_sounds": _("Use External Sounds"),
"send_voice_messages": _("Send Voice Messages"),
}

DANGEROUS_COMMANDS = {
Expand Down
44 changes: 20 additions & 24 deletions redbot/cogs/cleanup/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ def check(m):
)
to_delete.append(ctx.message)

reason = "{}({}) deleted {} messages containing '{}' in channel #{}.".format(
author.name,
reason = "{} ({}) deleted {} messages containing '{}' in channel #{}.".format(
author,
author.id,
humanize_number(len(to_delete), override_locale="en_us"),
text,
Expand Down Expand Up @@ -295,10 +295,10 @@ def check(m):
to_delete.append(ctx.message)

reason = (
"{}({}) deleted {} messages"
" made by {}({}) in channel #{}."
"{} ({}) deleted {} messages"
" made by {} ({}) in channel #{}."
"".format(
author.name,
author,
author.id,
humanize_number(len(to_delete), override_locale="en_US"),
member or "???",
Expand Down Expand Up @@ -353,8 +353,8 @@ async def after(
channel=channel, number=None, after=after, delete_pinned=delete_pinned
)

reason = "{}({}) deleted {} messages in channel #{}.".format(
author.name,
reason = "{} ({}) deleted {} messages in channel #{}.".format(
author,
author.id,
humanize_number(len(to_delete), override_locale="en_US"),
channel.name,
Expand Down Expand Up @@ -409,8 +409,8 @@ async def before(
)
to_delete.append(ctx.message)

reason = "{}({}) deleted {} messages in channel #{}.".format(
author.name,
reason = "{} ({}) deleted {} messages in channel #{}.".format(
author,
author.id,
humanize_number(len(to_delete), override_locale="en_US"),
channel.name,
Expand Down Expand Up @@ -462,8 +462,8 @@ async def between(
channel=channel, before=mtwo, after=mone, delete_pinned=delete_pinned
)
to_delete.append(ctx.message)
reason = "{}({}) deleted {} messages in channel #{}.".format(
author.name,
reason = "{} ({}) deleted {} messages in channel #{}.".format(
author,
author.id,
humanize_number(len(to_delete), override_locale="en_US"),
channel.name,
Expand Down Expand Up @@ -504,8 +504,8 @@ async def messages(
)
to_delete.append(ctx.message)

reason = "{}({}) deleted {} messages in channel #{}.".format(
author.name, author.id, len(to_delete), channel.name
reason = "{} ({}) deleted {} messages in channel #{}.".format(
author, author.id, len(to_delete), channel.name
)
log.info(reason)

Expand Down Expand Up @@ -585,10 +585,10 @@ def check(m):
to_delete.append(ctx.message)

reason = (
"{}({}) deleted {}"
"{} ({}) deleted {}"
" command messages in channel #{}."
"".format(
author.name,
author,
author.id,
humanize_number(len(to_delete), override_locale="en_US"),
channel.name,
Expand Down Expand Up @@ -670,15 +670,11 @@ def check(m):
else:
channel_name = str(channel)

reason = (
"{}({}) deleted {} messages "
"sent by the bot in {}."
"".format(
author.name,
author.id,
humanize_number(len(to_delete), override_locale="en_US"),
channel_name,
)
reason = "{} ({}) deleted {} messages sent by the bot in {}.".format(
author,
author.id,
humanize_number(len(to_delete), override_locale="en_US"),
channel_name,
)
log.info(reason)

Expand Down
4 changes: 3 additions & 1 deletion redbot/cogs/economy/economy.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,9 @@ async def leaderboard(self, ctx: commands.Context, top: int = 10, show_global: b
if show_global and await bank.is_global():
# show_global is only applicable if bank is global
bank_sorted = await bank.get_leaderboard(positions=top, guild=None)
base_embed.set_author(name=ctx.bot.user.name, icon_url=ctx.bot.user.display_avatar)
base_embed.set_author(
name=ctx.bot.user.display_name, icon_url=ctx.bot.user.display_avatar
)
else:
bank_sorted = await bank.get_leaderboard(positions=top, guild=guild)
if guild:
Expand Down
2 changes: 1 addition & 1 deletion redbot/cogs/general/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def _bitsize(num: int):
joined_on = _(
"{bot_name} joined this server on {bot_join}. That's over {since_join} days ago!"
).format(
bot_name=ctx.bot.user.name,
bot_name=ctx.bot.user.display_name,
bot_join=guild.me.joined_at.strftime("%d %b %Y %H:%M:%S"),
since_join=humanize_number((ctx.message.created_at - guild.me.joined_at).days),
)
Expand Down
35 changes: 20 additions & 15 deletions redbot/cogs/mod/events.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
from datetime import timezone
from collections import defaultdict, deque
from typing import List, Optional

import discord
from redbot.core import i18n, modlog, commands
Expand Down Expand Up @@ -158,21 +159,31 @@ async def on_message(self, message):
if not deleted:
await self.check_mention_spam(message)

@staticmethod
def _update_past_names(name: str, name_list: List[Optional[str]]) -> None:
while None in name_list: # clean out null entries from a bug
name_list.remove(None)
if name in name_list:
# Ensure order is maintained without duplicates occurring
name_list.remove(name)
name_list.append(name)
while len(name_list) > 20:
name_list.pop(0)

@commands.Cog.listener()
async def on_user_update(self, before: discord.User, after: discord.User):
if before.name != after.name:
track_all_names = await self.config.track_all_names()
if not track_all_names:
return
async with self.config.user(before).past_names() as name_list:
while None in name_list: # clean out null entries from a bug
name_list.remove(None)
if before.name in name_list:
# Ensure order is maintained without duplicates occurring
name_list.remove(before.name)
name_list.append(before.name)
while len(name_list) > 20:
name_list.pop(0)
self._update_past_names(before.name, name_list)
if before.display_name != after.display_name:
track_all_names = await self.config.track_all_names()
if not track_all_names:
return
async with self.config.user(before).past_display_names() as name_list:
self._update_past_names(before.display_name, name_list)

@commands.Cog.listener()
async def on_member_update(self, before: discord.Member, after: discord.Member):
Expand All @@ -185,10 +196,4 @@ async def on_member_update(self, before: discord.Member, after: discord.Member):
if (not track_all_names) or (not track_nicknames):
return
async with self.config.member(before).past_nicks() as nick_list:
while None in nick_list: # clean out null entries from a bug
nick_list.remove(None)
if before.nick in nick_list:
nick_list.remove(before.nick)
nick_list.append(before.nick)
while len(nick_list) > 20:
nick_list.pop(0)
self._update_past_names(before.nick, nick_list)

0 comments on commit 10e09d6

Please sign in to comment.