|
1 |
| -from typing import Literal, Optional |
2 |
| - |
3 |
| -import discord |
4 |
| -from discord import app_commands |
5 |
| -from discord.ext import commands |
6 |
| -from discord.ext.commands import Context, Greedy |
7 |
| -from kumikocore import KumikoCore |
8 |
| - |
9 |
| - |
10 |
| -def is_nat(): |
11 |
| - def pred(ctx): |
12 |
| - return ( |
13 |
| - ctx.guild is not None and ctx.author.id == 1028431063321686036 |
14 |
| - ) # natalie's account |
15 |
| - |
16 |
| - return commands.check(pred) |
17 |
| - |
18 |
| - |
19 |
| -class DevTools(commands.Cog, command_attrs=dict(hidden=True)): |
20 |
| - """Tools for developing Kumiko""" |
21 |
| - |
22 |
| - def __init__(self, bot: KumikoCore): |
23 |
| - self.bot = bot |
24 |
| - |
25 |
| - @property |
26 |
| - def display_emoji(self) -> discord.PartialEmoji: |
27 |
| - return discord.PartialEmoji(name="\U0001f6e0") |
28 |
| - |
29 |
| - @commands.hybrid_command(name="sync") |
30 |
| - @commands.guild_only() |
31 |
| - @commands.check_any(commands.is_owner(), is_nat()) |
32 |
| - async def sync( |
33 |
| - self, |
34 |
| - ctx: Context, |
35 |
| - guilds: Greedy[discord.Object], |
36 |
| - spec: Optional[Literal["~", "*", "^"]] = None, |
37 |
| - ) -> None: |
38 |
| - """Performs a sync of the tree. This will sync, copy globally, or clear the tree. |
39 |
| -
|
40 |
| - Args: |
41 |
| - ctx (Context): Context of the command |
42 |
| - guilds (Greedy[discord.Object]): Which guilds to sync to. Greedily accepts a number of guilds |
43 |
| - spec (Optional[Literal["~", "*", "^"], optional): Specs to sync. |
44 |
| - """ |
45 |
| - await ctx.defer() |
46 |
| - if not guilds: |
47 |
| - if spec == "~": |
48 |
| - synced = await self.bot.tree.sync(guild=ctx.guild) |
49 |
| - elif spec == "*": |
50 |
| - self.bot.tree.copy_global_to(guild=ctx.guild) # type: ignore |
51 |
| - synced = await self.bot.tree.sync(guild=ctx.guild) |
52 |
| - elif spec == "^": |
53 |
| - self.bot.tree.clear_commands(guild=ctx.guild) |
54 |
| - await self.bot.tree.sync(guild=ctx.guild) |
55 |
| - synced = [] |
56 |
| - else: |
57 |
| - synced = await self.bot.tree.sync() |
58 |
| - |
59 |
| - await ctx.send( |
60 |
| - f"Synced {len(synced)} commands {'globally' if spec is None else 'to the current guild.'}" |
61 |
| - ) |
62 |
| - return |
63 |
| - |
64 |
| - ret = 0 |
65 |
| - for guild in guilds: |
66 |
| - try: |
67 |
| - await self.bot.tree.sync(guild=guild) |
68 |
| - except discord.HTTPException: |
69 |
| - pass |
70 |
| - else: |
71 |
| - ret += 1 |
72 |
| - |
73 |
| - await ctx.send(f"Synced the tree to {ret}/{len(guilds)}.") |
74 |
| - |
75 |
| - @commands.hybrid_command(name="dispatch") |
76 |
| - @commands.guild_only() |
77 |
| - @commands.check_any(commands.is_owner(), is_nat()) |
78 |
| - @app_commands.describe(event="The event to dispatch") |
79 |
| - async def dispatch_event(self, ctx: commands.Context, event: str) -> None: |
80 |
| - """Dispatches an custom event |
81 |
| -
|
82 |
| - Args: |
83 |
| - ctx (commands.Context): _description_ |
84 |
| - """ |
85 |
| - self.bot.dispatch(event, ctx.guild, ctx.author) |
86 |
| - await ctx.send("Dispatched event") |
87 |
| - |
88 |
| - @commands.check_any(commands.is_owner(), is_nat()) |
89 |
| - @commands.command(name="arg-check", usage="<user: discord.Member>") |
90 |
| - async def arg_check(self, ctx: commands.Context, user: discord.Member): |
91 |
| - """Testing arg checks |
92 |
| -
|
93 |
| - Args: |
94 |
| - user (discord.Member): The member to ping lol |
95 |
| - """ |
96 |
| - await ctx.send(user.name) |
97 |
| - |
98 |
| - |
99 |
| -async def setup(bot: KumikoCore): |
100 |
| - await bot.add_cog(DevTools(bot)) |
| 1 | +from typing import Literal, Optional |
| 2 | + |
| 3 | +import discord |
| 4 | +from discord import app_commands |
| 5 | +from discord.ext import commands |
| 6 | +from discord.ext.commands import Context, Greedy |
| 7 | +from kumikocore import KumikoCore |
| 8 | + |
| 9 | + |
| 10 | +def is_nat(): |
| 11 | + def pred(ctx): |
| 12 | + return ( |
| 13 | + ctx.guild is not None and ctx.author.id == 1028431063321686036 |
| 14 | + ) # natalie's account |
| 15 | + |
| 16 | + return commands.check(pred) |
| 17 | + |
| 18 | + |
| 19 | +class DevTools(commands.Cog, command_attrs=dict(hidden=True)): |
| 20 | + """Tools for developing Kumiko""" |
| 21 | + |
| 22 | + def __init__(self, bot: KumikoCore): |
| 23 | + self.bot = bot |
| 24 | + |
| 25 | + @property |
| 26 | + def display_emoji(self) -> discord.PartialEmoji: |
| 27 | + return discord.PartialEmoji(name="\U0001f6e0") |
| 28 | + |
| 29 | + @commands.hybrid_command(name="sync") |
| 30 | + @commands.guild_only() |
| 31 | + @commands.check_any(commands.is_owner(), is_nat()) |
| 32 | + async def sync( |
| 33 | + self, |
| 34 | + ctx: Context, |
| 35 | + guilds: Greedy[discord.Object], |
| 36 | + spec: Optional[Literal["~", "*", "^"]] = None, |
| 37 | + ) -> None: |
| 38 | + """Performs a sync of the tree. This will sync, copy globally, or clear the tree. |
| 39 | +
|
| 40 | + Args: |
| 41 | + ctx (Context): Context of the command |
| 42 | + guilds (Greedy[discord.Object]): Which guilds to sync to. Greedily accepts a number of guilds |
| 43 | + spec (Optional[Literal["~", "*", "^"], optional): Specs to sync. |
| 44 | + """ |
| 45 | + await ctx.defer() |
| 46 | + if not guilds: |
| 47 | + if spec == "~": |
| 48 | + synced = await self.bot.tree.sync(guild=ctx.guild) |
| 49 | + elif spec == "*": |
| 50 | + self.bot.tree.copy_global_to(guild=ctx.guild) # type: ignore |
| 51 | + synced = await self.bot.tree.sync(guild=ctx.guild) |
| 52 | + elif spec == "^": |
| 53 | + self.bot.tree.clear_commands(guild=ctx.guild) |
| 54 | + await self.bot.tree.sync(guild=ctx.guild) |
| 55 | + synced = [] |
| 56 | + else: |
| 57 | + synced = await self.bot.tree.sync() |
| 58 | + |
| 59 | + await ctx.send( |
| 60 | + f"Synced {len(synced)} commands {'globally' if spec is None else 'to the current guild.'}" |
| 61 | + ) |
| 62 | + return |
| 63 | + |
| 64 | + ret = 0 |
| 65 | + for guild in guilds: |
| 66 | + try: |
| 67 | + await self.bot.tree.sync(guild=guild) |
| 68 | + except discord.HTTPException: |
| 69 | + pass |
| 70 | + else: |
| 71 | + ret += 1 |
| 72 | + |
| 73 | + await ctx.send(f"Synced the tree to {ret}/{len(guilds)}.") |
| 74 | + |
| 75 | + @commands.hybrid_command(name="dispatch") |
| 76 | + @commands.guild_only() |
| 77 | + @commands.check_any(commands.is_owner(), is_nat()) |
| 78 | + @app_commands.describe(event="The event to dispatch") |
| 79 | + async def dispatch_event(self, ctx: commands.Context, event: str) -> None: |
| 80 | + """Dispatches an custom event |
| 81 | +
|
| 82 | + Args: |
| 83 | + ctx (commands.Context): _description_ |
| 84 | + """ |
| 85 | + self.bot.dispatch(event, ctx.guild) |
| 86 | + await ctx.send("Dispatched event") |
| 87 | + |
| 88 | + @commands.check_any(commands.is_owner(), is_nat()) |
| 89 | + @commands.command(name="arg-check", usage="<user: discord.Member>") |
| 90 | + async def arg_check(self, ctx: commands.Context, user: discord.Member): |
| 91 | + """Testing arg checks |
| 92 | +
|
| 93 | + Args: |
| 94 | + user (discord.Member): The member to ping lol |
| 95 | + """ |
| 96 | + await ctx.send(user.name) |
| 97 | + |
| 98 | + |
| 99 | +async def setup(bot: KumikoCore): |
| 100 | + await bot.add_cog(DevTools(bot)) |
0 commit comments