From 72acb35dd6b01684a0972c32a24dea206f63aecd Mon Sep 17 00:00:00 2001 From: Mike Tung Date: Sun, 24 Dec 2017 13:34:34 -0500 Subject: [PATCH 1/3] #7 added config.json which will be ignored. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 265a4a5..b348bd0 100644 --- a/.gitignore +++ b/.gitignore @@ -100,3 +100,4 @@ ENV/ # mypy .mypy_cache/ .idea +/config.json From b0b384af6b5b0d1627e97d5a1dbf93f24c78e8ad Mon Sep 17 00:00:00 2001 From: Mike Tung Date: Sun, 24 Dec 2017 14:04:51 -0500 Subject: [PATCH 2/3] #7 added settings py to configure our setup, and bot.py with code to start our bot. --- bot.py | 24 ++++++++++++++++++++++++ settings.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 bot.py create mode 100644 settings.py diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..4642c0a --- /dev/null +++ b/bot.py @@ -0,0 +1,24 @@ +""" +Awesomebot entry point +Mike Tung (seekheart) +""" + +import discord +import asyncio +from settings import CREDS, PREFIX, logger + + + +def init_bot(): + """Creates a discord client connection""" + return discord.Client() + +client = init_bot() + +@client.event +async def on_ready(): + """Logs the bot in for operations""" + print('logged in as {}'.format(client.user.name)) + +if __name__ == '__main__': + client.run(CREDS['token']) diff --git a/settings.py b/settings.py new file mode 100644 index 0000000..151c41c --- /dev/null +++ b/settings.py @@ -0,0 +1,35 @@ +""" +Awesome Bot Settings +Mike Tung (seekheart) +""" + +import json +import logging +import os + + +# setup logger format +logger = logging.getLogger() +handler = logging.StreamHandler() +formatter = logging.Formatter( + '%(asctime)s %(name)-12s %(levelname)-8s %(message)s') +handler.setFormatter(formatter) +logger.addHandler(handler) + + +# setup configurations +ENV = os.environ.get('ENV', 'DEV') +CONFIG = os.environ.get('BOT_CONFIG', None) +CREDS = {} +with open(CONFIG, 'r') as c: + c = json.load(c) + CREDS['id'] = c['clientId'] + CREDS['secret'] = c['clientSecret'] + CREDS['token'] = c['token'] + PREFIX = c['botPrefix'] + +if ENV == 'PROD': + logger.setLevel(logging.INFO) +else: + logger.setLevel(logging.DEBUG) + From 65a82ae7856849b3bcd17212022b37522d4a8c87 Mon Sep 17 00:00:00 2001 From: Mike Tung Date: Tue, 26 Dec 2017 12:58:20 -0500 Subject: [PATCH 3/3] #8 added example config json --- example_config.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 example_config.json diff --git a/example_config.json b/example_config.json new file mode 100644 index 0000000..30292ad --- /dev/null +++ b/example_config.json @@ -0,0 +1,6 @@ +{ + "clientId": 123, + "clientSecret": "abc", + "botPrefix": "ab", + "token": "TOKEN" +} \ No newline at end of file