Skip to content

Commit

Permalink
Update RESTClient to GatewayClient in order to utilise Cache in hikar…
Browse files Browse the repository at this point in the history
…i fully
  • Loading branch information
patelheet30 committed Jan 1, 2024
1 parent bba0992 commit 47b905e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions FormulaForge/Extensions/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
from FormulaForge.Models.url import URLBuilder, convert_new_line_to_url_encoding


latex_images = arc.RESTPlugin("latex_images")
latex_images = arc.GatewayPlugin("latex_images")


@latex_images.include
@arc.slash_command(
name="latex_to_image", description="Convert LaTeX (Math Mode) to an image."
)
async def latex_to_image(
ctx: arc.RESTContext,
ctx: arc.GatewayContext,
is_transparent: arc.Option[
bool,
arc.BoolParams(
Expand Down Expand Up @@ -105,10 +105,10 @@ async def latex_to_image(


@arc.loader
def load(client: arc.RESTClient) -> None:
def load(client: arc.GatewayClient) -> None:
client.add_plugin(latex_images)


@arc.unloader
def unload(client: arc.RESTClient) -> None:
def unload(client: arc.GatewayClient) -> None:
client.remove_plugin(latex_images)
16 changes: 8 additions & 8 deletions FormulaForge/Extensions/unit_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from FormulaForge.utils.convert_temp import convert_temperature


unit_converter = arc.RESTPlugin("unit_converter")
unit_converter = arc.GatewayPlugin("unit_converter")

unit_convert_group = unit_converter.include_slash_group(
"unit_convert",
Expand Down Expand Up @@ -56,7 +56,7 @@ def embed_builder(value, from_unit, to_unit, converted_value):
@unit_convert_group.include
@arc.slash_subcommand(name="temperature", description="Convert temperature.")
async def temperature(
ctx: arc.RESTContext,
ctx: arc.GatewayContext,
temperature: arc.Option[
float,
arc.FloatParams(
Expand Down Expand Up @@ -94,7 +94,7 @@ async def temperature(
@unit_convert_group.include
@arc.slash_subcommand(name="speed", description="Convert speed.")
async def speed(
ctx: arc.RESTContext,
ctx: arc.GatewayContext,
speed: arc.Option[
float,
arc.FloatParams(
Expand Down Expand Up @@ -139,7 +139,7 @@ async def speed(
@unit_convert_group.include
@arc.slash_subcommand(name="mass", description="Convert mass.")
async def mass(
ctx: arc.RESTContext,
ctx: arc.GatewayContext,
mass: arc.Option[
float,
arc.FloatParams(
Expand Down Expand Up @@ -174,7 +174,7 @@ async def mass(
@unit_convert_group.include
@arc.slash_subcommand(name="energy", description="Convert energy.")
async def energy(
ctx: arc.RESTContext,
ctx: arc.GatewayContext,
energy: arc.Option[
float,
arc.FloatParams(
Expand Down Expand Up @@ -209,7 +209,7 @@ async def energy(
@unit_convert_group.include
@arc.slash_subcommand(name="length", description="Convert length.")
async def length(
ctx: arc.RESTContext,
ctx: arc.GatewayContext,
length: arc.Option[
float,
arc.FloatParams(
Expand Down Expand Up @@ -242,10 +242,10 @@ async def length(


@arc.loader
def load(client: arc.RESTClient) -> None:
def load(client: arc.GatewayClient) -> None:
client.add_plugin(unit_converter)


@arc.unloader
def unload(client: arc.RESTClient) -> None:
def unload(client: arc.GatewayClient) -> None:
client.remove_plugin(unit_converter)
2 changes: 1 addition & 1 deletion FormulaForge/Models/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ def __call__(self, *args, **kwargs) -> str:


def convert_new_line_to_url_encoding(formula_without_newline_encoding: str) -> str:
"""Converts \n to %0A"""
"""Converts newline to %0A which is the URL encoding for newline."""
return formula_without_newline_encoding.replace("\n", "%0A")
14 changes: 7 additions & 7 deletions FormulaForge/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@
import miru


class MyModal(miru.Modal[miru.REST]):
formula = miru.TextInput[miru.REST](
class MyModal(miru.Modal[miru.GW]):
formula = miru.TextInput[miru.GW](
label="Formula",
placeholder="Remember to add $ in Math Mode https://www1.cmc.edu/pages/faculty/aaksoy/latex/latexthree.html",
required=True,
style=hikari.TextInputStyle.PARAGRAPH,
)

async def callback(self, context: miru.ModalContext[miru.REST]) -> None:
async def callback(self, context: miru.ModalContext[miru.GW]) -> None:
await context.respond("Processing...")


TOKEN = os.environ["TOKEN"]

bot = hikari.RESTBot(token=TOKEN, logs="DEBUG")
modal_client = miru.RESTClient(bot)
client = arc.RESTClient(bot)
bot = hikari.GatewayBot(token=TOKEN, logs="DEBUG")
modal_client = miru.GatewayClient(bot)
client = arc.GatewayClient(bot)


@client.include
@arc.slash_command(name="ping", description="Ping the bot.")
async def ping_slash(ctx: arc.RESTContext) -> None:
async def ping_slash(ctx: arc.GatewayContext) -> None:
await ctx.respond("Pong!")


Expand Down

0 comments on commit 47b905e

Please sign in to comment.