Skip to content
This repository has been archived by the owner on Oct 15, 2023. It is now read-only.

[slashtags] update slashtags for dpy2 #175

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Once the bot is installed, run the following command in Discord:
| Ratings | 1.0.0 | <details><summary>Find out how (simp/sane/smart) you are.</summary>Rate yourself on many things.</details> | PhenoM4n4n |
| RoleUtils | 1.4.0 | <details><summary>Reaction roles, massroling, and role targeting!.</summary>Reaction roles, massroling, and role targeting!.</details> | PhenoM4n4n, Bobloy, TrustyJaid, and Neuro Assassin |
| Calculator | 1.0.1 | <details><summary>Calculate stuff</summary>Calculate stuff</details> | PhenoM4n4n |
| SlashTags | 0.6.2 | <details><summary>Create custom slash commands.</summary>Create custom slash commands.</details> | PhenoM4n4n |
| SlashTags | 0.7.0 | <details><summary>Create custom slash commands.</summary>Create custom slash commands.</details> | PhenoM4n4n |
| Tags | 2.4.1 | <details><summary>Create and use tags.</summary>Create and use tags.</details> | PhenoM4n4n, sravan, and npc203 |
| TypeRacer | 1.0.4 | <details><summary>Race to see who can type the fastest!</summary>Race to see who can type the fastest!</details> | Cats3153 and PhenoM4n4n |
| Webhook | 1.3.0 | <details><summary>Webhook related commands.</summary>Various webhook commands to create and send messages along webhooks.</details> | PhenoM4n4n |
Expand Down
13 changes: 8 additions & 5 deletions disboardreminder/disboardreminder.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import asyncio
import logging
import re
from collections import defaultdict
from datetime import datetime, timezone
from typing import Coroutine, DefaultDict, Dict, Optional
Expand All @@ -42,6 +41,7 @@
DISBOARD_BOT_ID = 302050872383242240
LOCK_REASON = "DisboardReminder auto-lock"


class DisboardReminder(commands.Cog):
"""
Set a reminder to bump on Disboard.
Expand Down Expand Up @@ -427,8 +427,11 @@ def validate_cache(self, message: discord.Message) -> Optional[discord.TextChann
def validate_success(self, message: discord.Message) -> bool:
if not message.embeds or not message.interaction:
return False

return message.interaction.type == discord.InteractionType.application_command and message.interaction.name == "bump"

return (
message.interaction.type == discord.InteractionType.application_command
and message.interaction.name == "bump"
)

async def respond_to_bump(
self,
Expand Down Expand Up @@ -478,10 +481,10 @@ async def on_message_without_command(self, message: discord.Message):
data = await self.config.guild(guild).all()
if not data["channel"]:
return

clean = data["clean"]
my_perms = channel.permissions_for(guild.me)

if self.validate_success(message):
last_bump = data["nextBump"]
if last_bump and last_bump - message.created_at.timestamp() > 0:
Expand Down
4 changes: 3 additions & 1 deletion roleutils/reactroles.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,9 @@ async def react_list(self, ctx: commands.Context):
embeds = []
pages = pagify(description, delims=["\n\n", "\n"])
base_embed = discord.Embed(color=color)
base_embed.set_author(name="Reaction Roles", icon_url=ctx.guild.icon.url if guild.icon else None)
base_embed.set_author(
name="Reaction Roles", icon_url=ctx.guild.icon.url if guild.icon else None
)
for page in pages:
e = base_embed.copy()
e.description = page
Expand Down
10 changes: 1 addition & 9 deletions slashtags/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SlashTags(Commands, Processor, commands.Cog, metaclass=CompositeMetaClass)
The TagScript documentation can be found [here](https://phen-cogs.readthedocs.io/en/latest/index.html).
"""

__version__ = "0.6.2"
__version__ = "0.7.0"
__author__ = ("PhenoM4n4n",)

def format_help_for_context(self, ctx: commands.Context):
Expand Down Expand Up @@ -260,14 +260,6 @@ async def restore_tags(self, ctx: commands.Context, guild: Optional[discord.Guil
def get_command(self, command_id: int) -> ApplicationCommand:
return self.command_cache.get(command_id)

@commands.Cog.listener()
async def on_interaction(self, interaction: discord.Interaction):
if interaction.type != discord.InteractionType.application_command:
return
wrapped = InteractionCommandWrapper(interaction, self)
log.debug("Received interaction %r", wrapped)
await self.handle_slash_interaction(wrapped)

async def handle_slash_interaction(self, interaction: InteractionCommandWrapper):
try:
await self.invoke_and_catch(interaction)
Expand Down
42 changes: 42 additions & 0 deletions slashtags/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from redbot.core.bot import Red
from redbot.core.utils.chat_formatting import box, pagify

from .errors import SlashTagException
from .http import (
ApplicationCommandType,
ApplicationOptionChoice,
Expand Down Expand Up @@ -129,6 +130,7 @@ class ApplicationCommand:
"options",
"type",
"version",
"_dpy_command",
)

def __init__(
Expand All @@ -155,6 +157,7 @@ def __init__(
self.type = type
self.options = options.copy()
self.version = version
self._dpy_command = None

def __str__(self) -> str:
return self.name
Expand Down Expand Up @@ -254,6 +257,45 @@ async def delete(self):

def add_to_cache(self):
self.cog.command_cache[self.id] = self
guild = discord.Object(self.guild_id) if self.guild_id else None
if self.type == ApplicationCommandType.CHAT_INPUT:
deco = self.cog.bot.tree.command(
name=self.name, description=self.description, guild=guild
)

async def processor(interaction: discord.Interaction):
if interaction.type != discord.InteractionType.application_command:
return
wrapped = InteractionCommandWrapper(interaction, self.cog)
log.debug("Received app command %r", wrapped)
await self.cog.handle_slash_interaction(wrapped)

else:
deco = self.cog.bot.tree.context_menu(name=self.name, guild=guild)

if self.type == ApplicationCommandType.USER:

async def processor(interaction: discord.Interaction, user: discord.User):
if interaction.type != discord.InteractionType.application_command:
return
wrapped = InteractionCommandWrapper(interaction, self.cog)
log.debug("Received user command %r", wrapped)
await self.cog.handle_slash_interaction(wrapped)

elif self.type == ApplicationCommandType.MESSAGE:

async def processor(interaction: discord.Interaction, message: discord.Message):
if interaction.type != discord.InteractionType.application_command:
return
wrapped = InteractionCommandWrapper(interaction, self.cog)
log.debug("Received message command %r", wrapped)
await self.cog.handle_slash_interaction(wrapped)

else:
raise SlashTagException(f"Unknown application command type: {self.type}")

self._dpy_command = deco(processor)
log.debug("dpy command created %s | %r", self.name, self._dpy_command)

def remove_from_cache(self):
try:
Expand Down