1212from discord .ext .commands .cooldowns import BucketType
1313from discord .ext .commands .view import StringView
1414
15- from core import checks
15+ from core import blocklist , checks
1616from core .blocklist import BlockType
1717from core .models import DMDisabled , PermissionLevel , SimilarCategoryConverter , getLogger
1818from core .paginator import EmbedPaginatorSession
@@ -1646,57 +1646,34 @@ async def contact(
16461646 async def blocked (self , ctx ):
16471647 """Retrieve a list of blocked users."""
16481648
1649- roles , users , now = [], [], discord . utils . utcnow ()
1649+ roles , users = [], []
16501650
1651- blocked_users = list (self .bot .blocked_users .items ())
1652- for id_ , data in blocked_users :
1653- blocked_by_id = data ["blocked_by" ]
1654- blocked_at = parser .parse (data ["blocked_at" ])
1655- human_blocked_at = discord .utils .format_dt (blocked_at , style = "R" )
1656- if "until" in data :
1657- blocked_until = parser .parse (data ["until" ])
1658- human_blocked_until = discord .utils .format_dt (blocked_until , style = "R" )
1659- else :
1660- blocked_until = human_blocked_until = "Permanent"
1661-
1662- if isinstance (blocked_until , datetime .datetime ) and blocked_until < now :
1663- self .bot .blocked_users .pop (str (id_ ))
1664- logger .debug ("No longer blocked, user %s." , id_ )
1665- continue
1666-
1667- string = f"<@{ id_ } > ({ human_blocked_until } )"
1668- string += f"\n - Issued { human_blocked_at } by <@{ blocked_by_id } >"
1651+ blocked : list [blocklist .BlocklistItem ] = await self .bot .blocklist .get_all_blocks ()
16691652
1670- reason = data .get ("reason" )
1671- if reason :
1672- string += f"\n - Blocked for { reason } "
1673-
1674- users .append (string + "\n " )
1653+ for item in blocked :
1654+ human_blocked_at = discord .utils .format_dt (item .timestamp , style = "R" )
1655+ if item .expires_at is not None :
1656+ human_blocked_until = discord .utils .format_dt (item .expires_at , style = "R" )
1657+ else :
1658+ human_blocked_until = "Permanent"
16751659
1676- blocked_roles = list (self .bot .blocked_roles .items ())
1677- for id_ , data in blocked_roles :
1678- blocked_by_id = data ["blocked_by" ]
1679- blocked_at = parser .parse (data ["blocked_at" ])
1680- human_blocked_at = discord .utils .format_dt (blocked_at , style = "R" )
1681- if "until" in data :
1682- blocked_until = parser .parse (data ["until" ])
1683- human_blocked_until = discord .utils .format_dt (blocked_until , style = "R" )
1660+ if item .type == blocklist .BlockType .USER :
1661+ string = f"<@{ item .id } >"
16841662 else :
1685- blocked_until = human_blocked_until = "Permanent "
1663+ string = f"<@& { item . id } > "
16861664
1687- if isinstance (blocked_until , datetime .datetime ) and blocked_until < now :
1688- self .bot .blocked_users .pop (str (id_ ))
1689- logger .debug ("No longer blocked, user %s." , id_ )
1690- continue
1665+ string += f" ({ human_blocked_until } )"
16911666
1692- string = f"<@&{ id_ } > ({ human_blocked_until } )"
1693- string += f"\n - Issued { human_blocked_at } by <@{ blocked_by_id } >"
1667+ string += f"\n - Issued { human_blocked_at } by <@{ item .blocking_user_id } >"
16941668
1695- reason = data . get ( " reason" )
1696- if reason :
1697- string += f "\n - Blocked for { reason } "
1669+ if item . reason is not None :
1670+ string += f" \n - Blocked for { item . reason } "
1671+ string += "\n "
16981672
1699- roles .append (string + "\n " )
1673+ if item .type == blocklist .BlockType .USER :
1674+ users .append (string )
1675+ elif item .type == blocklist .BlockType .ROLE :
1676+ roles .append (string )
17001677
17011678 user_embeds = [discord .Embed (title = "Blocked Users" , color = self .bot .main_color , description = "" )]
17021679
@@ -1714,7 +1691,7 @@ async def blocked(self, ctx):
17141691 else :
17151692 embed .description += line
17161693 else :
1717- user_embeds [0 ].description = "Currently there are no blocked users ."
1694+ user_embeds [0 ].description = "No users are currently blocked."
17181695
17191696 if len (user_embeds ) > 1 :
17201697 for n , em in enumerate (user_embeds ):
@@ -1737,7 +1714,7 @@ async def blocked(self, ctx):
17371714 else :
17381715 embed .description += line
17391716 else :
1740- role_embeds [- 1 ].description = "Currently there are no blocked roles ."
1717+ role_embeds [- 1 ].description = "No roles are currently blocked."
17411718
17421719 if len (role_embeds ) > 1 :
17431720 for n , em in enumerate (role_embeds ):
0 commit comments