aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2018-10-03 20:45:54 +0200
committerGravatar GitHub <[email protected]>2018-10-03 20:45:54 +0200
commit9a81988267408f3ca4c23083c9a4b771d6dc3d5f (patch)
treee16aae5974f0dd8eba556cc818d689ac170f309a
parentCreate CONTRIBUTING.md (diff)
parentUse docstrings instead of block comments. (diff)
Merge pull request #2 from markylon/master
Set up some simple Discord bot boilerplate.
-rw-r--r--bot/bot.py22
-rw-r--r--bot/cogs/template.py36
-rw-r--r--bot/constants.py0
-rw-r--r--requirements.txt10
-rw-r--r--tox.ini6
5 files changed, 74 insertions, 0 deletions
diff --git a/bot/bot.py b/bot/bot.py
new file mode 100644
index 00000000..a67fcdab
--- /dev/null
+++ b/bot/bot.py
@@ -0,0 +1,22 @@
+from pathlib import Path
+from sys import stderr
+from traceback import print_exc
+from os import environ
+
+from discord.ext import commands
+
+
+HACKTOBERBOT_TOKEN = environ.get('HACKTOBERBOT_TOKEN')
+bot = commands.Bot(command_prefix=commands.when_mentioned_or('!'))
+
+if __name__ == '__main__':
+ # Scan for files in the /cogs/ directory and make a list of the file names.
+ cogs = [file.stem for file in Path('cogs').glob('*.py')]
+ for extension in cogs:
+ try:
+ bot.load_extension(f'cogs.{extension}')
+ except Exception as e:
+ print(f'Failed to load extension {extension}.', file=stderr)
+ print_exc()
+
+bot.run(HACKTOBERBOT_TOKEN)
diff --git a/bot/cogs/template.py b/bot/cogs/template.py
new file mode 100644
index 00000000..89f12fe1
--- /dev/null
+++ b/bot/cogs/template.py
@@ -0,0 +1,36 @@
+from discord.ext import commands
+
+
+class Template:
+
+ """
+ A template cog that contains examples of commands and command groups.
+ """
+
+ def __init__(self, bot):
+ self.bot = bot
+
+ @commands.command(name='repo', aliases=['repository', 'project'], brief='A link to the repository of this bot.')
+ async def repository(self, ctx):
+ await ctx.send('https://github.com/discord-python/hacktoberbot')
+
+ @commands.group(name='git', invoke_without_command=True)
+ async def github(self, ctx):
+ """
+ A command group with the name git. You can now create sub-commands such as git commit.
+ """
+
+ await ctx.send('Resources to learn **Git**: https://try.github.io/.')
+
+ @github.command()
+ async def commit(self, ctx):
+ """
+ A command that belongs to the git command group. Invoked using git commit.
+ """
+
+ await ctx.send('`git commit -m "First commit"` commits tracked changes.')
+
+
+# Required in order to load the cog, use the class name in the add_cog function.
+def setup(bot):
+ bot.add_cog(Template(bot))
diff --git a/bot/constants.py b/bot/constants.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/bot/constants.py
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 00000000..850f73bb
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,10 @@
+aiohttp==3.4.4
+async-timeout==3.0.0
+attrs==18.2.0
+chardet==3.0.4
+discord.py==1.0.0a0
+idna==2.7
+idna-ssl==1.1.0
+multidict==4.4.2
+websockets==6.0
+yarl==1.2.6 \ No newline at end of file
diff --git a/tox.ini b/tox.ini
new file mode 100644
index 00000000..780c31d7
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,6 @@
+[flake8]
+max-line-length=120
+application_import_names=proj
+ignore=P102,B311,W503,E226,S311
+exclude=__pycache__, venv, .venv, tests
+import-order-style=pycharm