mirror of
https://github.com/brandons209/Red-bot-Cogs.git
synced 2024-06-27 02:20:44 +12:00
one of these days ill remember this
This commit is contained in:
parent
64e6da1f0b
commit
96baa7791b
|
@ -27,10 +27,7 @@ class RecentActivityRecord:
|
||||||
return len(self.activities) + len(self.messages)
|
return len(self.activities) + len(self.messages)
|
||||||
|
|
||||||
def _filter(
|
def _filter(
|
||||||
self,
|
self, *, after: Optional[datetime] = None, message_check: Optional[MessagePredicate] = None,
|
||||||
*,
|
|
||||||
after: Optional[datetime] = None,
|
|
||||||
message_check: Optional[MessagePredicate] = None,
|
|
||||||
) -> List[Union[datetime, discord.Message]]:
|
) -> List[Union[datetime, discord.Message]]:
|
||||||
|
|
||||||
ret: List[Union[datetime, discord.Message]] = []
|
ret: List[Union[datetime, discord.Message]] = []
|
||||||
|
@ -52,10 +49,7 @@ class RecentActivityRecord:
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def conditional_count(
|
def conditional_count(
|
||||||
self,
|
self, *, after: Optional[datetime] = None, message_check: Optional[MessagePredicate] = None,
|
||||||
*,
|
|
||||||
after: Optional[datetime] = None,
|
|
||||||
message_check: Optional[MessagePredicate] = None,
|
|
||||||
) -> int:
|
) -> int:
|
||||||
|
|
||||||
ret = len(self._filter(after=after, message_check=message_check))
|
ret = len(self._filter(after=after, message_check=message_check))
|
||||||
|
@ -63,20 +57,13 @@ class RecentActivityRecord:
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def conditional_remove(
|
def conditional_remove(
|
||||||
self,
|
self, *, before: Optional[datetime] = None, message_check: Optional[MessagePredicate] = None,
|
||||||
*,
|
|
||||||
before: Optional[datetime] = None,
|
|
||||||
message_check: Optional[MessagePredicate] = None,
|
|
||||||
):
|
):
|
||||||
if before:
|
if before:
|
||||||
self.activities = [a for a in self.activities if a > before]
|
self.activities = [a for a in self.activities if a > before]
|
||||||
|
|
||||||
if message_check:
|
if message_check:
|
||||||
self.messages = [
|
self.messages = [m for m in self.messages if m.created_at > before and message_check(m)]
|
||||||
m
|
|
||||||
for m in self.messages
|
|
||||||
if m.created_at > before and message_check(m)
|
|
||||||
]
|
|
||||||
else:
|
else:
|
||||||
self.messages = [m for m in self.messages if m.created_at > before]
|
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)
|
self.records[guild][member].add_message(message)
|
||||||
|
|
||||||
def get_active_for_guild(
|
def get_active_for_guild(
|
||||||
self,
|
self, *, guild: discord.Guild, after: datetime, message_check: Optional[MessagePredicate] = None,
|
||||||
*,
|
|
||||||
guild: discord.Guild,
|
|
||||||
after: datetime,
|
|
||||||
message_check: Optional[MessagePredicate] = None,
|
|
||||||
) -> Iterator[discord.Member]:
|
) -> Iterator[discord.Member]:
|
||||||
|
|
||||||
with contextlib.suppress(KeyError):
|
with contextlib.suppress(KeyError):
|
||||||
|
|
|
@ -32,9 +32,7 @@ def settings_converter(user_input: str) -> dict:
|
||||||
assert args["interval"] == int(args["interval"])
|
assert args["interval"] == int(args["interval"])
|
||||||
assert args["interval"] >= 5
|
assert args["interval"] >= 5
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
raise commands.BadArgument(
|
raise commands.BadArgument("Interval must be an integer value 5 or greater") from None
|
||||||
"Interval must be an integer value 5 or greater"
|
|
||||||
) from None
|
|
||||||
|
|
||||||
for value in (
|
for value in (
|
||||||
"econ_per_interval",
|
"econ_per_interval",
|
||||||
|
@ -49,19 +47,13 @@ def settings_converter(user_input: str) -> dict:
|
||||||
try:
|
try:
|
||||||
assert args[value] == int(args[value]) and args[value] >= 0
|
assert args[value] == int(args[value]) and args[value] >= 0
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
raise commands.BadArgument(
|
raise commands.BadArgument(f"{value} must be a non-negative integer value")
|
||||||
f"{value} must be a non-negative integer value"
|
|
||||||
)
|
|
||||||
|
|
||||||
for value in ("maximum_level", "maximum_bonus"):
|
for value in ("maximum_level", "maximum_bonus"):
|
||||||
if value in args:
|
if value in args:
|
||||||
try:
|
try:
|
||||||
assert args[value] is None or (
|
assert args[value] is None or (args[value] == int(args[value]) and args[value] >= 0)
|
||||||
args[value] == int(args[value]) and args[value] >= 0
|
|
||||||
)
|
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
raise commands.BadArgument(
|
raise commands.BadArgument(f"{value} must be a non-negative integer value or `null`")
|
||||||
f"{value} must be a non-negative integer value or `null`"
|
|
||||||
)
|
|
||||||
|
|
||||||
return args
|
return args
|
||||||
|
|
|
@ -24,9 +24,7 @@ class EconomyTrickle(commands.Cog):
|
||||||
def __init__(self, bot, *args, **kwargs):
|
def __init__(self, bot, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.config = Config.get_conf(
|
self.config = Config.get_conf(self, identifier=78631113035100160, force_registration=True)
|
||||||
self, identifier=78631113035100160, force_registration=True
|
|
||||||
)
|
|
||||||
self.config.register_guild(
|
self.config.register_guild(
|
||||||
active=False,
|
active=False,
|
||||||
mode="blacklist",
|
mode="blacklist",
|
||||||
|
@ -65,9 +63,7 @@ class EconomyTrickle(commands.Cog):
|
||||||
if g.id in data and data[g.id]["active"]:
|
if g.id in data and data[g.id]["active"]:
|
||||||
minutes[g] += 1
|
minutes[g] += 1
|
||||||
if minutes[g] % data[g.id]["interval"]:
|
if minutes[g] % data[g.id]["interval"]:
|
||||||
tsk = self.bot.loop.create_task(
|
tsk = self.bot.loop.create_task(self.do_rewards_for(g, now, data[g.id]))
|
||||||
self.do_rewards_for(g, now, data[g.id])
|
|
||||||
)
|
|
||||||
self.extra_tasks.append(tsk)
|
self.extra_tasks.append(tsk)
|
||||||
|
|
||||||
async def do_rewards_for(self, guild: discord.Guild, now: datetime, data: dict):
|
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):
|
with contextlib.suppress(AttributeError):
|
||||||
return mem.voice.channel.id in data["whitelist"] and not mem.bot
|
return mem.voice.channel.id in data["whitelist"] and not mem.bot
|
||||||
|
|
||||||
has_active_message = set(
|
has_active_message = set(self.recordhandler.get_active_for_guild(guild=guild, after=after, message_check=mpred))
|
||||||
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)}
|
is_active_voice = {m for m in guild.members if vpred(m)}
|
||||||
|
|
||||||
|
@ -200,9 +192,7 @@ class EconomyTrickle(commands.Cog):
|
||||||
await ctx.tick()
|
await ctx.tick()
|
||||||
|
|
||||||
@ect.command(name="addchan")
|
@ect.command(name="addchan")
|
||||||
async def rset_add_chan(
|
async def rset_add_chan(self, ctx, *channels: Union[discord.TextChannel, discord.VoiceChannel]):
|
||||||
self, ctx, *channels: Union[discord.TextChannel, discord.VoiceChannel]
|
|
||||||
):
|
|
||||||
"""
|
"""
|
||||||
Adds one or more channels to the current mode's settings
|
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()
|
gsets = await self.config.guild(ctx.guild).all()
|
||||||
mode = gsets["mode"]
|
mode = gsets["mode"]
|
||||||
if not mode:
|
if not mode:
|
||||||
return await ctx.send(
|
return await ctx.send(f"You need to set a mode using `{ctx.clean_prefix}redirectset mode` first")
|
||||||
f"You need to set a mode using `{ctx.clean_prefix}redirectset mode` first"
|
|
||||||
)
|
|
||||||
|
|
||||||
for channel in channels:
|
for channel in channels:
|
||||||
if channel.id not in gsets[mode]:
|
if channel.id not in gsets[mode]:
|
||||||
|
@ -225,9 +213,7 @@ class EconomyTrickle(commands.Cog):
|
||||||
await ctx.tick()
|
await ctx.tick()
|
||||||
|
|
||||||
@ect.command(name="remchan")
|
@ect.command(name="remchan")
|
||||||
async def rset_rem_chan(
|
async def rset_rem_chan(self, ctx, *channels: Union[discord.TextChannel, discord.VoiceChannel]):
|
||||||
self, ctx, *channels: Union[discord.TextChannel, discord.VoiceChannel]
|
|
||||||
):
|
|
||||||
"""
|
"""
|
||||||
removes one or more channels from the current mode's settings
|
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()
|
gsets = await self.config.guild(ctx.guild).all()
|
||||||
mode = gsets["mode"]
|
mode = gsets["mode"]
|
||||||
if not mode:
|
if not mode:
|
||||||
return await ctx.send(
|
return await ctx.send(f"You need to set a mode using `{ctx.clean_prefix}trickleset mode` first")
|
||||||
f"You need to set a mode using `{ctx.clean_prefix}trickleset mode` first"
|
|
||||||
)
|
|
||||||
|
|
||||||
for channel in channels:
|
for channel in channels:
|
||||||
while channel.id in gsets[mode]:
|
while channel.id in gsets[mode]:
|
||||||
|
|
Loading…
Reference in a new issue