1
1
import asyncio
2
- import datetime
3
2
import re
4
3
from datetime import timezone
5
4
from itertools import zip_longest
12
11
from discord .ext .commands .cooldowns import BucketType
13
12
from discord .ext .commands .view import StringView
14
13
15
- from core import checks
14
+ from core import blocklist , checks
16
15
from core .blocklist import BlockType
17
16
from core .models import DMDisabled , PermissionLevel , SimilarCategoryConverter , getLogger
18
17
from core .paginator import EmbedPaginatorSession
@@ -1646,57 +1645,34 @@ async def contact(
1646
1645
async def blocked (self , ctx ):
1647
1646
"""Retrieve a list of blocked users."""
1648
1647
1649
- roles , users , now = [], [], discord . utils . utcnow ()
1648
+ roles , users = [], []
1650
1649
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 } >"
1650
+ blocked : list [blocklist .BlocklistItem ] = await self .bot .blocklist .get_all_blocks ()
1669
1651
1670
- reason = data .get ("reason" )
1671
- if reason :
1672
- string += f"\n - Blocked for { reason } "
1673
-
1674
- users .append (string + "\n " )
1652
+ for item in blocked :
1653
+ human_blocked_at = discord .utils .format_dt (item .timestamp , style = "R" )
1654
+ if item .expires_at is not None :
1655
+ human_blocked_until = discord .utils .format_dt (item .expires_at , style = "R" )
1656
+ else :
1657
+ human_blocked_until = "Permanent"
1675
1658
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" )
1659
+ if item .type == blocklist .BlockType .USER :
1660
+ string = f"<@{ item .id } >"
1684
1661
else :
1685
- blocked_until = human_blocked_until = "Permanent "
1662
+ string = f"<@& { item . id } > "
1686
1663
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
1664
+ string += f" ({ human_blocked_until } )"
1691
1665
1692
- string = f"<@&{ id_ } > ({ human_blocked_until } )"
1693
- string += f"\n - Issued { human_blocked_at } by <@{ blocked_by_id } >"
1666
+ string += f"\n - Issued { human_blocked_at } by <@{ item .blocking_user_id } >"
1694
1667
1695
- reason = data . get ( " reason" )
1696
- if reason :
1697
- string += f "\n - Blocked for { reason } "
1668
+ if item . reason is not None :
1669
+ string += f" \n - Blocked for { item . reason } "
1670
+ string += "\n "
1698
1671
1699
- roles .append (string + "\n " )
1672
+ if item .type == blocklist .BlockType .USER :
1673
+ users .append (string )
1674
+ elif item .type == blocklist .BlockType .ROLE :
1675
+ roles .append (string )
1700
1676
1701
1677
user_embeds = [discord .Embed (title = "Blocked Users" , color = self .bot .main_color , description = "" )]
1702
1678
@@ -1714,7 +1690,7 @@ async def blocked(self, ctx):
1714
1690
else :
1715
1691
embed .description += line
1716
1692
else :
1717
- user_embeds [0 ].description = "Currently there are no blocked users ."
1693
+ user_embeds [0 ].description = "No users are currently blocked."
1718
1694
1719
1695
if len (user_embeds ) > 1 :
1720
1696
for n , em in enumerate (user_embeds ):
@@ -1737,7 +1713,7 @@ async def blocked(self, ctx):
1737
1713
else :
1738
1714
embed .description += line
1739
1715
else :
1740
- role_embeds [- 1 ].description = "Currently there are no blocked roles ."
1716
+ role_embeds [- 1 ].description = "No roles are currently blocked."
1741
1717
1742
1718
if len (role_embeds ) > 1 :
1743
1719
for n , em in enumerate (role_embeds ):
0 commit comments