-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fa9d873
Showing
11 changed files
with
285 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# IDEA | ||
.idea/ | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 ReperakPro | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,12 @@ | ||
# waffle | ||
A libre framework for creating Discord.py bots. Simple, structured, and painless. | ||
|
||
## Making a command | ||
1. Create a Python file in the [command folder](commands) | ||
2. Write the command inside [a cog](https://discordpy.readthedocs.io/en/latest/ext/commands/cogs.html) | ||
3. Register your command in [cogregister.py](cogregister.py) | ||
|
||
## Running | ||
Install Discord.py - `$ pip3 install discord.py` | ||
|
||
Running the bot - `$ python3 waffle.py -t <TOKEN> -p <PREFIX>` |
Empty file.
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,15 @@ | ||
# To register or unregister a cog, place the location of the object in the relevant list. | ||
# | ||
# To load a cog located in "<PROJECT DIRECTORY>/commands/examplecommand.py", you would insert "commands.examplecommand" | ||
# into the appropriate list, omitting the .py file extension. | ||
# | ||
# If a command/event you've added doesn't load, check this file to see if you've forgotten to register the cog. | ||
# Note: events is also intended to be used for tasks, as well. | ||
|
||
commandregister = [ | ||
'commands.examplecommand' | ||
] | ||
|
||
eventregister = [ | ||
'events.exampleevent' | ||
] |
Empty file.
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,29 @@ | ||
from discord.ext import commands | ||
|
||
|
||
# For more information on commands, see | ||
# https://discordpy.readthedocs.io/en/latest/ext/commands/commands.html | ||
class ExampleCommand(commands.Cog): | ||
""" | ||
Pings the command sender and repeats the arguments it was given to them | ||
""" | ||
|
||
# Cog constructor | ||
def __init__(self, bot): | ||
self.bot = bot | ||
|
||
@commands.command() | ||
async def examplecommand(self, ctx, *args): | ||
message = 'Hello, {}! I recieved {} arguments with this command: {}.'.format( | ||
ctx.author.mention, # Used to @ someone | ||
len(args), # Length of args | ||
', '.join(args) # Prints the arguments with a comma and a space as a separator for each | ||
) | ||
|
||
# Sending the finalized message | ||
await ctx.send(message) | ||
|
||
|
||
# Constructor for loading the cog | ||
def setup(bot): | ||
bot.add_cog(ExampleCommand(bot)) |
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,25 @@ | ||
# If you're looking to expand upon the arguments, https://docs.python.org/3/library/argparse.html may be useful to you. | ||
from argparse import ArgumentParser | ||
__parser = ArgumentParser() | ||
|
||
# Essential configuration (e.g. token, prefix) | ||
__botdetails = __parser.add_argument_group('bot details') | ||
__botdetails.add_argument('-t', '--token', type=str, help='token for the bot') | ||
__botdetails.add_argument('-p', '--prefix', type=str, default='%', help='prefix for the bot') | ||
|
||
# Tuning configuration (e.g. disabling sharding) | ||
__bottuning = __parser.add_argument_group('bot tuning') | ||
__bottuning.add_argument('--no-auto-sharding', action='store_true', help='disable sharding') | ||
|
||
args = vars(__parser.parse_args()) | ||
|
||
|
||
def getarg(argname: str): | ||
""" | ||
Returns the value of a commandline argument. | ||
:param argname: Argument value to fetch | ||
:type argname: str | ||
""" | ||
|
||
return args[argname] |
Empty file.
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,25 @@ | ||
from discord.ext import commands | ||
|
||
|
||
# For more information on commands, see | ||
# https://discordpy.readthedocs.io/en/latest/api.html#event-reference | ||
class ExampleEvent(commands.Cog): | ||
""" | ||
Sends "Welcome!" in the system channel when a member joins the guild. | ||
""" | ||
|
||
# Cog constructor | ||
def __init__(self, bot): | ||
self.bot = bot | ||
|
||
@commands.Cog.listener() | ||
async def on_member_join(self, member): | ||
channel = member.guild.system_channel | ||
|
||
if channel is not None: # if the system channel is set | ||
await channel.send('Welcome!') | ||
|
||
|
||
# Constructor for loading the cog | ||
def setup(bot): | ||
bot.add_cog(ExampleEvent(bot)) |
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,26 @@ | ||
from discord.ext import commands | ||
|
||
from config import getarg | ||
from cogregister import commandregister, eventregister | ||
|
||
|
||
# Creates two types of bots based on the value of the --no-auto-sharding flag | ||
if getarg('no_auto_sharding'): | ||
bot = commands.Bot | ||
else: | ||
bot = commands.AutoShardedBot | ||
# Initialize method into bot object | ||
bot = bot(command_prefix=getarg('prefix')) | ||
|
||
|
||
# Loading cogs from register | ||
for x in commandregister: | ||
bot.load_extension(x) | ||
for x in eventregister: | ||
bot.load_extension(x) | ||
|
||
|
||
# Running | ||
bot.run( | ||
getarg('token') | ||
) |