Skip to content

Commit

Permalink
Merge pull request #116 from Sonnet-Discord/dev-unstable
Browse files Browse the repository at this point in the history
Sonnet 2.0.0
  • Loading branch information
ultrabear authored Aug 29, 2022
2 parents fd0e3a1 + 75fc13f commit 7a4e27f
Show file tree
Hide file tree
Showing 27 changed files with 635 additions and 304 deletions.
12 changes: 6 additions & 6 deletions build_tools/cached_yapf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import subprocess
from dataclasses import dataclass

from typing import List, Literal, Final, Dict
from typing import List, Literal, Final, Dict, AsyncIterator


@dataclass
Expand Down Expand Up @@ -153,12 +153,12 @@ async def run_single_yapf(mode: Literal["diff", "inplace"], filename: str) -> Pr
return ProcessedData(filename, stdout, stderr, proc.returncode or 0)


async def run_yapf_async(mode: Literal["diff", "inplace"], files: List[str]) -> List[ProcessedData]:
async def run_yapf_async(mode: Literal["diff", "inplace"], files: List[str]) -> AsyncIterator[ProcessedData]:
"""
Runs multiple yapf instances in async subprocesses and provides returncode and info for each
"""
tasks = [asyncio.create_task(run_single_yapf(mode, i)) for i in files]
return [await task for task in tasks]
return (await task for task in tasks)


def run_yapf_once(mode: Literal["diff", "inplace"], files: List[str]) -> "subprocess.CompletedProcess[bytes]":
Expand All @@ -184,12 +184,12 @@ def process_inplace(cache: Dict[str, CacheEntry], files: List[str]) -> int:
return proc.returncode


def process_diff(cache: Dict[str, CacheEntry], files: List[str]) -> int:
async def process_diff(cache: Dict[str, CacheEntry], files: List[str]) -> int:
returncode = 0

safe_cached = []

for proc in asyncio.run(run_yapf_async("diff", files)):
async for proc in await run_yapf_async("diff", files):

if proc.stdout:
print(proc.stdout.decode("utf8"))
Expand Down Expand Up @@ -231,7 +231,7 @@ def main(args: List[str]) -> int:
if parsed.mode == "inplace":
return process_inplace(cache, process)
else:
return process_diff(cache, process)
return asyncio.run(process_diff(cache, process))


if __name__ == "__main__":
Expand Down
13 changes: 13 additions & 0 deletions build_tools/cmds_to_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@

raise SyntaxError(f"ERROR IN [{execmodule} : {command}] PERMISSION TYPE({cmd.permission}) IS NOT VALID")

# Test for pretty_name starting with the keyname
for command in command_modules_dict:
if "alias" in command_modules_dict[command]:
continue

# cmd.execute might point to lib_sonnetcommands if it builds a closure for backwards compat, so get the raw value
execmodule = command_modules_dict[command]['execute'].__module__

if command_modules_dict[command]["pretty_name"].startswith(command):
continue

raise SyntaxError(f"ERROR IN [{execmodule} : {command}] pretty_name does not start with command name (malformed helptext)")

# Test for aliases pointing to existing commands that are not aliases
for command in command_modules_dict:
if "alias" not in command_modules_dict[command]:
Expand Down
54 changes: 44 additions & 10 deletions cmds/cmd_automod.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,29 @@ async def set_blacklist_infraction_level(message: discord.Message, args: List[st
if ctx.verbose: await message.channel.send(f"Updated blacklist action to `{action}`")


async def set_antispam_command(message: discord.Message, args: List[str], client: discord.Client, ctx: CommandCtx) -> int:
if not message.guild:
return 1

if args:
action = args[0].lower()
else:
await message.channel.send(f"antispam action is `{ctx.conf_cache['antispam-action']}`")
return 0

if action not in ["timeout", "mute"]:
await message.channel.send("ERROR: Antispam action is not valid\nValid Actions: `timeout` and `mute`")
return 1

with db_hlapi(message.guild.id) as database:
database.add_config("antispam-action", action)

if ctx.verbose:
await message.channel.send(f"Updated antispam action to `{action}`")

return 0


async def change_rolewhitelist(message: discord.Message, args: List[str], client: discord.Client, ctx: CommandCtx) -> Any:

return await parse_role(message, args, "blacklist-whitelist", verbose=ctx.verbose)
Expand Down Expand Up @@ -376,21 +399,21 @@ async def antispam_time_set(message: discord.Message, args: List[str], client: d
return 1
else:
mutetime = int(ctx.conf_cache["antispam-time"])
await message.channel.send(f"Antispam mute time is {mutetime} seconds")
await message.channel.send(f"Antispam timeout is {format_duration(mutetime)}")
return 0

if mutetime < 0:
await message.channel.send("ERROR: Mutetime cannot be negative")
await message.channel.send("ERROR: timeout cannot be negative")
return 1

elif mutetime >= 60 * 60 * 256:
await message.channel.send("ERROR: Mutetime cannot be greater than 256 hours")
await message.channel.send("ERROR: timeout cannot be greater than 256 hours")
return 1

with db_hlapi(message.guild.id) as db:
db.add_config("antispam-time", str(mutetime))

if ctx.verbose: await message.channel.send(f"Set antispam mute time to {format_duration(mutetime)}")
if ctx.verbose: await message.channel.send(f"Set antispam timeout to {format_duration(mutetime)}")


class NoGuildError(Exception):
Expand Down Expand Up @@ -669,15 +692,26 @@ async def add_joinrule(message: discord.Message, args: List[str], client: discor
'execute': antispam_set
},
'mutetime-set': {
'alias': 'set-mutetime'
'alias': 'set-antispam-timeout'
},
'set-mutetime':
'set-mutetime': {
'alias': 'set-antispam-timeout'
},
'set-antispam-timeout':
{
'pretty_name': 'set-antispam-timeout <time[h|m|S]>',
'description': 'Set how many seconds a person should be out for with antispam auto mute/timeout',
'permission': 'administrator',
'cache': 'regenerate',
'execute': antispam_time_set,
},
'set-antispam-action':
{
'pretty_name': 'set-mutetime <time[h|m|S]>',
'description': 'Set how many seconds a person should be muted for with antispam automute',
'pretty_name': 'set-antispam-action [timeout|mute]',
'description': 'set whether to use mute or timeout for antispam triggers',
'permission': 'administrator',
'cache': 'regenerate',
'execute': antispam_time_set
'execute': set_antispam_command,
},
'add-regexnotifier':
{
Expand All @@ -697,4 +731,4 @@ async def add_joinrule(message: discord.Message, args: List[str], client: discor
},
}

version_info: str = "1.2.14"
version_info: str = "2.0.0"
Loading

0 comments on commit 7a4e27f

Please sign in to comment.