-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add example command / cog file. (#9) * Added poetry script for running the subclassed bot. * Added example runner script for testing. * Fixed bug after moving logging out to init file.
- Loading branch information
Rob
authored
Feb 15, 2021
1 parent
f9ced4c
commit 6c74ab4
Showing
8 changed files
with
149 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
# Testing | ||
examples/commands/ | ||
|
||
# JetBrains | ||
.idea/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,17 @@ | ||
""" | ||
dpymenus -- Simplified menus for discord.py developers. | ||
""" | ||
|
||
__title__ = "cogwatch" | ||
__author__ = "Rob Wagner <rob@robwagner.dev>" | ||
__license__ = "MIT" | ||
__copyright__ = "Copyright 2020-2021 Rob Wagner" | ||
__version__ = "2.1.0" | ||
|
||
import logging | ||
|
||
from cogwatch.cogwatch import Watcher, watch | ||
|
||
|
||
logger = logging.getLogger("cogwatch") | ||
logger.addHandler(logging.NullHandler()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from discord.ext import commands | ||
|
||
|
||
class Ping(commands.Cog): | ||
def __init__(self, client): | ||
self.client = client | ||
|
||
@commands.command() | ||
async def ping(self, ctx): | ||
await ctx.reply("Pong!") | ||
|
||
|
||
def setup(client): | ||
client.add_cog(Ping(client)) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# This is a testing module which interfaces with the documentation examples. You will need to | ||
# have an environment variable called "COGWATCH_BOT_TOKEN" set in order for this to run. This | ||
# module must live in the root directory. | ||
# | ||
# You can run this file directly or with `poetry run example`. | ||
|
||
import asyncio | ||
import logging | ||
import os | ||
import sys | ||
|
||
from cogwatch import watch | ||
from discord.ext import commands | ||
from dotenv import load_dotenv | ||
|
||
try: | ||
import uvloop | ||
except ImportError: | ||
uvloop = None | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
|
||
if sys.platform in {"linux", "macos"}: | ||
uvloop.install() | ||
logging.info("Using `uvloop` asyncio event loop.") | ||
|
||
load_dotenv() | ||
|
||
|
||
class ExampleRunner(commands.Bot): | ||
def __init__(self): | ||
super().__init__(command_prefix=".") | ||
|
||
@watch(path="examples/commands", preload=True) | ||
async def on_ready(self): | ||
logging.info("Bot ready.") | ||
|
||
async def on_message(self, message): | ||
logging.info(message) | ||
|
||
if message.author.bot: | ||
return | ||
|
||
await self.process_commands(message) | ||
|
||
|
||
async def main(): | ||
client = ExampleRunner() | ||
await client.start(os.getenv("COGWATCH_BOT_TOKEN")) | ||
|
||
|
||
def __poetry_run(): | ||
asyncio.run(main()) | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |