Skip to content

Commit 879caed

Browse files
authored
Merge pull request #240 from UnifierHQ/dev
3.11.4: Filter improvements
2 parents 7067a92 + 279f80b commit 879caed

File tree

20 files changed

+199
-108
lines changed

20 files changed

+199
-108
lines changed

cogs/badge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ async def badge(self, ctx: Union[nextcord.Interaction, commands.Context], user:
7979

8080
await ctx.send(embed=embed)
8181

82-
@commands.command(hidden=True, aliases=['trust'], description=language.desc('badge.verify'))
82+
@commands.command(aliases=['trust'], description=language.desc('badge.verify'))
8383
@restrictions_legacy.admin()
8484
async def verify(self, ctx, user: nextcord.User):
8585
selector = language.get_selector(ctx)
@@ -94,7 +94,7 @@ async def verify(self, ctx, user: nextcord.User):
9494

9595
await ctx.send(f'{self.bot.ui_emojis.success} ' + selector.fget("success", values={'user': user.name}))
9696

97-
@commands.command(hidden=True, aliases=['untrust'], description=language.desc('badge.unverify'))
97+
@commands.command(aliases=['untrust'], description=language.desc('badge.unverify'))
9898
@restrictions_legacy.admin()
9999
async def unverify(self, ctx, user: nextcord.User):
100100
selector = language.get_selector(ctx)

cogs/bridge.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,6 +1636,7 @@ async def can_send_forward(self, room, content):
16361636

16371637
message_data = {
16381638
'author': '',
1639+
'server': '',
16391640
'bot': False,
16401641
'webhook_id': None,
16411642
'content': content,
@@ -1777,11 +1778,13 @@ async def can_send(self, room, message, content, files, source='discord', is_fir
17771778

17781779
message_data = {
17791780
'author': str(author),
1781+
'server': str(server),
17801782
'bot': is_bot,
17811783
'webhook_id': str(webhook_id) if webhook_id else None,
17821784
'content': content,
17831785
'files': files,
1784-
'suspected_spammer': is_spammer
1786+
'suspected_spammer': is_spammer,
1787+
'is_first': is_first
17851788
}
17861789

17871790
try:
@@ -2864,11 +2867,15 @@ async def stickers_to_urls(stickers):
28642867
else:
28652868
trimmed_length = 0
28662869

2870+
compact_text = f'{author_text} / {trimmed}' if trimmed_length >= 0 else f'{author_text} / \U0001F3DE'
2871+
if len(compact_text) > 80:
2872+
compact_text = compact_text[:-(len(compact_text)-77)] + '...'
2873+
28672874
components.add_rows(
28682875
ui.ActionRow(
28692876
nextcord.ui.Button(
28702877
style=nextcord.ButtonStyle.url,
2871-
label=f'{author_text} / {trimmed}' if trimmed_length >= 0 else f'{author_text} / \U0001F3DE',
2878+
label=compact_text,
28722879
emoji='\U000021AA\U0000FE0F',
28732880
url=url,
28742881
disabled=url is None

cogs/lockdown.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ async def preunload(self, extension):
7979
script = importlib.import_module('utils.' + plugin_name + '_check')
8080
await script.check(self.bot)
8181

82-
@commands.command(hidden=True,aliases=['globalkill'],description=language.desc('lockdown.lockdown'))
82+
@commands.command(aliases=['globalkill'],description=language.desc('lockdown.lockdown'))
8383
@restrictions.owner()
8484
async def lockdown(self,ctx):
8585
selector = language.get_selector(ctx)

cogs/sysmgr.py

Lines changed: 88 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,12 @@ def allow_storage(plugin, cog):
11301130
requires_storage[plugin].append(cog)
11311131

11321132
for cog in cogs:
1133+
if cog == 'system':
1134+
toload.append('system')
1135+
skip.append('system')
1136+
failed.update({cog: 'Cannot manage the entire system plugin, manage the individual modules instead'})
1137+
continue
1138+
11331139
cog_exists = f'{cog}.py' in os.listdir('cogs')
11341140
plugin_exists = f'{cog}.json' in os.listdir('plugins')
11351141

@@ -1512,7 +1518,7 @@ async def system(self, ctx):
15121518
async def system_legacy(self, ctx):
15131519
pass
15141520

1515-
@system_legacy.command(aliases=['reload-services'], hidden=True, description=language.desc('sysmgr.reload_services'))
1521+
@system_legacy.command(aliases=['reload-services'], description=language.desc('sysmgr.reload_services'))
15161522
@restrictions_legacy.owner()
15171523
async def reload_services(self,ctx,*,services=None):
15181524
selector = language.get_selector(ctx)
@@ -1555,9 +1561,8 @@ async def reload_services(self,ctx,*,services=None):
15551561
return await ctx.author.send(selector.get("too_long"))
15561562
await ctx.author.send(f'**{selector.get("fail_logs")}**\n{text}')
15571563

1558-
@system_legacy.command(hidden=True, description=language.desc('sysmgr.eval'))
1559-
@restrictions_legacy.owner()
1560-
async def eval(self, ctx, *, body):
1564+
# Eval command
1565+
async def eval(self, ctx, body):
15611566
selector = language.get_selector(ctx)
15621567
env = {
15631568
'ctx': ctx,
@@ -1613,13 +1618,11 @@ async def eval(self, ctx, *, body):
16131618
else:
16141619
await ctx.send(f'{self.bot.ui_emojis.success} {selector.fget("success", values={"exec_time": exec_time})}\n```\n{value}\n```')
16151620

1616-
@system_legacy.command(aliases=['poweroff'], hidden=True, description=language.desc('sysmgr.shutdown'))
1617-
@restrictions_legacy.owner()
1621+
# Shutdown command
16181622
async def shutdown(self, ctx):
16191623
await self.bot_shutdown(ctx)
16201624

1621-
@system_legacy.command(aliases=['reboot'], hidden=True, description=language.desc('sysmgr.restart'))
1622-
@restrictions_legacy.owner()
1625+
# Restart command
16231626
async def restart(self, ctx):
16241627
await self.bot_shutdown(ctx, restart=True)
16251628

@@ -1648,7 +1651,7 @@ async def modifiers(self, ctx: Union[nextcord.Interaction, commands.Context]):
16481651
))
16491652
return await ctx.send(embed=embed)
16501653

1651-
@system_legacy.command(hidden=True, aliases=['cogs'], description=language.desc('sysmgr.extensions'))
1654+
@system_legacy.command(aliases=['cogs'], description=language.desc('sysmgr.extensions'))
16521655
@restrictions_legacy.owner()
16531656
async def extensions(self, ctx, *, extension=None):
16541657
selector = language.get_selector(ctx)
@@ -1703,22 +1706,21 @@ async def extensions(self, ctx, *, extension=None):
17031706
embed.description = embed.description + selector.get('system_module')
17041707
await ctx.send(embed=embed)
17051708

1706-
@system_legacy.command(hidden=True,description=language.desc('sysmgr.reload'))
1707-
@restrictions_legacy.owner()
1708-
async def reload(self, ctx, *, extensions):
1709+
# Reload command
1710+
async def reload(self, ctx, extensions):
17091711
await self.manage_cog_cmd(ctx, CogAction.reload, extensions)
17101712

1711-
@system_legacy.command(hidden=True,description=language.desc('sysmgr.load'))
1713+
@system_legacy.command(description=language.desc('sysmgr.load'))
17121714
@restrictions_legacy.owner()
17131715
async def load(self, ctx, *, extensions):
17141716
await self.manage_cog_cmd(ctx, CogAction.load, extensions)
17151717

1716-
@system_legacy.command(hidden=True,description='Unloads an extension.')
1718+
@system_legacy.command(description='Unloads an extension.')
17171719
@restrictions_legacy.owner()
17181720
async def unload(self, ctx, *, extensions):
17191721
await self.manage_cog_cmd(ctx, CogAction.unload, extensions)
17201722

1721-
@system_legacy.command(hidden=True,description='Installs a plugin.')
1723+
@system_legacy.command(description='Installs a plugin.')
17221724
@restrictions_legacy.owner()
17231725
async def install(self, ctx, url):
17241726
if self.bot.devmode:
@@ -1974,7 +1976,7 @@ def check(interaction):
19741976
await msg.edit(embed=embed)
19751977
return
19761978

1977-
@system_legacy.command(hidden=True,description='Uninstalls a plugin.')
1979+
@system_legacy.command(description='Uninstalls a plugin.')
19781980
@restrictions_legacy.owner()
19791981
async def uninstall(self, ctx, plugin):
19801982
if self.bot.devmode:
@@ -2068,9 +2070,8 @@ def check(interaction):
20682070
await msg.edit(embed=embed)
20692071
return
20702072

2071-
@system_legacy.command(hidden=True,description='Upgrades Unifier or a plugin.')
2072-
@restrictions_legacy.owner()
2073-
async def upgrade(self, ctx, plugin='system', *, args=''):
2073+
# Upgrade command
2074+
async def upgrade(self, ctx, plugin='system', args=''):
20742075
if self.bot.devmode:
20752076
return await ctx.send('Command unavailable in devmode')
20762077
if not ctx.author.id == self.bot.config['owner']:
@@ -3082,14 +3083,15 @@ def search_filter(query, query_cmd):
30823083

30833084
for index in range(len(cmds)):
30843085
cmd = cmds[index-offset]
3086+
hidden = False
30853087
if permissions=='owner':
30863088
canrun = True
30873089
else:
30883090
try:
30893091
if (
30903092
isinstance(cmd, nextcord.BaseApplicationCommand) or
30913093
isinstance(cmd, nextcord.SlashApplicationSubcommand)
3092-
) and not is_legacy or type(cmd) is commands.command and is_legacy:
3094+
) and not is_legacy or type(cmd) is commands.Command and is_legacy:
30933095
canrun = await cmd.can_run(ctx)
30943096
else:
30953097
canrun = (
@@ -3099,7 +3101,11 @@ def search_filter(query, query_cmd):
30993101
) # legacy commands can only be used by owners and admins
31003102
except:
31013103
canrun = False or cmd.qualified_name in overrides[permissions]
3102-
if not canrun or (cogname=='search' and not search_filter(query,cmd)):
3104+
3105+
if type(cmd) is commands.Command:
3106+
hidden = cmd.hidden
3107+
3108+
if not canrun or (cogname=='search' and not search_filter(query,cmd)) or hidden:
31033109
cmds.pop(index-offset)
31043110
offset += 1
31053111

@@ -3549,7 +3555,7 @@ def check(interaction):
35493555
else:
35503556
await ctx.send(response)
35513557

3552-
@system_legacy.command(name='register-commands', hidden=True, description='Registers commands.')
3558+
@system_legacy.command(name='register-commands', description='Registers commands.')
35533559
@restrictions_legacy.owner()
35543560
async def register_commands(self, ctx, *, args=''):
35553561
selector = language.get_selector(ctx)
@@ -3559,7 +3565,7 @@ async def register_commands(self, ctx, *, args=''):
35593565
await self.bot.sync_application_commands()
35603566
return await ctx.send(selector.get("registered"))
35613567

3562-
@system_legacy.command(hidden=True, description='Views cloud backup status.')
3568+
@system_legacy.command(description='Views cloud backup status.')
35633569
@restrictions_legacy.owner()
35643570
async def cloud(self, ctx):
35653571
selector = language.get_selector(ctx)
@@ -3916,8 +3922,7 @@ async def help_autocomplete(self, ctx: nextcord.Interaction, query: str):
39163922

39173923
if query.lower() in cmd.qualified_name or has_alias:
39183924
try:
3919-
if isinstance(cmd, nextcord.BaseApplicationCommand) or isinstance(cmd,
3920-
nextcord.SlashApplicationSubcommand):
3925+
if isinstance(cmd, nextcord.BaseApplicationCommand) or isinstance(cmd, nextcord.SlashApplicationSubcommand):
39213926
canrun = await cmd.can_run(ctx)
39223927
else:
39233928
canrun = (
@@ -3927,6 +3932,10 @@ async def help_autocomplete(self, ctx: nextcord.Interaction, query: str):
39273932
) # legacy commands can only be used by owners and admins
39283933
except:
39293934
canrun = False or cmd.qualified_name in overrides[permissions]
3935+
3936+
if type(cmd) is commands.Command and cmd.hidden:
3937+
continue
3938+
39303939
if canrun:
39313940
if not cmd.qualified_name in possible:
39323941
possible.append(cmd.qualified_name)
@@ -3983,6 +3992,60 @@ async def uptime_slash(self, ctx: nextcord.Interaction):
39833992
async def uptime_legacy(self, ctx: commands.Context):
39843993
await self.uptime(ctx)
39853994

3995+
# system upgrade
3996+
@system_legacy.command(name='upgrade', description='Upgrades Unifier or a plugin.')
3997+
@restrictions_legacy.owner()
3998+
async def upgrade_legacy(self, ctx, plugin='system', *, args=''):
3999+
await self.upgrade(ctx, plugin=plugin, args=args)
4000+
4001+
@commands.command(name='upgrade', description='Upgrades Unifier or a plugin.', hidden=True)
4002+
@restrictions_legacy.owner()
4003+
async def upgrade_legacy_alt(self, ctx, plugin='system', *, args=''):
4004+
await self.upgrade(ctx, plugin=plugin, args=args)
4005+
4006+
# system shutdown
4007+
@system_legacy.command(name='shutdown', aliases=['poweroff'], description=language.desc('sysmgr.shutdown'))
4008+
@restrictions_legacy.owner()
4009+
async def shutdown_legacy(self, ctx):
4010+
await self.shutdown(ctx)
4011+
4012+
@commands.command(name='shutdown', aliases=['poweroff'], description=language.desc('sysmgr.shutdown'), hidden=True)
4013+
async def shutdown_legacy_alt(self, ctx):
4014+
await self.shutdown(ctx)
4015+
4016+
# system restart
4017+
@system_legacy.command(name='restart', aliases=['reboot'], description=language.desc('sysmgr.restart'))
4018+
@restrictions_legacy.owner()
4019+
async def restart_legacy(self, ctx):
4020+
await self.restart(ctx)
4021+
4022+
@commands.command(name='restart', aliases=['reboot'], description=language.desc('sysmgr.restart'), hidden=True)
4023+
@restrictions_legacy.owner()
4024+
async def restart_legacy_alt(self, ctx):
4025+
await self.restart(ctx)
4026+
4027+
# system reload
4028+
@system_legacy.command(name='reload', description=language.desc('sysmgr.reload'))
4029+
@restrictions_legacy.owner()
4030+
async def reload_legacy(self, ctx, *, extensions):
4031+
await self.reload(ctx, extensions)
4032+
4033+
@commands.command(name='reload', description=language.desc('sysmgr.reload'), hidden=True)
4034+
@restrictions_legacy.owner()
4035+
async def reload_legacy_alt(self, ctx, *, extensions):
4036+
await self.reload(ctx, extensions)
4037+
4038+
# system eval
4039+
@system_legacy.command(name='eval', description=language.desc('sysmgr.eval'))
4040+
@restrictions_legacy.owner()
4041+
async def eval_legacy(self, ctx, *, body):
4042+
await self.eval(ctx, body)
4043+
4044+
@commands.command(name='eval', description=language.desc('sysmgr.eval'), hidden=True)
4045+
@restrictions_legacy.owner()
4046+
async def eval_legacy_alt(self, ctx, *, body):
4047+
await self.eval(ctx, body)
4048+
39864049
# Error handling
39874050

39884051
async def cog_command_error(self, ctx, error):

config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ custom_slogan = ""
2727

2828
[backups]
2929
compress_cache = true
30-
cache_backup_limit = 200000 # number of messages to cache
30+
cache_backup_limit = 100000 # number of messages to cache
3131
encrypted_backups = true # enables encryption for local backups (cloud backups are always encrypted)
3232
zstd_level = 1 # compression level, -7 (best performance) - 22 (best compression). 1 is recommended.
3333
zstd_chunk_size = 4194304 # chunk size in bytes. default is 4MB (4 * 1024 * 1024).

filters/known_spammer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class Filter(BaseFilter):
44
def __init__(self):
55
super().__init__(
66
'known-spammers',
7-
'Suspected Spammers Filter',
7+
'Block Suspected Spammers',
88
'Prevents users that are suspected to have engaged in spam activities from talking.'
99
)
1010

filters/slowmode.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ def __init__(self):
1717
)
1818

1919
def check(self, message, data) -> FilterResult:
20+
if not message['is_first']:
21+
return FilterResult(True, data)
22+
2023
if message['author'] in data['data']:
2124
if time.time() < data['data'][message['author']]:
2225
return FilterResult(

0 commit comments

Comments
 (0)