one of these days ill remember this

This commit is contained in:
brandons209 2020-02-02 02:18:16 -05:00
parent 64e6da1f0b
commit 96baa7791b
3 changed files with 16 additions and 57 deletions

View file

@ -27,10 +27,7 @@ class RecentActivityRecord:
return len(self.activities) + len(self.messages)
def _filter(
self,
*,
after: Optional[datetime] = None,
message_check: Optional[MessagePredicate] = None,
self, *, after: Optional[datetime] = None, message_check: Optional[MessagePredicate] = None,
) -> List[Union[datetime, discord.Message]]:
ret: List[Union[datetime, discord.Message]] = []
@ -52,10 +49,7 @@ class RecentActivityRecord:
return ret
def conditional_count(
self,
*,
after: Optional[datetime] = None,
message_check: Optional[MessagePredicate] = None,
self, *, after: Optional[datetime] = None, message_check: Optional[MessagePredicate] = None,
) -> int:
ret = len(self._filter(after=after, message_check=message_check))
@ -63,20 +57,13 @@ class RecentActivityRecord:
return ret
def conditional_remove(
self,
*,
before: Optional[datetime] = None,
message_check: Optional[MessagePredicate] = None,
self, *, before: Optional[datetime] = None, message_check: Optional[MessagePredicate] = None,
):
if before:
self.activities = [a for a in self.activities if a > before]
if message_check:
self.messages = [
m
for m in self.messages
if m.created_at > before and message_check(m)
]
self.messages = [m for m in self.messages if m.created_at > before and message_check(m)]
else:
self.messages = [m for m in self.messages if m.created_at > before]
@ -113,11 +100,7 @@ class RecordHandler:
self.records[guild][member].add_message(message)
def get_active_for_guild(
self,
*,
guild: discord.Guild,
after: datetime,
message_check: Optional[MessagePredicate] = None,
self, *, guild: discord.Guild, after: datetime, message_check: Optional[MessagePredicate] = None,
) -> Iterator[discord.Member]:
with contextlib.suppress(KeyError):

View file

@ -32,9 +32,7 @@ def settings_converter(user_input: str) -> dict:
assert args["interval"] == int(args["interval"])
assert args["interval"] >= 5
except AssertionError:
raise commands.BadArgument(
"Interval must be an integer value 5 or greater"
) from None
raise commands.BadArgument("Interval must be an integer value 5 or greater") from None
for value in (
"econ_per_interval",
@ -49,19 +47,13 @@ def settings_converter(user_input: str) -> dict:
try:
assert args[value] == int(args[value]) and args[value] >= 0
except AssertionError:
raise commands.BadArgument(
f"{value} must be a non-negative integer value"
)
raise commands.BadArgument(f"{value} must be a non-negative integer value")
for value in ("maximum_level", "maximum_bonus"):
if value in args:
try:
assert args[value] is None or (
args[value] == int(args[value]) and args[value] >= 0
)
assert args[value] is None or (args[value] == int(args[value]) and args[value] >= 0)
except AssertionError:
raise commands.BadArgument(
f"{value} must be a non-negative integer value or `null`"
)
raise commands.BadArgument(f"{value} must be a non-negative integer value or `null`")
return args

View file

@ -24,9 +24,7 @@ class EconomyTrickle(commands.Cog):
def __init__(self, bot, *args, **kwargs):
super().__init__(*args, **kwargs)
self.bot = bot
self.config = Config.get_conf(
self, identifier=78631113035100160, force_registration=True
)
self.config = Config.get_conf(self, identifier=78631113035100160, force_registration=True)
self.config.register_guild(
active=False,
mode="blacklist",
@ -65,9 +63,7 @@ class EconomyTrickle(commands.Cog):
if g.id in data and data[g.id]["active"]:
minutes[g] += 1
if minutes[g] % data[g.id]["interval"]:
tsk = self.bot.loop.create_task(
self.do_rewards_for(g, now, data[g.id])
)
tsk = self.bot.loop.create_task(self.do_rewards_for(g, now, data[g.id]))
self.extra_tasks.append(tsk)
async def do_rewards_for(self, guild: discord.Guild, now: datetime, data: dict):
@ -92,11 +88,7 @@ class EconomyTrickle(commands.Cog):
with contextlib.suppress(AttributeError):
return mem.voice.channel.id in data["whitelist"] and not mem.bot
has_active_message = set(
self.recordhandler.get_active_for_guild(
guild=guild, after=after, message_check=mpred
)
)
has_active_message = set(self.recordhandler.get_active_for_guild(guild=guild, after=after, message_check=mpred))
is_active_voice = {m for m in guild.members if vpred(m)}
@ -200,9 +192,7 @@ class EconomyTrickle(commands.Cog):
await ctx.tick()
@ect.command(name="addchan")
async def rset_add_chan(
self, ctx, *channels: Union[discord.TextChannel, discord.VoiceChannel]
):
async def rset_add_chan(self, ctx, *channels: Union[discord.TextChannel, discord.VoiceChannel]):
"""
Adds one or more channels to the current mode's settings
"""
@ -213,9 +203,7 @@ class EconomyTrickle(commands.Cog):
gsets = await self.config.guild(ctx.guild).all()
mode = gsets["mode"]
if not mode:
return await ctx.send(
f"You need to set a mode using `{ctx.clean_prefix}redirectset mode` first"
)
return await ctx.send(f"You need to set a mode using `{ctx.clean_prefix}redirectset mode` first")
for channel in channels:
if channel.id not in gsets[mode]:
@ -225,9 +213,7 @@ class EconomyTrickle(commands.Cog):
await ctx.tick()
@ect.command(name="remchan")
async def rset_rem_chan(
self, ctx, *channels: Union[discord.TextChannel, discord.VoiceChannel]
):
async def rset_rem_chan(self, ctx, *channels: Union[discord.TextChannel, discord.VoiceChannel]):
"""
removes one or more channels from the current mode's settings
"""
@ -238,9 +224,7 @@ class EconomyTrickle(commands.Cog):
gsets = await self.config.guild(ctx.guild).all()
mode = gsets["mode"]
if not mode:
return await ctx.send(
f"You need to set a mode using `{ctx.clean_prefix}trickleset mode` first"
)
return await ctx.send(f"You need to set a mode using `{ctx.clean_prefix}trickleset mode` first")
for channel in channels:
while channel.id in gsets[mode]: