Added pagination features to /warnings, /bans, added /ctc2 guesses
This commit is contained in:
parent
b2753cdd04
commit
a97f474525
4 changed files with 371 additions and 70 deletions
|
@ -36,7 +36,7 @@ jarvis = commands.Bot(
|
||||||
)
|
)
|
||||||
slash = SlashCommand(jarvis, sync_commands=True, sync_on_cog_reload=True)
|
slash = SlashCommand(jarvis, sync_commands=True, sync_on_cog_reload=True)
|
||||||
jarvis_self = Process()
|
jarvis_self = Process()
|
||||||
__version__ = "1.3.0"
|
__version__ = "1.4.0"
|
||||||
|
|
||||||
|
|
||||||
db = DBManager(get_config().mongo).mongo
|
db = DBManager(get_config().mongo).mongo
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
import re
|
import re
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
import pymongo
|
import pymongo
|
||||||
|
from ButtonPaginator import Paginator
|
||||||
from discord import Member, Role, TextChannel, User, VoiceChannel
|
from discord import Member, Role, TextChannel, User, VoiceChannel
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
from discord.ext.tasks import loop
|
||||||
from discord.utils import find, get
|
from discord.utils import find, get
|
||||||
from discord_slash import SlashContext, cog_ext
|
from discord_slash import SlashContext, cog_ext
|
||||||
|
from discord_slash.model import ButtonStyle
|
||||||
from discord_slash.utils.manage_commands import create_choice, create_option
|
from discord_slash.utils.manage_commands import create_choice, create_option
|
||||||
|
|
||||||
import jarvis
|
import jarvis
|
||||||
|
@ -16,6 +19,7 @@ from jarvis.db.types import (
|
||||||
Ban,
|
Ban,
|
||||||
Kick,
|
Kick,
|
||||||
Lock,
|
Lock,
|
||||||
|
MongoSort,
|
||||||
Mute,
|
Mute,
|
||||||
Purge,
|
Purge,
|
||||||
Setting,
|
Setting,
|
||||||
|
@ -38,6 +42,19 @@ class AdminCog(commands.Cog):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
config = jarvis.config.get_config()
|
config = jarvis.config.get_config()
|
||||||
self.db = DBManager(config.mongo).mongo.jarvis
|
self.db = DBManager(config.mongo).mongo.jarvis
|
||||||
|
self.cache = {}
|
||||||
|
self._expire_interaction.start()
|
||||||
|
|
||||||
|
def check_cache(self, ctx: SlashContext, **kwargs):
|
||||||
|
if not kwargs:
|
||||||
|
kwargs = {}
|
||||||
|
return find(
|
||||||
|
lambda x: x["command"] == ctx.subcommand_name
|
||||||
|
and x["user"] == ctx.author.id
|
||||||
|
and x["guild"] == ctx.guild.id
|
||||||
|
and all(x[k] == v for k, v in kwargs.items()),
|
||||||
|
self.cache.values(),
|
||||||
|
)
|
||||||
|
|
||||||
@cog_ext.cog_slash(
|
@cog_ext.cog_slash(
|
||||||
name="ban",
|
name="ban",
|
||||||
|
@ -316,6 +333,15 @@ class AdminCog(commands.Cog):
|
||||||
async def _bans_list(
|
async def _bans_list(
|
||||||
self, ctx: SlashContext, type: int = 0, active: int = 1
|
self, ctx: SlashContext, type: int = 0, active: int = 1
|
||||||
):
|
):
|
||||||
|
exists = self.check_cache(ctx, type=type)
|
||||||
|
if exists:
|
||||||
|
await ctx.defer(hidden=True)
|
||||||
|
await ctx.send(
|
||||||
|
"Please use existing interaction: "
|
||||||
|
+ f"{exists['paginator']._message.jump_url}",
|
||||||
|
hidden=True,
|
||||||
|
)
|
||||||
|
return
|
||||||
active = bool(active)
|
active = bool(active)
|
||||||
types = [0, "perm", "temp", "soft"]
|
types = [0, "perm", "temp", "soft"]
|
||||||
search = {"guild": ctx.guild.id}
|
search = {"guild": ctx.guild.id}
|
||||||
|
@ -325,36 +351,85 @@ class AdminCog(commands.Cog):
|
||||||
search["type"] = types[type]
|
search["type"] = types[type]
|
||||||
bans = Ban.get_many(**search)
|
bans = Ban.get_many(**search)
|
||||||
bans.sort(key=lambda x: x.created_at, reverse=True)
|
bans.sort(key=lambda x: x.created_at, reverse=True)
|
||||||
ban_messages = []
|
|
||||||
db_bans = []
|
db_bans = []
|
||||||
|
fields = []
|
||||||
for ban in bans:
|
for ban in bans:
|
||||||
if not ban.username:
|
if not ban.username:
|
||||||
user = await self.bot.fetch_user(ban.user)
|
user = await self.bot.fetch_user(ban.user)
|
||||||
ban.username = user.name if user else "[deleted user]"
|
ban.username = user.name if user else "[deleted user]"
|
||||||
ban_messages.append(
|
fields.append(
|
||||||
"[{0}] {1} ({2}): {3}".format(
|
Field(
|
||||||
ban.created_at.strftime("%d-%m-%Y"),
|
name=f"Username: {ban.username}#{ban.discrim}",
|
||||||
ban.username,
|
value="Date: {ban.created_at.strftime('%d-%m-%Y')}\n"
|
||||||
ban.user,
|
+ f"User ID: {ban.user}\n"
|
||||||
ban.reason,
|
+ f"Reason: {ban.reason}\n"
|
||||||
|
+ f"Type: {ban.type}\n\u200b",
|
||||||
|
inline=False,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
db_bans.append(ban.user)
|
db_bans.append(ban.user)
|
||||||
bans = await ctx.guild.bans()
|
if type == 0:
|
||||||
for ban in bans:
|
bans = await ctx.guild.bans()
|
||||||
if ban.user.id not in db_bans:
|
for ban in bans:
|
||||||
ban_messages.append(
|
if ban.user.id not in db_bans:
|
||||||
"[unknown] {0} ({1}): {2}".format(
|
fields.append(
|
||||||
ban.user.name, ban.user.id, ban.reason
|
Field(
|
||||||
|
name=f"Username: {ban.user.name}#"
|
||||||
|
+ f"{ban.user.discriminator}",
|
||||||
|
value="Date: [unknown]\n"
|
||||||
|
+ f"User ID: {ban.user.id}\n"
|
||||||
|
+ f"Reason: {ban.reason}\n"
|
||||||
|
+ "Type: manual\n\u200b",
|
||||||
|
inline=False,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
message = ""
|
pages = []
|
||||||
if len(ban_messages) == 0:
|
title = "Active " if active else "Inactive "
|
||||||
message = "No bans matched the criteria."
|
if type > 0:
|
||||||
|
title += types[type]
|
||||||
|
if type == 1:
|
||||||
|
title += "a"
|
||||||
|
title += "bans"
|
||||||
|
if len(fields) == 0:
|
||||||
|
embed = build_embed(
|
||||||
|
title=title,
|
||||||
|
description=f"No {'in' if not active else ''}active bans",
|
||||||
|
fields=[],
|
||||||
|
)
|
||||||
|
embed.set_thumbnail(url=ctx.guild.icon_url)
|
||||||
|
pages.append(embed)
|
||||||
else:
|
else:
|
||||||
message = "Active " if active else "Inactive "
|
for i in range(0, len(bans), 5):
|
||||||
message += "Bans:\n```\n" + "\n".join(ban_messages) + "\n```"
|
embed = build_embed(
|
||||||
await ctx.send(message)
|
title=title, description="", fields=fields[i : i + 5]
|
||||||
|
)
|
||||||
|
embed.set_thumbnail(url=ctx.guild.icon_url)
|
||||||
|
pages.append(embed)
|
||||||
|
|
||||||
|
paginator = Paginator(
|
||||||
|
bot=self.bot,
|
||||||
|
ctx=ctx,
|
||||||
|
embeds=pages,
|
||||||
|
only=ctx.author,
|
||||||
|
timeout=60 * 5, # 5 minute timeout
|
||||||
|
disable_after_timeout=True,
|
||||||
|
use_extend=len(pages) > 2,
|
||||||
|
left_button_style=ButtonStyle.grey,
|
||||||
|
right_button_style=ButtonStyle.grey,
|
||||||
|
basic_buttons=["◀", "▶"],
|
||||||
|
)
|
||||||
|
|
||||||
|
self.cache[hash(paginator)] = {
|
||||||
|
"guild": ctx.guild.id,
|
||||||
|
"user": ctx.author.id,
|
||||||
|
"timeout": datetime.utcnow() + timedelta(minutes=5),
|
||||||
|
"command": ctx.subcommand_name,
|
||||||
|
"type": type,
|
||||||
|
"paginator": paginator,
|
||||||
|
}
|
||||||
|
|
||||||
|
await paginator.start()
|
||||||
|
|
||||||
@cog_ext.cog_slash(
|
@cog_ext.cog_slash(
|
||||||
name="kick",
|
name="kick",
|
||||||
|
@ -822,41 +897,123 @@ class AdminCog(commands.Cog):
|
||||||
option_type=6,
|
option_type=6,
|
||||||
required=True,
|
required=True,
|
||||||
),
|
),
|
||||||
|
create_option(
|
||||||
|
name="active",
|
||||||
|
description="View only active",
|
||||||
|
option_type=4,
|
||||||
|
required=False,
|
||||||
|
choices=[
|
||||||
|
create_choice(name="Yes", value=1),
|
||||||
|
create_choice(name="No", value=0),
|
||||||
|
],
|
||||||
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@commands.has_permissions(administrator=True)
|
@commands.has_permissions(administrator=True)
|
||||||
async def _warnings(self, ctx: SlashContext, user: User):
|
async def _warnings(self, ctx: SlashContext, user: User, active: bool = 1):
|
||||||
await ctx.defer(hidden=True)
|
active = bool(active)
|
||||||
warnings = Warning.get_many(user=user.id, guild=ctx.guild.id)
|
exists = self.check_cache(ctx, user_id=user.id, active=active)
|
||||||
active = [
|
if exists:
|
||||||
f'`{y.created_at.strftime("%Y-%m-%d %H:%M:%S")}` - {y.reason}'
|
await ctx.defer(hidden=True)
|
||||||
for y in list(filter(lambda x: x.active, warnings))
|
await ctx.send(
|
||||||
]
|
"Please use existing interaction: "
|
||||||
|
+ f"{exists['paginator']._message.jump_url}",
|
||||||
n_active = len(active)
|
hidden=True,
|
||||||
if len(active) > 10:
|
)
|
||||||
active = active[:10]
|
return
|
||||||
active.append("\n>10 active, results truncated")
|
warnings = Warning.get_many(
|
||||||
elif len(active) == 0:
|
user=user.id,
|
||||||
active = ["No active warnings"]
|
guild=ctx.guild.id,
|
||||||
|
sort=MongoSort(direction="desc", key="created_at"),
|
||||||
total = len(warnings)
|
|
||||||
fields = [
|
|
||||||
Field(f"{n_active} Active", "\n".join(active), False),
|
|
||||||
Field("Total", total),
|
|
||||||
]
|
|
||||||
embed = build_embed(
|
|
||||||
title="Warnings",
|
|
||||||
description=f"{user.mention} active and total warnings",
|
|
||||||
fields=fields,
|
|
||||||
)
|
)
|
||||||
embed.set_author(
|
active_warns = list(filter(lambda x: x.active, warnings))
|
||||||
name=user.nick if user.nick else user.name,
|
|
||||||
icon_url=user.avatar_url,
|
pages = []
|
||||||
|
if active:
|
||||||
|
if len(active_warns) == 0:
|
||||||
|
embed = build_embed(
|
||||||
|
title="Warnings",
|
||||||
|
description=f"{len(warnings)} total | 0 currently active",
|
||||||
|
fields=[],
|
||||||
|
)
|
||||||
|
embed.set_author(name=user.name, icon_url=user.avatar_url)
|
||||||
|
embed.set_thumbnail(url=ctx.guild.icon_url)
|
||||||
|
pages.append(embed)
|
||||||
|
else:
|
||||||
|
fields = []
|
||||||
|
for warn in active_warns:
|
||||||
|
fields.append(
|
||||||
|
Field(
|
||||||
|
name=warn.created_at.strftime(
|
||||||
|
"%Y-%m-%d %H:%M:%S UTC"
|
||||||
|
),
|
||||||
|
value=warn.reason + "\n\u200b",
|
||||||
|
inline=False,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
for i in range(0, len(fields), 5):
|
||||||
|
embed = build_embed(
|
||||||
|
title="Warnings",
|
||||||
|
description=f"{len(warnings)} total | "
|
||||||
|
+ f"{len(active_warns)} currently active",
|
||||||
|
fields=fields[i : i + 5],
|
||||||
|
)
|
||||||
|
embed.set_author(
|
||||||
|
name=user.name + "#" + user.discriminator,
|
||||||
|
icon_url=user.avatar_url,
|
||||||
|
)
|
||||||
|
embed.set_thumbnail(url=ctx.guild.icon_url)
|
||||||
|
pages.append(embed)
|
||||||
|
else:
|
||||||
|
fields = []
|
||||||
|
for warn in warnings:
|
||||||
|
title = "[A] " if warn.active else "[I] "
|
||||||
|
title += warn.created_at.strftime("%Y-%m-%d %H:%M:%S UTC")
|
||||||
|
fields.append(
|
||||||
|
Field(
|
||||||
|
name=title,
|
||||||
|
value=warn.reason + "\n\u200b",
|
||||||
|
inline=False,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
for i in range(0, len(fields), 5):
|
||||||
|
embed = build_embed(
|
||||||
|
title="Warnings",
|
||||||
|
description=f"{len(warnings)} total | "
|
||||||
|
+ f"{len(active_warns)} currently active",
|
||||||
|
fields=fields[i : i + 5],
|
||||||
|
)
|
||||||
|
embed.set_author(
|
||||||
|
name=user.name + "#" + user.discriminator,
|
||||||
|
icon_url=user.avatar_url,
|
||||||
|
)
|
||||||
|
embed.set_thumbnail(url=ctx.guild.icon_url)
|
||||||
|
pages.append(embed)
|
||||||
|
|
||||||
|
paginator = Paginator(
|
||||||
|
bot=self.bot,
|
||||||
|
ctx=ctx,
|
||||||
|
embeds=pages,
|
||||||
|
only=ctx.author,
|
||||||
|
timeout=60 * 5, # 5 minute timeout
|
||||||
|
disable_after_timeout=True,
|
||||||
|
use_extend=len(pages) > 2,
|
||||||
|
left_button_style=ButtonStyle.grey,
|
||||||
|
right_button_style=ButtonStyle.grey,
|
||||||
|
basic_buttons=["◀", "▶"],
|
||||||
)
|
)
|
||||||
embed.set_footer(text=f"{user.name}#{user.discriminator} | {user.id}")
|
|
||||||
embed.set_thumbnail(url=user.avatar_url)
|
self.cache[hash(paginator)] = {
|
||||||
await ctx.send(embed=embed)
|
"guild": ctx.guild.id,
|
||||||
|
"user": ctx.author.id,
|
||||||
|
"timeout": datetime.utcnow() + timedelta(minutes=5),
|
||||||
|
"command": ctx.subcommand_name,
|
||||||
|
"user_id": user.id,
|
||||||
|
"active": active,
|
||||||
|
"paginator": paginator,
|
||||||
|
}
|
||||||
|
|
||||||
|
await paginator.start()
|
||||||
|
|
||||||
@cog_ext.cog_subcommand(
|
@cog_ext.cog_subcommand(
|
||||||
base="roleping",
|
base="roleping",
|
||||||
|
@ -1041,6 +1198,15 @@ class AdminCog(commands.Cog):
|
||||||
f"Autopurge delay updated to {delay} seconds on {channel.mention}."
|
f"Autopurge delay updated to {delay} seconds on {channel.mention}."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@loop(minutes=1)
|
||||||
|
async def _expire_interaction(self):
|
||||||
|
keys = list(self.cache.keys())
|
||||||
|
for key in keys:
|
||||||
|
if self.cache[key]["timeout"] <= datetime.utcnow() + timedelta(
|
||||||
|
minutes=1
|
||||||
|
):
|
||||||
|
del self.cache[key]
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(AdminCog(bot))
|
bot.add_cog(AdminCog(bot))
|
||||||
|
|
|
@ -1,12 +1,29 @@
|
||||||
|
import re
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
import pymongo
|
||||||
|
from ButtonPaginator import Paginator
|
||||||
|
from discord import Member, User
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from discord_slash import cog_ext
|
from discord.ext.tasks import loop
|
||||||
|
from discord.utils import find
|
||||||
|
from discord_slash import SlashContext, cog_ext
|
||||||
|
from discord_slash.model import ButtonStyle
|
||||||
|
|
||||||
from jarvis.config import get_config
|
from jarvis.config import get_config
|
||||||
from jarvis.db import DBManager
|
from jarvis.db import DBManager
|
||||||
|
from jarvis.utils import build_embed
|
||||||
|
from jarvis.utils.field import Field
|
||||||
|
|
||||||
guild_ids = [578757004059738142, 520021794380447745, 862402786116763668]
|
guild_ids = [578757004059738142, 520021794380447745, 862402786116763668]
|
||||||
|
|
||||||
|
valid = re.compile(r"[\w\s\-\\/.!@#$%^*()+=<>,\u0080-\U000E0FFF]*")
|
||||||
|
invites = re.compile(
|
||||||
|
r"(?:https?://)?(?:www.)?(?:discord.(?:gg|io|me|li)|discord(?:app)?.com/invite)/([^\s/]+?)(?=\b)",
|
||||||
|
flags=re.IGNORECASE,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class CTCCog(commands.Cog):
|
class CTCCog(commands.Cog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
|
@ -15,6 +32,19 @@ class CTCCog(commands.Cog):
|
||||||
self.db = DBManager(mconf).mongo
|
self.db = DBManager(mconf).mongo
|
||||||
self._session = aiohttp.ClientSession()
|
self._session = aiohttp.ClientSession()
|
||||||
self.url = "https://completethecodetwo.cards/pw"
|
self.url = "https://completethecodetwo.cards/pw"
|
||||||
|
self.cache = {}
|
||||||
|
self._expire_interaction.start()
|
||||||
|
|
||||||
|
def check_cache(self, ctx: SlashContext, **kwargs):
|
||||||
|
if not kwargs:
|
||||||
|
kwargs = {}
|
||||||
|
return find(
|
||||||
|
lambda x: x["command"] == ctx.subcommand_name
|
||||||
|
and x["user"] == ctx.author.id
|
||||||
|
and x["guild"] == ctx.guild.id
|
||||||
|
and all(x[k] == v for k, v in kwargs.items()),
|
||||||
|
self.cache.values(),
|
||||||
|
)
|
||||||
|
|
||||||
@cog_ext.cog_subcommand(
|
@cog_ext.cog_subcommand(
|
||||||
base="ctc2",
|
base="ctc2",
|
||||||
|
@ -33,23 +63,129 @@ class CTCCog(commands.Cog):
|
||||||
guild_ids=guild_ids,
|
guild_ids=guild_ids,
|
||||||
)
|
)
|
||||||
@commands.cooldown(1, 2, commands.BucketType.user)
|
@commands.cooldown(1, 2, commands.BucketType.user)
|
||||||
async def _pw(self, ctx, guess: str):
|
async def _pw(self, ctx: SlashContext, guess: str):
|
||||||
|
if len(guess) > 800:
|
||||||
|
await ctx.send(
|
||||||
|
"Listen here, dipshit. Don't be like "
|
||||||
|
+ "<@256110768724901889>. Make your guesses < 800 characters.",
|
||||||
|
hidden=True,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
elif not valid.fullmatch(guess):
|
||||||
|
await ctx.send(
|
||||||
|
"Listen here, dipshit. Don't be like "
|
||||||
|
+ "<@256110768724901889>. Make your guesses *readable*.",
|
||||||
|
hidden=True,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
elif invites.search(guess):
|
||||||
|
await ctx.send(
|
||||||
|
"Listen here, dipshit. "
|
||||||
|
+ "No using this to bypass sending invite links.",
|
||||||
|
hidden=True,
|
||||||
|
)
|
||||||
|
return
|
||||||
guessed = self.db.ctc2.guesses.find_one({"guess": guess})
|
guessed = self.db.ctc2.guesses.find_one({"guess": guess})
|
||||||
if guessed:
|
if guessed:
|
||||||
await ctx.send("Already guessed, dipshit.", hidden=True)
|
await ctx.send("Already guessed, dipshit.", hidden=True)
|
||||||
return
|
return
|
||||||
result = await self._session.post(self.url, data=guess)
|
result = await self._session.post(self.url, data=guess)
|
||||||
message = ""
|
|
||||||
correct = False
|
correct = False
|
||||||
if 200 <= result.status < 400:
|
if 200 <= result.status < 400:
|
||||||
message = f"{ctx.author.mention} got it! Password is {guess}!"
|
await ctx.send(
|
||||||
|
f"{ctx.author.mention} got it! Password is {guess}!"
|
||||||
|
)
|
||||||
correct = True
|
correct = True
|
||||||
else:
|
else:
|
||||||
message = "Nope."
|
await ctx.send("Nope.", hidden=True)
|
||||||
self.db.ctc2.guesses.insert_one(
|
self.db.ctc2.guesses.insert_one(
|
||||||
{"guess": guess, "user": ctx.author.id, "correct": correct}
|
{"guess": guess, "user": ctx.author.id, "correct": correct}
|
||||||
)
|
)
|
||||||
await ctx.send(message)
|
|
||||||
|
@cog_ext.cog_subcommand(
|
||||||
|
base="ctc2",
|
||||||
|
name="guesses",
|
||||||
|
description="Show guesses made for https://completethecodetwo.cards",
|
||||||
|
guild_ids=guild_ids,
|
||||||
|
)
|
||||||
|
@commands.cooldown(1, 2, commands.BucketType.user)
|
||||||
|
async def _guesses(self, ctx: SlashContext):
|
||||||
|
exists = self.check_cache(ctx)
|
||||||
|
if exists:
|
||||||
|
await ctx.defer(hidden=True)
|
||||||
|
await ctx.send(
|
||||||
|
"Please use existing interaction: "
|
||||||
|
+ f"{exists['paginator']._message.jump_url}",
|
||||||
|
hidden=True,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
guesses = self.db.ctc2.guesses.find().sort(
|
||||||
|
[("correct", pymongo.DESCENDING), ("_id", pymongo.DESCENDING)]
|
||||||
|
)
|
||||||
|
fields = []
|
||||||
|
for guess in guesses:
|
||||||
|
user = ctx.guild.get_member(guess["user"])
|
||||||
|
if not user:
|
||||||
|
user = self.bot.fetch_user(guess["user"])
|
||||||
|
if not user:
|
||||||
|
user = "[redacted]"
|
||||||
|
if isinstance(user, User) or isinstance(user, Member):
|
||||||
|
user = user.name + "#" + user.discriminator
|
||||||
|
name = "Correctly" if guess["correct"] else "Incorrectly"
|
||||||
|
name += " guessed by: " + user
|
||||||
|
fields.append(
|
||||||
|
Field(
|
||||||
|
name=name,
|
||||||
|
value=guess["guess"] + "\n\u200b",
|
||||||
|
inline=False,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
pages = []
|
||||||
|
for i in range(0, len(fields), 5):
|
||||||
|
embed = build_embed(
|
||||||
|
title="completethecodetwo.cards guesses",
|
||||||
|
description=f"{len(fields)} guesses so far",
|
||||||
|
fields=fields[i : i + 5],
|
||||||
|
url="https://completethecodetwo.cards",
|
||||||
|
)
|
||||||
|
embed.set_thumbnail(url="https://dev.zevaryx.com/db_logo.png")
|
||||||
|
embed.set_footer(
|
||||||
|
text="dbrand.com",
|
||||||
|
icon_url="https://dev.zevaryx.com/db_logo.png",
|
||||||
|
)
|
||||||
|
pages.append(embed)
|
||||||
|
|
||||||
|
paginator = Paginator(
|
||||||
|
bot=self.bot,
|
||||||
|
ctx=ctx,
|
||||||
|
embeds=pages,
|
||||||
|
timeout=60 * 5, # 5 minute timeout
|
||||||
|
only=ctx.author,
|
||||||
|
disable_after_timeout=True,
|
||||||
|
use_extend=len(pages) > 2,
|
||||||
|
left_button_style=ButtonStyle.grey,
|
||||||
|
right_button_style=ButtonStyle.grey,
|
||||||
|
basic_buttons=["◀", "▶"],
|
||||||
|
)
|
||||||
|
|
||||||
|
self.cache[hash(paginator)] = {
|
||||||
|
"guild": ctx.guild.id,
|
||||||
|
"user": ctx.author.id,
|
||||||
|
"timeout": datetime.utcnow() + timedelta(minutes=5),
|
||||||
|
"command": ctx.subcommand_name,
|
||||||
|
"paginator": paginator,
|
||||||
|
}
|
||||||
|
|
||||||
|
await paginator.start()
|
||||||
|
|
||||||
|
@loop(minutes=1)
|
||||||
|
async def _expire_interaction(self):
|
||||||
|
keys = list(self.cache.keys())
|
||||||
|
for key in keys:
|
||||||
|
if self.cache[key]["timeout"] <= datetime.utcnow() + timedelta(
|
||||||
|
minutes=1
|
||||||
|
):
|
||||||
|
del self.cache[key]
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
|
|
|
@ -5,9 +5,8 @@ from ButtonPaginator import Paginator
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from discord.ext.tasks import loop
|
from discord.ext.tasks import loop
|
||||||
from discord.utils import find
|
from discord.utils import find
|
||||||
from discord_slash import ComponentContext, SlashContext, cog_ext
|
from discord_slash import SlashContext, cog_ext
|
||||||
from discord_slash.model import ButtonStyle
|
from discord_slash.model import ButtonStyle
|
||||||
from discord_slash.utils import manage_components
|
|
||||||
from discord_slash.utils.manage_commands import create_choice, create_option
|
from discord_slash.utils.manage_commands import create_choice, create_option
|
||||||
|
|
||||||
from jarvis.config import get_config
|
from jarvis.config import get_config
|
||||||
|
@ -29,6 +28,16 @@ class GitlabCog(commands.Cog):
|
||||||
self.cache = {}
|
self.cache = {}
|
||||||
self._expire_interaction.start()
|
self._expire_interaction.start()
|
||||||
|
|
||||||
|
def check_cache(self, ctx: SlashContext, **kwargs):
|
||||||
|
if not kwargs:
|
||||||
|
kwargs = {}
|
||||||
|
return find(
|
||||||
|
lambda x: x["command"] == ctx.subcommand_name
|
||||||
|
and x["user"] == ctx.author.id
|
||||||
|
and all(x[k] == v for k, v in kwargs.items()),
|
||||||
|
self.cache.values(),
|
||||||
|
)
|
||||||
|
|
||||||
@cog_ext.cog_subcommand(
|
@cog_ext.cog_subcommand(
|
||||||
base="gl",
|
base="gl",
|
||||||
name="issue",
|
name="issue",
|
||||||
|
@ -288,16 +297,6 @@ class GitlabCog(commands.Cog):
|
||||||
)
|
)
|
||||||
return embed
|
return embed
|
||||||
|
|
||||||
def check_cache(self, ctx: SlashContext, **kwargs):
|
|
||||||
if not kwargs:
|
|
||||||
kwargs = {}
|
|
||||||
return find(
|
|
||||||
lambda x: x["command"] == ctx.subcommand_name
|
|
||||||
and x["user"] == ctx.author.id
|
|
||||||
and all(x[k] == v for k, v in kwargs.items()),
|
|
||||||
self.cache.values(),
|
|
||||||
)
|
|
||||||
|
|
||||||
@cog_ext.cog_subcommand(
|
@cog_ext.cog_subcommand(
|
||||||
base="gl",
|
base="gl",
|
||||||
name="issues",
|
name="issues",
|
||||||
|
|
Loading…
Add table
Reference in a new issue