Skip to content

Commit

Permalink
refactor!: rename prelude to context
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentRPS committed Mar 17, 2023
1 parent 5ad5d10 commit 111a9d8
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ async def on_ready() -> None:

# give a high five to a user
@bot.command()
async def highfive(pre: pycord.Prelude) -> None:
async def highfive(ctx: pycord.Context) -> None:
# send a response to the command
await pre.send(':raised_hand: High Five!')
await ctx.send(':raised_hand: High Five!')

# this is only for certain things, which we allow the builder api for
view = pycord.View().url_button('Google it!', 'https://google.com')

# a command which sends a button to go to Google.
@bot.command()
async def google(pre: pycord.Prelude) -> None:
async def google(ctx: pycord.Context) -> None:
iview = view()
await pre.send('Just go to Google!', view=iview)
await ctx.send('Just go to Google!', view=iview)

# REMEMBER TO CHANGE THIS!
bot.run('token')
Expand Down Expand Up @@ -103,6 +103,6 @@ bot.run('token')

```py
@bot.command()
async def push(pre: pycord.Prelude, user: pycord.User) -> None:
await pre.send(f'{pre.user.mention} pushed {user.mention}!')
async def push(ctx: pycord.Context, user: pycord.User) -> None:
await pre.send(f'{ctx.user.mention} pushed {user.mention}!')
```
12 changes: 6 additions & 6 deletions examples/interactions/commands/application_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# this has the option anime, displayed as a Parameter,
# which is parsed by Pycord to give you the information the user gave.
async def favorite(
pre: pycord.Prelude,
ctx: pycord.Context,
# The name of this option,
# can be set to anything but
# try to keep it short
Expand Down Expand Up @@ -52,17 +52,17 @@ async def favorite(
# it responds with a custom response.
match anime:
case 'Attack on Titan':
await pre.send('It seems like you like Attack on Titan, Nice!')
await ctx.send('It seems like you like Attack on Titan, Nice!')
case "JoJo's Bizzare Adventure":
await pre.send("おにいちゃんありがとう. You like JoJo's Bizzare Adventure. Nice!")
await ctx.send("おにいちゃんありがとう. You like JoJo's Bizzare Adventure. Nice!")
case 'Cowboy Bebop':
await pre.send('良い!あなたはカウボーイビバップが好きです')
await ctx.send('良い!あなたはカウボーイビバップが好きです')
case 'Hunter x Hunter':
await pre.send(
await ctx.send(
'I ran out of responses... Well anyway, you like Hunter x Hunter which is Nice!'
)
case 'Spy x Family':
await pre.send(
await ctx.send(
'I have a friend which really likes this anime, '
"it's good seeing you like it too. Of course, Spy x Family!"
)
Expand Down
2 changes: 1 addition & 1 deletion pycord/commands/application/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
"""
from .command import *
from .errors import *
from .prelude import *
from .context import *
6 changes: 3 additions & 3 deletions pycord/commands/application/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from ..command import Command
from ..group import Group
from .errors import ApplicationCommandException
from .prelude import Prelude
from .context import Context

if TYPE_CHECKING:
from ...state import State
Expand Down Expand Up @@ -360,7 +360,7 @@ class ApplicationCommand(Command):
Defaults to False.
"""

_processor_event = InteractionCreate(Prelude)
_processor_event = InteractionCreate(Context)
sub_level: int = 0

def __init__(
Expand Down Expand Up @@ -535,7 +535,7 @@ def _parse_arguments(self) -> None:
for name, v in arg_defaults.items():
if name == 'self':
continue
elif v[1] is Interaction or v[1] is Prelude:
elif v[1] is Interaction or v[1] is Context:
continue
elif not isinstance(v[0], Option) and v[0] is not None:
raise ApplicationCommandException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from ...types import Interaction as InteractionData


class Prelude(Interaction):
class Context(Interaction):
"""
Contextual prelude to Interactions.
"""
Expand Down
7 changes: 5 additions & 2 deletions pycord/ext/gears/gear.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,15 @@ class Gear(Generic[ContextT]):

ctx: ContextT

def __init__(self, name: str, ctx: ContextT) -> None:
def __init__(self, name: str, ctx: ContextT | None = None) -> None:
self.name = name
self._listener_functions: dict[Type[Event], list[AsyncFunc]] = {}
self.bot: Bot
self._commands: list[Command | Group] = []
self.ctx = ctx
if ctx is None:
self.ctx = BaseContext()
else:
self.ctx = ctx

async def on_attach(self, *args, **kwargs) -> None:
...
Expand Down

0 comments on commit 111a9d8

Please sign in to comment.