Skip to content

Commit

Permalink
Update examples provided
Browse files Browse the repository at this point in the history
  • Loading branch information
No767 committed Dec 9, 2023
1 parent b27807d commit 4ddd9ab
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 17 deletions.
24 changes: 17 additions & 7 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Basic IPC
.. code-block:: python
import logging
import discord
from discord.ext import commands, ipcx
Expand All @@ -21,7 +22,7 @@ Basic IPC
super().__init__(command_prefix="!", intents=intents, *args, **kwargs)
self.ipc = ipcx.Server(
self, secret_key="my_secret_key" # nosec
) # Creating our IPC server
)
self.log = logging.getLogger("discord.ext.ipcx")
async def setup_hook(self):
Expand Down Expand Up @@ -57,6 +58,7 @@ Basic IPC
if __name__ == "__main__":
bot.run(TOKEN)
``webserver.py``

.. code-block:: python
Expand All @@ -67,8 +69,8 @@ Basic IPC
app = Quart(__name__)
ipc_client = ipcx.Client(
secret_key="my_secret_key" # nosec
) # secret_key must be the same as your server
secret_key="my_secret_key" # nosec # secret_key must be the same as your server
)
@app.route("/")
Expand All @@ -79,10 +81,14 @@ Basic IPC
return str(member_count) # display member count
@app.after_serving
async def close_session():
await ipc_client.close()
if __name__ == "__main__":
app.run()
Cog-based IPC
-------------

Expand Down Expand Up @@ -137,7 +143,7 @@ Cog-based IPC
super().__init__(command_prefix="!", intents=intents, *args, **kwargs)
self.ipc = ipcx.Server(
self, secret_key="my_secret_key" # nosec
) # Creating our IPC server
)
self.log = logging.getLogger("discord.ext.ipcx")
async def setup_hook(self):
Expand All @@ -164,6 +170,7 @@ Cog-based IPC
if __name__ == "__main__":
bot.run(TOKEN)
``webserver.py``

.. code-block:: python
Expand All @@ -174,8 +181,8 @@ Cog-based IPC
app = Quart(__name__)
ipc_client = ipcx.Client(
secret_key="my_secret_key" # nosec
) # secret_key must be the same as your server
secret_key="my_secret_key" # nosec # secret_key must be the same as your server
)
@app.route("/")
Expand All @@ -186,6 +193,9 @@ Cog-based IPC
return str(member_count) # display member count
@app.after_serving
async def close_session():
await ipc_client.close()
if __name__ == "__main__":
app.run()
app.run()
4 changes: 1 addition & 3 deletions examples/basic-ipc/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
class MyBot(commands.Bot):
def __init__(self, intents: discord.Intents, *args, **kwargs):
super().__init__(command_prefix="!", intents=intents, *args, **kwargs)
self.ipc = ipcx.Server(
self, secret_key="my_secret_key" # nosec
) # Creating our IPC server
self.ipc = ipcx.Server(self, secret_key="my_secret_key") # nosec
self.log = logging.getLogger("discord.ext.ipcx")

async def setup_hook(self):
Expand Down
9 changes: 7 additions & 2 deletions examples/basic-ipc/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

app = Quart(__name__)
ipc_client = ipcx.Client(
secret_key="my_secret_key" # nosec
) # secret_key must be the same as your server
secret_key="my_secret_key" # nosec # secret_key must be the same as your server
)


@app.route("/")
Expand All @@ -17,5 +17,10 @@ async def index():
return str(member_count) # display member count


@app.after_serving
async def close_session():
await ipc_client.close()


if __name__ == "__main__":
app.run()
4 changes: 1 addition & 3 deletions examples/cog-based-ipc/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
class MyBot(commands.Bot):
def __init__(self, intents: discord.Intents, *args, **kwargs):
super().__init__(command_prefix="!", intents=intents, *args, **kwargs)
self.ipc = ipcx.Server(
self, secret_key="my_secret_key" # nosec
) # Creating our IPC server
self.ipc = ipcx.Server(self, secret_key="my_secret_key") # nosec
self.log = logging.getLogger("discord.ext.ipcx")

async def setup_hook(self):
Expand Down
9 changes: 7 additions & 2 deletions examples/cog-based-ipc/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

app = Quart(__name__)
ipc_client = ipcx.Client(
secret_key="my_secret_key" # nosec
) # secret_key must be the same as your server
secret_key="my_secret_key" # nosec # secret_key must be the same as your server
)


@app.route("/")
Expand All @@ -17,5 +17,10 @@ async def index():
return str(member_count) # display member count


@app.after_serving
async def close_session():
await ipc_client.close()


if __name__ == "__main__":
app.run()

0 comments on commit 4ddd9ab

Please sign in to comment.