✨ status command
This commit is contained in:
parent
8c5b4ec59f
commit
99b9fa091a
|
@ -1,10 +1,11 @@
|
||||||
import itertools
|
import itertools
|
||||||
import random
|
import random
|
||||||
import sys
|
import datetime
|
||||||
import traceback
|
|
||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
|
from time import time
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
|
from discord import Guild
|
||||||
from discord.ext.commands import (
|
from discord.ext.commands import (
|
||||||
Cog,
|
Cog,
|
||||||
command,
|
command,
|
||||||
|
@ -13,13 +14,10 @@ from discord.ext.commands import (
|
||||||
Command,
|
Command,
|
||||||
CommandError,
|
CommandError,
|
||||||
Group,
|
Group,
|
||||||
CommandInvokeError,
|
|
||||||
CommandNotFound,
|
|
||||||
MissingRole,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from src.constants import *
|
from src.constants import *
|
||||||
from src.errors import UnwantedCommand
|
from src.utils import has_role
|
||||||
|
|
||||||
|
|
||||||
class MiscCog(Cog, name="Divers"):
|
class MiscCog(Cog, name="Divers"):
|
||||||
|
@ -53,6 +51,31 @@ class MiscCog(Cog, name="Divers"):
|
||||||
msg = random.choice(jokes)
|
msg = random.choice(jokes)
|
||||||
await ctx.send(msg)
|
await ctx.send(msg)
|
||||||
|
|
||||||
|
@command(name="status")
|
||||||
|
async def status_cmd(self, ctx: Context):
|
||||||
|
guild: Guild = ctx.guild
|
||||||
|
embed = discord.Embed(title="État du serveur", color=EMBED_COLOR)
|
||||||
|
benevoles = [g for g in guild.members if has_role(g, Role.BENEVOLE)]
|
||||||
|
participants = [g for g in guild.members if has_role(g, Role.PARTICIPANT)]
|
||||||
|
no_role = [g for g in guild.members if g.top_role == guild.default_role]
|
||||||
|
uptime = datetime.timedelta(seconds=round(time() - START_TIME))
|
||||||
|
|
||||||
|
infos = {
|
||||||
|
"Bénévoles": len(benevoles),
|
||||||
|
"Participants": len(participants),
|
||||||
|
"Sans rôle": len(no_role),
|
||||||
|
"Total": len(guild.members),
|
||||||
|
"Bot uptime": uptime,
|
||||||
|
}
|
||||||
|
|
||||||
|
width = max(map(len, infos))
|
||||||
|
txt = "\n".join(
|
||||||
|
f"`{key.rjust(width)}`: {value}" for key, value in infos.items()
|
||||||
|
)
|
||||||
|
embed.add_field(name="Stats", value=txt)
|
||||||
|
|
||||||
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
# ----------------- Help ---------------- #
|
# ----------------- Help ---------------- #
|
||||||
|
|
||||||
@command(name="help", aliases=["h"])
|
@command(name="help", aliases=["h"])
|
||||||
|
|
|
@ -13,8 +13,12 @@ __all__ = [
|
||||||
"TEAMS_CHANNEL_CATEGORY",
|
"TEAMS_CHANNEL_CATEGORY",
|
||||||
"DIEGO",
|
"DIEGO",
|
||||||
"TOURNOIS",
|
"TOURNOIS",
|
||||||
|
"EMBED_COLOR",
|
||||||
|
"START_TIME",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
from time import time
|
||||||
|
|
||||||
TOKEN = os.environ.get("TFJM_DISCORD_TOKEN")
|
TOKEN = os.environ.get("TFJM_DISCORD_TOKEN")
|
||||||
|
|
||||||
if TOKEN is None:
|
if TOKEN is None:
|
||||||
|
@ -64,3 +68,6 @@ JOKES_FILE = TOP_LEVEL_DIR / "data" / "jokes"
|
||||||
with open(TOP_LEVEL_DIR / "data" / "problems") as f:
|
with open(TOP_LEVEL_DIR / "data" / "problems") as f:
|
||||||
PROBLEMS = f.read().splitlines()
|
PROBLEMS = f.read().splitlines()
|
||||||
MAX_REFUSE = len(PROBLEMS) - 4 # -5 usually but not in 2020 because of covid-19
|
MAX_REFUSE = len(PROBLEMS) - 4 # -5 usually but not in 2020 because of covid-19
|
||||||
|
|
||||||
|
EMBED_COLOR = 0xFFA500
|
||||||
|
START_TIME = time()
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
def has_role(member, role: str):
|
||||||
|
"""Return whether the member has a role with this name."""
|
||||||
|
|
||||||
|
return any(r.name == role for r in member.roles)
|
Loading…
Reference in New Issue