1
0
Fork 0

Add actions list on warn list command

This commit is contained in:
Ethanell 2020-08-02 20:50:11 +02:00
parent 26dda9142d
commit 74087980fc
4 changed files with 27 additions and 13 deletions

View file

@ -13,3 +13,13 @@ def time_pars(s: str) -> timedelta:
w, d, h, m, s = [i if i else 0 for i in [w, d, h, m, s]] w, d, h, m, s = [i if i else 0 for i in [w, d, h, m, s]]
return timedelta(weeks=int(w), days=int(d), hours=int(h), minutes=int(m), seconds=int(s)) return timedelta(weeks=int(w), days=int(d), hours=int(h), minutes=int(m), seconds=int(s))
raise BadArgument() raise BadArgument()
def seconds_to_time_string(seconds: float) -> str:
days, seconds = divmod(seconds, 86400)
hours, seconds = divmod(seconds, 3600)
minutes, seconds = divmod(seconds, 60)
return f"""{f"{days}d {hours}h {minutes}m {seconds}s"
if days > 0 else f"{hours}h {minutes}m {seconds}s"
if hours > 0 else f"{minutes}m {seconds}s"
if minutes > 0 else f"{seconds}s"}"""

View file

@ -1,14 +1,14 @@
from datetime import timedelta from datetime import timedelta
from db import Base from db import Base
from sqlalchemy import Column, Integer, BigInteger, Float, String from sqlalchemy import Column, Integer, BigInteger, String
class WarnAction(Base): class WarnAction(Base):
__tablename__ = "warn_actions" __tablename__ = "warn_actions"
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
guild = Column(BigInteger, nullable=False) guild = Column(BigInteger, nullable=False)
count = Column(Float, nullable=False, unique=True) count = Column(Integer, nullable=False, unique=True)
action = Column(String, nullable=False) action = Column(String, nullable=False)
duration = Column(BigInteger) duration = Column(BigInteger)

View file

@ -8,7 +8,7 @@ from discord.ext import tasks
from administrator.logger import logger from administrator.logger import logger
from administrator import db from administrator import db
from administrator.utils import time_pars from administrator.utils import time_pars, seconds_to_time_string
extension_name = "reminders" extension_name = "reminders"
logger = logger.getChild(extension_name) logger = logger.getChild(extension_name)
@ -45,12 +45,7 @@ class Reminders(commands.Cog, name="Reminder"):
s.commit() s.commit()
s.close() s.close()
hours, seconds = divmod(time.seconds, 3600) await ctx.send(f"""Remind you in {seconds_to_time_string(time.total_seconds())} !""")
minutes, seconds = divmod(seconds, 60)
await ctx.send(f"""Remind you in {f"{time.days}d {hours}h {minutes}m {seconds}s"
if time.days > 0 else f"{hours}h {minutes}m {seconds}s"
if hours > 0 else f"{minutes}m {seconds}s"
if minutes > 0 else f"{seconds}s"} !""")
@reminder.group("list", pass_context=True) @reminder.group("list", pass_context=True)
async def reminder_list(self, ctx: commands.Context): async def reminder_list(self, ctx: commands.Context):

View file

@ -4,7 +4,7 @@ from discord.ext.commands import BadArgument
from administrator import db from administrator import db
from administrator.logger import logger from administrator.logger import logger
from administrator.utils import time_pars from administrator.utils import time_pars, seconds_to_time_string
extension_name = "warn" extension_name = "warn"
logger = logger.getChild(extension_name) logger = logger.getChild(extension_name)
@ -51,13 +51,16 @@ class Warn(commands.Cog):
embed.add_field(name="add <user> <description>", value="Send a warn to a user", inline=False) embed.add_field(name="add <user> <description>", value="Send a warn to a user", inline=False)
embed.add_field(name="remove <user> <number>", value="Remove a number of warn to a user", inline=False) embed.add_field(name="remove <user> <number>", value="Remove a number of warn to a user", inline=False)
embed.add_field(name="purge <user>", value="Remove all warn of a user", inline=False) embed.add_field(name="purge <user>", value="Remove all warn of a user", inline=False)
embed.add_field(name="list [user]", value="List warn of the guild or a specified user", inline=False) embed.add_field(name="list [user#discriminator|actions]", value="List warn of the guild or a specified user\n"
"If you specify `actions` instead of a user, "
"all the actions of the guild will be listed",
inline=False)
embed.add_field(name="action <count> <action>", value="Set an action for a count of warn\n" embed.add_field(name="action <count> <action>", value="Set an action for a count of warn\n"
"Actions: `mute<time>`, `kick`, `ban[time]`, `nothing`\n" "Actions: `mute<time>`, `kick`, `ban[time]`, `nothing`\n"
"Time: `?D?H?M?S`\n" "Time: `?D?H?M?S`\n"
"Example: `action 1 mute1H` to mute someone for one hour " "Example: `action 1 mute1H` to mute someone for one hour "
"after only one war\n" "after only one war\n"
"or `action 3 ban3D` to ban someone for one day after 3 " "or `action 3 ban1D` to ban someone for one day after 3 "
"warns", inline=False) "warns", inline=False)
await ctx.send(embed=embed) await ctx.send(embed=embed)
@ -108,7 +111,13 @@ class Warn(commands.Cog):
embed = Embed(title="Warn list") embed = Embed(title="Warn list")
ws = {} ws = {}
if user: if user == "actions":
embed.title = "Actions list"
for a in s.query(db.WarnAction).filter(db.WarnAction.guild == ctx.guild.id).order_by(db.WarnAction.count)\
.all():
action = f"{a.action} for {seconds_to_time_string(a.duration)}" if a.duration else a.action
embed.add_field(name=f"{a.count} warn(s)", value=action, inline=False)
elif user:
target = self.get_target(ctx, user) target = self.get_target(ctx, user)
ws[target.id] = s.query(db.Warn).filter(db.Warn.guild == ctx.guild.id, db.Warn.user == target.id).all() ws[target.id] = s.query(db.Warn).filter(db.Warn.guild == ctx.guild.id, db.Warn.user == target.id).all()
else: else: