From b95e5d2b40891d08c165cc0319d5b066fcc25522 Mon Sep 17 00:00:00 2001 From: xedre Date: Fri, 5 Oct 2018 22:14:11 +0100 Subject: Create .gitignore --- .gitignore | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..a8072aaf --- /dev/null +++ b/.gitignore @@ -0,0 +1,107 @@ +# 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/ +*.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/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# 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/ + +# jetbrains +.idea/ -- cgit v1.2.3 From 1dc7d3859e071b3587e41098ceaff37971317c9a Mon Sep 17 00:00:00 2001 From: xedre Date: Fri, 5 Oct 2018 22:22:20 +0100 Subject: added docstring to repository --- bot/cogs/template.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bot/cogs/template.py b/bot/cogs/template.py index 89f12fe1..b3f4da21 100644 --- a/bot/cogs/template.py +++ b/bot/cogs/template.py @@ -12,6 +12,9 @@ class Template: @commands.command(name='repo', aliases=['repository', 'project'], brief='A link to the repository of this bot.') async def repository(self, ctx): + """ + A command to send the hacktoberbot github project + """ await ctx.send('https://github.com/discord-python/hacktoberbot') @commands.group(name='git', invoke_without_command=True) -- cgit v1.2.3 From a90769721f6e83153a4bbea4ab0bb15a81183bb1 Mon Sep 17 00:00:00 2001 From: xedre Date: Fri, 5 Oct 2018 22:27:19 +0100 Subject: added commands and motivation sections to README also added docstring to templete.py for repository command --- README.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3a1c32ad..10439275 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,22 @@ # hacktoberbot -A community project for Hacktoberfest 2018. A Discord bot primarily designed to help teach Python learners from the PythonDiscord community how to contribute to open source. +A community project for [Hacktoberfest 2018](https://hacktoberfest.digitalocean.com). A Discord bot primarily designed to help teach Python learners from the PythonDiscord community how to contribute to open source. You can find our community by going to https://discord.gg/python + +## Motivations +We know it can be difficult to get into the whole open source thing at first. To help out, we've decided to start a little community project during hacktober that you can all choose to contribute to if you're finding the event a little overwhelming, or if you're new to this whole thing and just want someone to hold your hand at first. + +by *Lemon* + +## Commands + +### repository +Alias: project +A command to send the hacktoberbot github project + +### git +Alias: github +A command that sends a getting started with Git page + +### git.commit +Sends a sample first commit -- cgit v1.2.3 From 80cf99c4cbaa701155f88f4c63da189156b40ee1 Mon Sep 17 00:00:00 2001 From: xedre Date: Fri, 5 Oct 2018 22:28:11 +0100 Subject: change "by *lemon*" to just "*lemon*" --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 10439275..2a4d0201 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ You can find our community by going to https://discord.gg/python ## Motivations We know it can be difficult to get into the whole open source thing at first. To help out, we've decided to start a little community project during hacktober that you can all choose to contribute to if you're finding the event a little overwhelming, or if you're new to this whole thing and just want someone to hold your hand at first. -by *Lemon* +*Lemon* ## Commands -- cgit v1.2.3 From c4931deed4418aabc4525a0c09cb91a9721af094 Mon Sep 17 00:00:00 2001 From: xedre Date: Fri, 5 Oct 2018 23:53:32 +0100 Subject: Began working on getting started --- README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/README.md b/README.md index 2a4d0201..c4ac693b 100644 --- a/README.md +++ b/README.md @@ -20,3 +20,45 @@ A command that sends a getting started with Git page ### git.commit Sends a sample first commit + +## Getting started + +If you are new to this you will find it far easier using PyCharm: + +### With PyCharm + +First things first, what is PyCharm? +PyCharm is a Python IDE(integrated development environment) that is used to make python development quicker and easier overall. +So now your going to need to download it [here](https://www.jetbrains.com/pycharm/). + +#### 1. Fork +Ok, now you have got PyCharm downloading you are going to want to fork this project and find its git URL. To fork scroll to the top of the page and press this button. +![](https://i.imgur.com/Saf9pgJ.png) +then when you new forked repository loads you are going to want to get the Git Url by clicking the green clone or download button and then the copy link button as seen below: +![](https://i.imgur.com/o6kuQcZ.png) +#### 2. Clone +Now that you have done that you are going to want to load up Pycharm and you'll get something like this without the left sidebar: +![](https://i.imgur.com/xiGERvR.png) +You going to want to click Check Out from Version Control->Git and you'll get a popup like the one below: +![](https://i.imgur.com/d4U6Iw7.png) +Now paste your link in, test the connection and hit clone. You now have a copy of your repository to work with and it should setup your Pipenv automatically. +#### 3. Bot +Now we have setup our repository we need somewhere to test out bot. +You'll need to make a new discord server: +![](https://i.imgur.com/49gBlQI.png) +We need to make the applicaiton for our bot... navigate over to [discordapp.com/developers](https://discordapp.com/developers) and hit new application +![](https://i.imgur.com/UIeGPju.png) +Now we have our discord application you'll want to name your bot as below: +![](https://i.imgur.com/odTWSMV.png) +To actually make the bot hit Bot->Add Bot->Yes, do It! as below: +![](https://i.imgur.com/frAUbTZ.png) +Copy that Token and put to somewhere for safe keeping. +![](https://i.imgur.com/oEpIqND.png) +Now to add that robot to out new discord server we need to generate an OAuth2 Url to do so navigate to the OAuth2 tab, Scrollto the OAUTH2 URL GENERATOR section, click the Bot checkbox in the scope section and finally hit the administrator checkboxin the newly formed Bot Permissions section. +![](https://i.imgur.com/I2XzYPj.png) +Copy and paste the link into your browser and follow the instructions to add the bot to your server - ensure it is the server you have just created. +#### 4. Run Configurations +Go back to PyCharm and you should have something a bit like below, Your going to want to hit the Add Configuration button in the top right. +![](https://i.imgur.com/nLpDfQO.png) +We are going to want to choose a python config as below: +![](https://i.imgur.com/9FgCuP1.png) -- cgit v1.2.3 From 580ba3065f208982a187d22787ad0727f013f941 Mon Sep 17 00:00:00 2001 From: xedre Date: Sat, 6 Oct 2018 09:00:32 +0100 Subject: Finished getting started --- README.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/README.md b/README.md index c4ac693b..8029cef2 100644 --- a/README.md +++ b/README.md @@ -62,3 +62,44 @@ Go back to PyCharm and you should have something a bit like below, Your going to ![](https://i.imgur.com/nLpDfQO.png) We are going to want to choose a python config as below: ![](https://i.imgur.com/9FgCuP1.png) +The first setting we need to change is script path as below (the start script may have changed from bot.py so be sure to click the right one +![](https://i.imgur.com/napKLar.png) +Now we need to add an enviroment variable - what this will do is allow us to set a value without it affact the main repository. +To do this click the folder icon to the right of the text, then on the new window the plus icon. Now name the var `HACKTOBERBOT_TOKEN` and give the value the token we kept for safe keeping earilier. +![](https://i.imgur.com/nZFWNaQ.png) +Now hit apply on that window and your ready to get going! +#### 5. Git in PyCharm +As we work on our project we are going to want to make commits. Commits are effectively a list of changes you made to the pervious version. To make one first hit the green tick in the top right +![](https://i.imgur.com/BCiisvN.png) +1. Select the files you wish to commit +2. Write a brief description of what your commit is +3. See the actual changes you commit does here (you can also turn some of them off or on if you wish) +4. Hit commit + +![](https://i.imgur.com/xA5ga4C.png) +Now once you have made a few commits and are happy with your changes you are going to want to push them back to your fork. +There are three ways of doing this. +1. using the VSC Menu `VSC->Git->Push +2. using the VSC popup alt-\`->Push +3. or a shortcut: `ctrl+shift+K` + +You should get a menu like below: +1. list of commits +2. List of changed files +3. Hit Push to send to fork! + +![](https://i.imgur.com/xA5ga4C.png) +#### 6. Pull Requests (PR or PRs) +Goto https://github.com/discord-python/hacktoberbot/pulls and the green New Pull Request button! +![](https://i.imgur.com/fB4a2wQ.png) +Now you should hit `Compare across forks` then on the third dropdown select your fork (it will be `your username/hacktoberbot`) then hit Create Pull request. +1[](https://i.imgur.com/N2X9A9v.png) +Now to tell other people what your PR does +1. Title - be concise and informative +2. Description - write what the PR changes as well as what issues it relates to +3. Hit `Create pull request` + +#### 7. Wait & further reading +At this point your PR will either be accepted or a maintainer might request some changes. + +So you can read up some more on (Git)[https://try.github.io], (PyCharm)[https://www.jetbrains.com/help/pycharm/quick-start-guide.html] or you might want to learn more about Python and discord: (discord.py rewrite)[https://discordpy.readthedocs.io/en/rewrite/] -- cgit v1.2.3 From 42b71f5f7df83acb1e99c60ea6854ff48ed6d8bf Mon Sep 17 00:00:00 2001 From: xedre Date: Sat, 6 Oct 2018 09:02:14 +0100 Subject: added final image and fixed links --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8029cef2..c3442e88 100644 --- a/README.md +++ b/README.md @@ -98,8 +98,9 @@ Now to tell other people what your PR does 1. Title - be concise and informative 2. Description - write what the PR changes as well as what issues it relates to 3. Hit `Create pull request` +![](https://i.imgur.com/OjKYdsL.png) #### 7. Wait & further reading At this point your PR will either be accepted or a maintainer might request some changes. -So you can read up some more on (Git)[https://try.github.io], (PyCharm)[https://www.jetbrains.com/help/pycharm/quick-start-guide.html] or you might want to learn more about Python and discord: (discord.py rewrite)[https://discordpy.readthedocs.io/en/rewrite/] +So you can read up some more on [https://try.github.io](Git), [https://www.jetbrains.com/help/pycharm/quick-start-guide.html](PyCharm) or you might want to learn more about Python and discord: [https://discordpy.readthedocs.io/en/rewrite/](discord.py rewrite) -- cgit v1.2.3 From b17e3d7345d4bb7a8158c0ba1d84228a5bb42611 Mon Sep 17 00:00:00 2001 From: xedre Date: Sat, 6 Oct 2018 09:04:22 +0100 Subject: added log/* to .gitignore --- .gitignore | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index a8072aaf..8f8974f9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ +# bot (project-specific) +log/* + + + + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] -- cgit v1.2.3 From dec834d055e3694452af8289a05abcf1b57e9a35 Mon Sep 17 00:00:00 2001 From: Ryan Gables Date: Sat, 6 Oct 2018 02:33:19 -0700 Subject: Roughed out omdb requests --- bot/cogs/rand_movie.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 bot/cogs/rand_movie.py diff --git a/bot/cogs/rand_movie.py b/bot/cogs/rand_movie.py new file mode 100644 index 00000000..d531b32b --- /dev/null +++ b/bot/cogs/rand_movie.py @@ -0,0 +1,66 @@ +import requests +import random +from pprint import pprint +from discord.ext import commands + +class Movies: + + """ + TODO. + """ + + def __init__(self, bot): + self.bot = bot + + @commands.command(name='movie', aliases=['rand_movie', 'movie'], brief='Pick a scary movie') + async def repository(self, ctx): + await ctx.send('https://github.com/discord-python/hacktoberbot') + + @staticmethod + def select_movie(api_key): + params = { + 'apikey': api_key, + 'type': 'movie', + 's': 'halloween' + } + + response = requests.get('http://www.omdbapi.com/', params) + + movies = [] + + for movie in response.json().get('Search'): + movie_id = movie.get('imdbID') + movies.append(movie_id) + + selection = random.choice(movies) + + params = { + 'apikey': api_key, + 'i': selection + } + + response = requests.get('http://www.omdbapi.com/', params) + + return response.json() + + + # @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)) -- cgit v1.2.3 From 0021275df95c3e26c8351b2e25a1520dcf59516a Mon Sep 17 00:00:00 2001 From: xedre Date: Sat, 6 Oct 2018 16:49:06 +0100 Subject: Update README.md --- README.md | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index c3442e88..d04fa85e 100644 --- a/README.md +++ b/README.md @@ -6,20 +6,13 @@ You can find our community by going to https://discord.gg/python ## Motivations We know it can be difficult to get into the whole open source thing at first. To help out, we've decided to start a little community project during hacktober that you can all choose to contribute to if you're finding the event a little overwhelming, or if you're new to this whole thing and just want someone to hold your hand at first. -*Lemon* - ## Commands -### repository -Alias: project -A command to send the hacktoberbot github project - -### git -Alias: github -A command that sends a getting started with Git page +!repository - Links to this repository -### git.commit -Sends a sample first commit +### Git +!Git - Links to getting started with Git page +!Git.commit - An example commit command ## Getting started @@ -34,7 +27,7 @@ So now your going to need to download it [here](https://www.jetbrains.com/pychar #### 1. Fork Ok, now you have got PyCharm downloading you are going to want to fork this project and find its git URL. To fork scroll to the top of the page and press this button. ![](https://i.imgur.com/Saf9pgJ.png) -then when you new forked repository loads you are going to want to get the Git Url by clicking the green clone or download button and then the copy link button as seen below: +Then when you new forked repository loads you are going to want to get the Git Url by clicking the green clone or download button and then the copy link button as seen below: ![](https://i.imgur.com/o6kuQcZ.png) #### 2. Clone Now that you have done that you are going to want to load up Pycharm and you'll get something like this without the left sidebar: @@ -79,12 +72,12 @@ As we work on our project we are going to want to make commits. Commits are effe ![](https://i.imgur.com/xA5ga4C.png) Now once you have made a few commits and are happy with your changes you are going to want to push them back to your fork. There are three ways of doing this. -1. using the VSC Menu `VSC->Git->Push -2. using the VSC popup alt-\`->Push -3. or a shortcut: `ctrl+shift+K` +1. Using the VSC Menu `VSC->Git->Push +2. Using the VSC popup alt-\`->Push +3. A shortcut: `ctrl+shift+K` You should get a menu like below: -1. list of commits +1. List of commits 2. List of changed files 3. Hit Push to send to fork! -- cgit v1.2.3 From 7ed17906148cb1e258e090b97dbd17f1557ad900 Mon Sep 17 00:00:00 2001 From: xedre Date: Sat, 6 Oct 2018 18:43:47 +0100 Subject: added links for how to achieve Setup without Pycharm --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index d04fa85e..46f322ff 100644 --- a/README.md +++ b/README.md @@ -97,3 +97,12 @@ Now to tell other people what your PR does At this point your PR will either be accepted or a maintainer might request some changes. So you can read up some more on [https://try.github.io](Git), [https://www.jetbrains.com/help/pycharm/quick-start-guide.html](PyCharm) or you might want to learn more about Python and discord: [https://discordpy.readthedocs.io/en/rewrite/](discord.py rewrite) + + +### Without PyCharm +The process above can be completed without PyCharm however it will be necessary to learn how to use Git, Pipenv and Environment variables. + +You can find tutorials for the above below: +- Git: [try.github](http://try.github.io/) +- Pipenv [Pipenv.readthedocs](https://pipenv.readthedocs.io) +- Environment Variables: [youtube](https://youtu.be/bEroNNzqlF4?t=27) -- cgit v1.2.3 From 45027a060962841bc53f38184f68a4c4b907f676 Mon Sep 17 00:00:00 2001 From: ninexball Date: Sat, 6 Oct 2018 14:39:18 -0500 Subject: Added logging --- bot/__init__.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 bot/__init__.py diff --git a/bot/__init__.py b/bot/__init__.py new file mode 100644 index 00000000..8cbcd121 --- /dev/null +++ b/bot/__init__.py @@ -0,0 +1,30 @@ +import os +import logging.handlers + +# set up logging + +log_dir = 'log' +log_file = log_dir + os.sep + 'hackbot.log' +os.makedirs(log_dir, exist_ok=True) + +# file handler sets up rotating logs every 5 MB +file_handler = logging.handlers.RotatingFileHandler( + log_file, maxBytes=5*(2**20), backupCount=10) +file_handler.setLevel(logging.DEBUG) + +# console handler prints to terminal +console_handler = logging.StreamHandler() +console_handler.setLevel(logging.INFO) + +# remove old loggers if any +root = logging.getLogger() +if root.handlers: + for handler in root.handlers: + root.removeHandler(handler) + +# setup new logging configuration +logging.basicConfig(format='%(asctime)s - %(name)s %(levelname)s: %(message)s', datefmt="%D %H:%M:%S", + level=logging.DEBUG, + handlers=[console_handler, file_handler]) + +logging.info('Logging Process Started') \ No newline at end of file -- cgit v1.2.3 From 9af16d77de893245a98ddb7c91825dd54bd6b106 Mon Sep 17 00:00:00 2001 From: Ryan Gables Date: Sat, 6 Oct 2018 18:21:12 -0700 Subject: made apikey env var + formatted omdb response --- bot/cogs/movie.py | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ bot/cogs/rand_movie.py | 66 -------------------------------------------------- 2 files changed, 65 insertions(+), 66 deletions(-) create mode 100644 bot/cogs/movie.py delete mode 100644 bot/cogs/rand_movie.py diff --git a/bot/cogs/movie.py b/bot/cogs/movie.py new file mode 100644 index 00000000..45714005 --- /dev/null +++ b/bot/cogs/movie.py @@ -0,0 +1,65 @@ +import requests +import random +from discord.ext import commands +from os import environ + +OMDB_API_KEY = environ.get('OMDB_API_KEY') + + +class Movie: + """ + Prints the details of a random scary movie to discord chat + """ + + def __init__(self, bot): + self.bot = bot + + @commands.command(name='movie', aliases=['scary_movie'], brief='Pick me a scary movie') + async def random_movie(self, ctx): + selection = await self.select_movie() + movie_details = await self.format_metadata(selection) + + await ctx.send(movie_details) + + @staticmethod + async def select_movie(): + """ + Selects a random movie and returns a json of movie details from omdb + """ + + # TODO: Come up w/ a scary movie list to select from. Currently returns random Halloween movie + omdb_params = { + 'apikey': OMDB_API_KEY, + 'type': 'movie', + 's': 'halloween' + } + response = requests.get('http://www.omdbapi.com/', omdb_params) + + movies = [] + for movie in response.json().get('Search'): + movie_id = movie.get('imdbID') + movies.append(movie_id) + + selection = random.choice(movies) + + omdb_params = { + 'apikey': OMDB_API_KEY, + 'i': selection + } + response = requests.get('http://www.omdbapi.com/', omdb_params) + + return response.json() + + @staticmethod + async def format_metadata(movie): + """ + Formats raw omdb data to be displayed in discord chat + """ + display_text = f"You should watch {movie.get('Title')} ({movie.get('Year')})\n" \ + f"https://www.imdb.com/title/{movie.get('imdbID')}" + + return display_text + + +def setup(bot): + bot.add_cog(Movie(bot)) diff --git a/bot/cogs/rand_movie.py b/bot/cogs/rand_movie.py deleted file mode 100644 index d531b32b..00000000 --- a/bot/cogs/rand_movie.py +++ /dev/null @@ -1,66 +0,0 @@ -import requests -import random -from pprint import pprint -from discord.ext import commands - -class Movies: - - """ - TODO. - """ - - def __init__(self, bot): - self.bot = bot - - @commands.command(name='movie', aliases=['rand_movie', 'movie'], brief='Pick a scary movie') - async def repository(self, ctx): - await ctx.send('https://github.com/discord-python/hacktoberbot') - - @staticmethod - def select_movie(api_key): - params = { - 'apikey': api_key, - 'type': 'movie', - 's': 'halloween' - } - - response = requests.get('http://www.omdbapi.com/', params) - - movies = [] - - for movie in response.json().get('Search'): - movie_id = movie.get('imdbID') - movies.append(movie_id) - - selection = random.choice(movies) - - params = { - 'apikey': api_key, - 'i': selection - } - - response = requests.get('http://www.omdbapi.com/', params) - - return response.json() - - - # @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)) -- cgit v1.2.3 From e1fd21b6a43966a5e82f9d7a5adccac0c2e03eac Mon Sep 17 00:00:00 2001 From: xedre Date: Mon, 8 Oct 2018 11:38:18 +0100 Subject: added graves consistently --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 46f322ff..27671cd4 100644 --- a/README.md +++ b/README.md @@ -27,14 +27,14 @@ So now your going to need to download it [here](https://www.jetbrains.com/pychar #### 1. Fork Ok, now you have got PyCharm downloading you are going to want to fork this project and find its git URL. To fork scroll to the top of the page and press this button. ![](https://i.imgur.com/Saf9pgJ.png) -Then when you new forked repository loads you are going to want to get the Git Url by clicking the green clone or download button and then the copy link button as seen below: +Then when you new forked repository loads you are going to want to get the Git Url by clicking the green `clone or download` button and then the copy link button as seen below: ![](https://i.imgur.com/o6kuQcZ.png) #### 2. Clone Now that you have done that you are going to want to load up Pycharm and you'll get something like this without the left sidebar: ![](https://i.imgur.com/xiGERvR.png) -You going to want to click Check Out from Version Control->Git and you'll get a popup like the one below: +You going to want to click Check Out from Version `Control->Git` and you'll get a popup like the one below: ![](https://i.imgur.com/d4U6Iw7.png) -Now paste your link in, test the connection and hit clone. You now have a copy of your repository to work with and it should setup your Pipenv automatically. +Now paste your link in, test the connection and hit `clone`. You now have a copy of your repository to work with and it should setup your Pipenv automatically. #### 3. Bot Now we have setup our repository we need somewhere to test out bot. You'll need to make a new discord server: @@ -43,15 +43,15 @@ We need to make the applicaiton for our bot... navigate over to [discordapp.com/ ![](https://i.imgur.com/UIeGPju.png) Now we have our discord application you'll want to name your bot as below: ![](https://i.imgur.com/odTWSMV.png) -To actually make the bot hit Bot->Add Bot->Yes, do It! as below: +To actually make the bot hit `Bot->Add Bot->Yes, do It!` as below: ![](https://i.imgur.com/frAUbTZ.png) Copy that Token and put to somewhere for safe keeping. ![](https://i.imgur.com/oEpIqND.png) -Now to add that robot to out new discord server we need to generate an OAuth2 Url to do so navigate to the OAuth2 tab, Scrollto the OAUTH2 URL GENERATOR section, click the Bot checkbox in the scope section and finally hit the administrator checkboxin the newly formed Bot Permissions section. +Now to add that robot to out new discord server we need to generate an OAuth2 Url to do so navigate to the OAuth2 tab, Scroll to the OAUTH2 URL GENERATOR section, click the `Bot` checkbox in the scope section and finally hit the `administrator` checkbox in the newly formed Bot Permissions section. ![](https://i.imgur.com/I2XzYPj.png) Copy and paste the link into your browser and follow the instructions to add the bot to your server - ensure it is the server you have just created. #### 4. Run Configurations -Go back to PyCharm and you should have something a bit like below, Your going to want to hit the Add Configuration button in the top right. +Go back to PyCharm and you should have something a bit like below, Your going to want to hit the `Add Configuration` button in the top right. ![](https://i.imgur.com/nLpDfQO.png) We are going to want to choose a python config as below: ![](https://i.imgur.com/9FgCuP1.png) @@ -72,7 +72,7 @@ As we work on our project we are going to want to make commits. Commits are effe ![](https://i.imgur.com/xA5ga4C.png) Now once you have made a few commits and are happy with your changes you are going to want to push them back to your fork. There are three ways of doing this. -1. Using the VSC Menu `VSC->Git->Push +1. Using the VSC Menu `VSC->Git->Push` 2. Using the VSC popup alt-\`->Push 3. A shortcut: `ctrl+shift+K` -- cgit v1.2.3 From 4fd7f6dd7523ac165073e2359c21f7b12159baf7 Mon Sep 17 00:00:00 2001 From: ninexball Date: Mon, 8 Oct 2018 20:51:57 -0500 Subject: Added basic logging to bot.py --- bot/bot.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/bot/bot.py b/bot/bot.py index a67fcdab..5c3d3c71 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -1,13 +1,23 @@ +from os import environ from pathlib import Path from sys import stderr -from traceback import print_exc -from os import environ +from traceback import print_exc, format_exc from discord.ext import commands - +import logging HACKTOBERBOT_TOKEN = environ.get('HACKTOBERBOT_TOKEN') -bot = commands.Bot(command_prefix=commands.when_mentioned_or('!')) + +if HACKTOBERBOT_TOKEN: + token_dl = len(HACKTOBERBOT_TOKEN) // 8 + logging.info(f'Bot token loaded: {HACKTOBERBOT_TOKEN[:token_dl]}...{HACKTOBERBOT_TOKEN[-token_dl:]}') +else: + logging.error(f'Bot token not found: {HACKTOBERBOT_TOKEN}') + +ghost_unicode = "\N{GHOST}" +bot = commands.Bot(command_prefix=commands.when_mentioned_or(".", f"{ghost_unicode} ", ghost_unicode)) + +logging.info('Start loading extensions from ./cogs/') if __name__ == '__main__': # Scan for files in the /cogs/ directory and make a list of the file names. @@ -15,8 +25,14 @@ if __name__ == '__main__': for extension in cogs: try: bot.load_extension(f'cogs.{extension}') + logging.info(f'Successfully loaded extension: {extension}') except Exception as e: - print(f'Failed to load extension {extension}.', file=stderr) - print_exc() + logging.error(f'Failed to load extension {extension}: {repr(e)} {format_exc()}') + # print(f'Failed to load extension {extension}.', file=stderr) + # print_exc() + +logging.info(f'Spooky Launch Sequence Initiated...') bot.run(HACKTOBERBOT_TOKEN) + +logging.info(f'HackBot has been slain!') \ No newline at end of file -- cgit v1.2.3 From eee33d3d294686a99e6410ad9d43ff155ee763dd Mon Sep 17 00:00:00 2001 From: Ryan Gables Date: Tue, 9 Oct 2018 01:16:38 -0700 Subject: Embeds movie data from TMDb --- bot/cogs/movie.py | 88 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 27 deletions(-) diff --git a/bot/cogs/movie.py b/bot/cogs/movie.py index 45714005..65c96075 100644 --- a/bot/cogs/movie.py +++ b/bot/cogs/movie.py @@ -1,64 +1,98 @@ import requests import random -from discord.ext import commands from os import environ +from discord.ext import commands +from discord import Embed -OMDB_API_KEY = environ.get('OMDB_API_KEY') +TMDB_API_KEY = environ.get('TMDB_API_KEY') +TMDB_TOKEN = environ.get('TMDB_TOKEN') class Movie: """ - Prints the details of a random scary movie to discord chat + Selects a random scary movie and embeds info into discord chat """ def __init__(self, bot): self.bot = bot - @commands.command(name='movie', aliases=['scary_movie'], brief='Pick me a scary movie') + @commands.command(name='movie', alias=['tmdb'], brief='Pick a scary movie') async def random_movie(self, ctx): selection = await self.select_movie() movie_details = await self.format_metadata(selection) - await ctx.send(movie_details) + await ctx.send(embed=movie_details) @staticmethod async def select_movie(): """ - Selects a random movie and returns a json of movie details from omdb + Selects a random movie and returns a json of movie details from TMDb """ - # TODO: Come up w/ a scary movie list to select from. Currently returns random Halloween movie - omdb_params = { - 'apikey': OMDB_API_KEY, - 'type': 'movie', - 's': 'halloween' + url = 'https://api.themoviedb.org/4/discover/movie' + params = { + 'with_genres': '27', + 'vote_count.gte': '5' + } + headers = { + 'Authorization': 'Bearer ' + TMDB_TOKEN, + 'Content-Type': 'application/json;charset=utf-8' } - response = requests.get('http://www.omdbapi.com/', omdb_params) - movies = [] - for movie in response.json().get('Search'): - movie_id = movie.get('imdbID') - movies.append(movie_id) + # Get total page count of horror movies + response = requests.get(url=url, params=params, headers=headers) + total_pages = response.json().get('total_pages') - selection = random.choice(movies) + # Get movie details from one random result on a random page + params['page'] = random.randint(1, total_pages) + response = requests.get(url=url, params=params, headers=headers) + selection_id = random.choice(response.json().get('results')).get('id') - omdb_params = { - 'apikey': OMDB_API_KEY, - 'i': selection - } - response = requests.get('http://www.omdbapi.com/', omdb_params) + # Get full details and credits + selection = requests.get(url='https://api.themoviedb.org/3/movie/' + str(selection_id), + params={'api_key': TMDB_API_KEY, 'append_to_response': 'credits'}) - return response.json() + return selection.json() @staticmethod async def format_metadata(movie): """ - Formats raw omdb data to be displayed in discord chat + Formats raw TMDb data to be embedded in discord chat """ - display_text = f"You should watch {movie.get('Title')} ({movie.get('Year')})\n" \ - f"https://www.imdb.com/title/{movie.get('imdbID')}" - return display_text + tmdb_url = 'https://www.themoviedb.org/movie/' + str(movie.get('id')) + poster = 'https://image.tmdb.org/t/p/original' + movie.get('poster_path') + + cast = [] + for actor in movie.get('credits').get('cast')[:3]: + cast.append(actor.get('name')) + + director = movie.get('credits').get('crew')[0].get('name') + + rating_count = movie.get('vote_average') / 2 + rating = '' + + for i in range(int(rating_count)): + rating += ':skull:' + + if (rating_count % 1) >= .5: + rating += ':bat:' + + embed = Embed( + colour=0x01d277, + title='**' + movie.get('title') + '**', + url=tmdb_url, + description=movie.get('overview') + ) + embed.set_image(url=poster) + embed.add_field(name='Staring', value=', '.join(cast)) + embed.add_field(name='Directed by', value=director) + embed.add_field(name='Year', value=movie.get('release_date')[:4]) + embed.add_field(name='Runtime', value=str(movie.get('runtime')) + 'm') + embed.add_field(name='Spooky Rating', value=rating) + embed.set_footer(text='powered by themoviedb.org') + + return embed def setup(bot): -- cgit v1.2.3 From 9f4065bcc720857564498d526c88bcc0a8c51881 Mon Sep 17 00:00:00 2001 From: Ryan Gables Date: Tue, 9 Oct 2018 01:40:39 -0700 Subject: spelling --- bot/cogs/movie.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/cogs/movie.py b/bot/cogs/movie.py index 65c96075..bb6f8df8 100644 --- a/bot/cogs/movie.py +++ b/bot/cogs/movie.py @@ -85,10 +85,10 @@ class Movie: description=movie.get('overview') ) embed.set_image(url=poster) - embed.add_field(name='Staring', value=', '.join(cast)) + embed.add_field(name='Starring', value=', '.join(cast)) embed.add_field(name='Directed by', value=director) embed.add_field(name='Year', value=movie.get('release_date')[:4]) - embed.add_field(name='Runtime', value=str(movie.get('runtime')) + 'm') + embed.add_field(name='Runtime', value=str(movie.get('runtime')) + ' min') embed.add_field(name='Spooky Rating', value=rating) embed.set_footer(text='powered by themoviedb.org') -- cgit v1.2.3 From f12940261d7afd7254c703d30272fdc688cb8ef7 Mon Sep 17 00:00:00 2001 From: Marko Kovačević Date: Tue, 9 Oct 2018 11:42:09 +0200 Subject: Implement Halloweenify feature. --- bot/cogs/halloweenify.py | 46 ++++++++++++++++++++++++ bot/resources/halloweenify.json | 79 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 bot/cogs/halloweenify.py create mode 100644 bot/resources/halloweenify.json diff --git a/bot/cogs/halloweenify.py b/bot/cogs/halloweenify.py new file mode 100644 index 00000000..0422e787 --- /dev/null +++ b/bot/cogs/halloweenify.py @@ -0,0 +1,46 @@ +from pathlib import Path +from json import load +from random import choice + + +import discord +from discord.ext import commands +from discord.ext.commands.cooldowns import BucketType + + +class Halloweenify: + + """ + A cog to change a invokers nickname to a spooky one! + """ + + def __init__(self, bot): + self.bot = bot + + @commands.cooldown(1, 300, BucketType.user) + @commands.command() + async def halloweenify(self, ctx): + with open(Path('../bot/resources', 'halloweenify.json'), 'r') as f: + data = load(f) + + # Choose a random character from our list we loaded above and set apart the nickname and image url. + character = choice(data['characters']) + nickname = ''.join([nickname for nickname in character]) + image = ''.join([character[nickname] for nickname in character]) + + # Build up a Embed + embed = discord.Embed() + embed.colour = discord.Colour.dark_orange() + embed.title = 'Wow!' + embed.description = ( + f'Your previous nickname, **{ctx.author.display_name}**, wasn\'t spooky enough for you that you have ' + f'decided to change it?! Okay, your new nickname will be **{nickname}**.\n\n' + ) + embed.set_image(url=image) + + await ctx.author.edit(nick=nickname) + await ctx.send(embed=embed) + + +def setup(bot): + bot.add_cog(Halloweenify(bot)) diff --git a/bot/resources/halloweenify.json b/bot/resources/halloweenify.json new file mode 100644 index 00000000..458f9342 --- /dev/null +++ b/bot/resources/halloweenify.json @@ -0,0 +1,79 @@ +{ + "characters": [ + { + "Michael Myers": "https://c-5uwzmx78pmca09x24quoqfx2ezivsmzx2ekwu.g00.ranker.com/g00/3_c-5eee.zivsmz.kwu_/c-5UWZMXPMCA09x24pbbx78ax3ax2fx2fquoqf.zivsmz.kwux2fcamz_vwlm_quox2f57x2f9353301x2fwzqoqvitx2fuqkpimt-ugmza-x78pwbw-c95x3fex3d438x26yx3d38x26nux3drx78ox26nqbx3dkzwx78x26kzwx78x3dnikmax26q98k.uizsx3dquiom_$/$/$/$/$/$" + }, + { + "Jason Voorhees": "https://c-5uwzmx78pmca09x24quoqfx2ezivsmzx2ekwu.g00.ranker.com/g00/3_c-5eee.zivsmz.kwu_/c-5UWZMXPMCA09x24pbbx78ax3ax2fx2fquoqf.zivsmz.kwux2fcamz_vwlm_quox2f42x2f9050161x2fwzqoqvitx2friawv-dwwzpmma-nqtu-kpizikbmza-x78pwbw-c1x3fex3d438x26yx3d38x26nux3drx78ox26nqbx3dkzwx78x26kzwx78x3dnikmax26q98k.uizsx3dquiom_$/$/$/$/$/$" + }, + { + "Freddy Krueger": "https://c-5uwzmx78pmca09x24quoqfx2ezivsmzx2ekwu.g00.ranker.com/g00/3_c-5eee.zivsmz.kwu_/c-5UWZMXPMCA09x24pbbx78ax3ax2fx2fquoqf.zivsmz.kwux2fvwlm_quox2f30x2f9800154x2fwzqoqvitx2fnzmllg-szcmomz-nqtu-kpizikbmza-x78pwbw-9x3fex3d438x26yx3d38x26nux3drx78ox26nqbx3dkzwx78x26kzwx78x3dnikmax26q98k.uizsx3dquiom_$/$/$/$/$/$" + }, + { + "Pennywise the Dancing Clown": "https://c-5uwzmx78pmca09x24quoqfx2ezivsmzx2ekwu.g00.ranker.com/g00/3_c-5eee.zivsmz.kwu_/c-5UWZMXPMCA09x24pbbx78ax3ax2fx2fquoqf.zivsmz.kwux2fcamz_vwlm_quox2f436x2f91927608x2fwzqoqvitx2fx78mvvgeqam-bpm-livkqvo-ktwev-nqtu-kpizikbmza-x78pwbw-c0x3fex3d438x26yx3d38x26nux3drx78ox26nqbx3dkzwx78x26kzwx78x3dnikmax26q98k.uizsx3dquiom_$/$/$/$/$/$" + }, + { + "Charles Lee Ray": "https://c-5uwzmx78pmca09x24quoqfx2ezivsmzx2ekwu.g00.ranker.com/g00/3_c-5eee.zivsmz.kwu_/c-5UWZMXPMCA09x24pbbx78ax3ax2fx2fquoqf.zivsmz.kwux2fcamz_vwlm_quox2f14x2f581261x2fwzqoqvitx2fkpiztma-tmm-zig-c90x3fex3d438x26yx3d48x26nux3drx78ox26nqbx3dkzwx78x26kzwx78x3dnikmax22x26q98k.uizsx3dquiom_$/$/$/$/$/$" + }, + { + "Leatherface": "https://c-5uwzmx78pmca09x24quoqfx2ezivsmzx2ekwu.g00.ranker.com/g00/3_c-5eee.zivsmz.kwu_/c-5UWZMXPMCA09x24pbbx78ax3ax2fx2fquoqf.zivsmz.kwux2fcamz_vwlm_quox2f50x2f9204163x2fwzqoqvitx2ftmibpmznikm-c08x3fex3d438x26yx3d48x26nux3drx78ox26nqbx3dkzwx78x26kzwx78x3dnikmax22x26q98k.uizsx3dquiom_$/$/$/$/$/$" + }, + { + "Jack Torrance": "https://c-5uwzmx78pmca09x24quoqfx2ezivsmzx2ekwu.g00.ranker.com/g00/3_c-5eee.zivsmz.kwu_/c-5UWZMXPMCA09x24pbbx78ax3ax2fx2fquoqf.zivsmz.kwux2fvwlm_quox2f41x2f9032825x2fwzqoqvitx2friks-bwzzivkm-nqtu-kpizikbmza-x78pwbw-9x3fex3d438x26yx3d48x26nux3drx78ox26nqbx3dkzwx78x26kzwx78x3dnikmax22x26q98k.uizsx3dquiom_$/$/$/$/$/$" + }, + { + "Ghostface": "https://c-5uwzmx78pmca09x24quoqfx2ezivsmzx2ekwu.g00.ranker.com/g00/3_c-5eee.zivsmz.kwu_/c-5UWZMXPMCA09x24pbbx78ax3ax2fx2fquoqf.zivsmz.kwux2fcamz_vwlm_quox2f32x2f9845748x2fwzqoqvitx2fopwabnikm-nqtu-kpizikbmza-x78pwbw-c9x3fex3d438x26yx3d48x26nux3drx78ox26nqbx3dkzwx78x26kzwx78x3dnikmax22x26q98k.uizsx3dquiom_$/$/$/$/$/$" + }, + { + "Regan MacNeil": "https://c-5uwzmx78pmca09x24quoqfx2ezivsmzx2ekwu.g00.ranker.com/g00/3_c-5eee.zivsmz.kwu_/c-5UWZMXPMCA09x24pbbx78ax3ax2fx2fquoqf.zivsmz.kwux2fcamz_vwlm_quox2f73x2f9665843x2fwzqoqvitx2fzmoiv-uikvmqt-zmkwzlqvo-izbqaba-ivl-ozwcx78a-x78pwbw-c1x3fex3d438x26yx3d48x26nux3drx78ox26nqbx3dkzwx78x26kzwx78x3dnikmax22x26q98k.uizsx3dquiom_$/$/$/$/$/$" + }, + { + "Hannibal Lecter": "https://c-5uwzmx78pmca09x24quoqfx2ezivsmzx2ekwu.g00.ranker.com/g00/3_c-5eee.zivsmz.kwu_/c-5UWZMXPMCA09x24pbbx78ax3ax2fx2fquoqf.zivsmz.kwux2fcamz_vwlm_quox2f35x2f9903368x2fwzqoqvitx2fpivvqjit-tmkbmz-nqtu-kpizikbmza-x78pwbw-c99x3fex3d438x26yx3d48x26nux3drx78ox26nqbx3dkzwx78x26kzwx78x3dnikmax22x26q98k.uizsx3dquiom_$/$/$/$/$/$" + }, + { + "Samara Morgan": "https://c-5uwzmx78pmca09x24quoqfx2ezivsmzx2ekwu.g00.ranker.com/g00/3_c-5eee.zivsmz.kwu_/c-5UWZMXPMCA09x24pbbx78ax3ax2fx2fquoqf.zivsmz.kwux2fcamz_vwlm_quox2f77x2f9744082x2fwzqoqvitx2faiuizi-uwzoiv-nqtu-kpizikbmza-x78pwbw-c9x3fex3d438x26yx3d48x26nux3drx78ox26nqbx3dkzwx78x26kzwx78x3dnikmax22x26q98k.uizsx3dquiom_$/$/$/$/$/$" + }, + { + "Pinhead": "https://c-5uwzmx78pmca09x24quoqfx2ezivsmzx2ekwu.g00.ranker.com/g00/3_c-5eee.zivsmz.kwu_/c-5UWZMXPMCA09x24pbbx78ax3ax2fx2fquoqf.zivsmz.kwux2fcamz_vwlm_quox2f79x2f9683232x2fwzqoqvitx2fx78qvpmil-nqtu-kpizikbmza-x78pwbw-c4x3fex3d438x26yx3d48x26nux3drx78ox26nqbx3dkzwx78x26kzwx78x3dnikmax22x26q98k.uizsx3dquiom_$/$/$/$/$/$" + }, + { + "Bruce": "https://c-5uwzmx78pmca09x24quoqfx2ezivsmzx2ekwu.g00.ranker.com/g00/3_c-5eee.zivsmz.kwu_/c-5UWZMXPMCA09x24pbbx78ax3ax2fx2fquoqf.zivsmz.kwux2fcamz_vwlm_quox2f2047x2f63159728x2fwzqoqvitx2friea-c3x3fex3d438x26yx3d48x26nux3drx78ox26nqbx3dkzwx78x26kzwx78x3dnikmax22x26q98k.uizsx3dquiom_$/$/$/$/$/$" + }, + { + "Xenomorph": "https://c-5uwzmx78pmca09x24quoqfx2ezivsmzx2ekwu.g00.ranker.com/g00/3_c-5eee.zivsmz.kwu_/c-5UWZMXPMCA09x24pbbx78ax3ax2fx2fquoqf.zivsmz.kwux2fcamz_vwlm_quox2f909x2f0297919x2fwzqoqvitx2ffmvwuwzx78p-x78pwbw-c91x3fex3d438x26yx3d48x26nux3drx78ox26nqbx3dkzwx78x26kzwx78x3dnikmax22x26q98k.uizsx3dquiom_$/$/$/$/$/$" + }, + { + "The Thing": "https://c-5uwzmx78pmca09x24quoqfx2ezivsmzx2ekwu.g00.ranker.com/g00/3_c-5eee.zivsmz.kwu_/c-5UWZMXPMCA09x24pbbx78ax3ax2fx2fquoqf.zivsmz.kwux2fcamz_vwlm_quox2f1947x2f41148806x2fwzqoqvitx2fbpm-bpqvo-x78pwbw-c6x3fex3d438x26yx3d48x26nux3drx78ox26nqbx3dkzwx78x26kzwx78x3dnikmax22x26q98k.uizsx3dquiom_$/$/$/$/$/$" + }, + { + "Sadako Yamamura": "https://c-5uwzmx78pmca09x24quoqfx2ezivsmzx2ekwu.g00.ranker.com/g00/3_c-5eee.zivsmz.kwu_/c-5UWZMXPMCA09x24pbbx78ax3ax2fx2fquoqf.zivsmz.kwux2fcamz_vwlm_quox2f76x2f9735755x2fwzqoqvitx2failisw-giuiuczi-c4x3fex3d438x26yx3d48x26nux3drx78ox26nqbx3dkzwx78x26kzwx78x3dnikmax22x26q98k.uizsx3dquiom_$/$/$/$/$/$" + }, + { + "Jigsaw Killer": "https://c-5uwzmx78pmca09x24quoqfx2ezivsmzx2ekwu.g00.ranker.com/g00/3_c-5eee.zivsmz.kwu_/c-5UWZMXPMCA09x24pbbx78ax3ax2fx2fquoqf.zivsmz.kwux2fvwlm_quox2f43x2f9065767x2fwzqoqvitx2frqoaie-sqttmz-nqtu-kpizikbmza-x78pwbw-9x3fex3d438x26yx3d48x26nux3drx78ox26nqbx3dkzwx78x26kzwx78x3dnikmax22x26q98k.uizsx3dquiom_$/$/$/$/$/$" + }, + { + "Norman Bates": "https://c-5uwzmx78pmca09x24quoqfx2ezivsmzx2ekwu.g00.ranker.com/g00/3_c-5eee.zivsmz.kwu_/c-5UWZMXPMCA09x24pbbx78ax3ax2fx2fquoqf.zivsmz.kwux2fcamz_vwlm_quox2f63x2f9467317x2fwzqoqvitx2fvwzuiv-jibma-nqtu-kpizikbmza-x78pwbw-c9x3fex3d438x26yx3d48x26nux3drx78ox26nqbx3dkzwx78x26kzwx78x3dnikmax22x26q98k.uizsx3dquiom_$/$/$/$/$/$" + }, + { + "Candyman": "https://c-5uwzmx78pmca09x24quoqfx2ezivsmzx2ekwu.g00.ranker.com/g00/3_c-5eee.zivsmz.kwu_/c-5UWZMXPMCA09x24pbbx78ax3ax2fx2fquoqf.zivsmz.kwux2fcamz_vwlm_quox2f255x2f7305168x2fwzqoqvitx2fkivlguiv-c5x3fex3d438x26yx3d48x26nux3drx78ox26nqbx3dkzwx78x26kzwx78x3dnikmax22x26q98k.uizsx3dquiom_$/$/$/$/$/$" + }, + { + "The Creeper": "https://c-5uwzmx78pmca09x24quoqfx2ezivsmzx2ekwu.g00.ranker.com/g00/3_c-5eee.zivsmz.kwu_/c-5UWZMXPMCA09x24pbbx78ax3ax2fx2fquoqf.zivsmz.kwux2fvwlm_quox2f998x2f0963452x2fwzqoqvitx2fbpm-kzmmx78mz-nqtu-kpizikbmza-x78pwbw-9x3fex3d438x26yx3d48x26nux3drx78ox26nqbx3dkzwx78x26kzwx78x3dnikmax22x26q98k.uizsx3dquiom_$/$/$/$/$/$" + }, + { + "Damien Thorn": "https://c-5uwzmx78pmca09x24quoqfx2ezivsmzx2ekwu.g00.ranker.com/g00/3_c-5eee.zivsmz.kwu_/c-5UWZMXPMCA09x24pbbx78ax3ax2fx2fquoqf.zivsmz.kwux2fcamz_vwlm_quox2f29x2f685981x2fwzqoqvitx2fliuqmv-bpwzv-x78pwbw-c1x3fex3d438x26yx3d48x26nux3drx78ox26nqbx3dkzwx78x26kzwx78x3dnikmax22x26q98k.uizsx3dquiom_$/$/$/$/$/$" + }, + { + "Joker": "https://c-5uwzmx78pmca09x24quoqfx2ezivsmzx2ekwu.g00.ranker.com/g00/3_c-5eee.zivsmz.kwu_/c-5UWZMXPMCA09x24pbbx78ax3ax2fx2fquoqf.zivsmz.kwux2fcamz_vwlm_quox2f903x2f0276049x2fwzqoqvitx2frwsmz-c71x3fex3d438x26yx3d48x26nux3drx78ox26nqbx3dkzwx78x26kzwx78x3dnikmax22x26q98k.uizsx3dquiom_$/$/$/$/$/$" + }, + { + "Cujo": "https://c-5uwzmx78pmca09x24quoqfx2ezivsmzx2ekwu.g00.ranker.com/g00/3_c-5eee.zivsmz.kwu_/c-5UWZMXPMCA09x24pbbx78ax3ax2fx2fquoqf.zivsmz.kwux2fcamz_vwlm_quox2f1581x2f52837948x2fwzqoqvitx2fkcrw-nqtu-kpizikbmza-x78pwbw-c9x3fex3d438x26yx3d48x26nux3drx78ox26nqbx3dkzwx78x26kzwx78x3dnikmax22x26q98k.uizsx3dquiom_$/$/$/$/$/$" + }, + { + "Gage Creed": "https://c-5uwzmx78pmca09x24quoqfx2ezivsmzx2ekwu.g00.ranker.com/g00/3_c-5eee.zivsmz.kwu_/c-5UWZMXPMCA09x24pbbx78ax3ax2fx2fquoqf.zivsmz.kwux2fcamz_vwlm_quox2f1968x2f41364699x2fwzqoqvitx2foiom-kzmml-nqtu-kpizikbmza-x78pwbw-c9x3fex3d438x26yx3d48x26nux3drx78ox26nqbx3dkzwx78x26kzwx78x3dnikmax22x26q98k.uizsx3dquiom_$/$/$/$/$/$" + }, + { + "Chatterer": "https://c-5uwzmx78pmca09x24quoqfx2ezivsmzx2ekwu.g00.ranker.com/g00/3_c-5eee.zivsmz.kwu_/c-5UWZMXPMCA09x24pbbx78ax3ax2fx2fquoqf.zivsmz.kwux2fvwlm_quox2f14x2f586061x2fwzqoqvitx2fkpibbmzmz-nqtu-kpizikbmza-x78pwbw-9x3fex3d438x26yx3d48x26nux3drx78ox26nqbx3dkzwx78x26kzwx78x3dnikmax22x26q98k.uizsx3dquiom_$/$/$/$/$/$" + } + ] +} \ No newline at end of file -- cgit v1.2.3 From a4c8da298b4b44fe222b304676029407734c77f6 Mon Sep 17 00:00:00 2001 From: Marko Kovačević Date: Wed, 10 Oct 2018 11:04:24 +0200 Subject: Change message to a more friendly one. --- bot/cogs/halloweenify.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bot/cogs/halloweenify.py b/bot/cogs/halloweenify.py index 0422e787..58cef019 100644 --- a/bot/cogs/halloweenify.py +++ b/bot/cogs/halloweenify.py @@ -33,8 +33,9 @@ class Halloweenify: embed.colour = discord.Colour.dark_orange() embed.title = 'Wow!' embed.description = ( - f'Your previous nickname, **{ctx.author.display_name}**, wasn\'t spooky enough for you that you have ' - f'decided to change it?! Okay, your new nickname will be **{nickname}**.\n\n' + f'**{ctx.author.display_name}** wasn\'t spooky enough for you? That\'s understandable, ' + f'{ctx.author.display_name} isn\'t scary at all! Let me think of something better. Hmm... I got it!\n Your ' + f'new nickname will be: \n 👻 **{nickname}** 🎃' ) embed.set_image(url=image) -- cgit v1.2.3 From 94a275c3b0222a261aa7d07b8ab37f92f9d82fd3 Mon Sep 17 00:00:00 2001 From: Marko Kovačević Date: Wed, 10 Oct 2018 11:18:55 +0200 Subject: Minor changes to the Embed. --- bot/cogs/halloweenify.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/cogs/halloweenify.py b/bot/cogs/halloweenify.py index 58cef019..c49e0058 100644 --- a/bot/cogs/halloweenify.py +++ b/bot/cogs/halloweenify.py @@ -31,11 +31,11 @@ class Halloweenify: # Build up a Embed embed = discord.Embed() embed.colour = discord.Colour.dark_orange() - embed.title = 'Wow!' + embed.title = 'Not spooky enough?' embed.description = ( f'**{ctx.author.display_name}** wasn\'t spooky enough for you? That\'s understandable, ' f'{ctx.author.display_name} isn\'t scary at all! Let me think of something better. Hmm... I got it!\n Your ' - f'new nickname will be: \n 👻 **{nickname}** 🎃' + f'new nickname will be: \n :jack_o_lantern: **{nickname}** :ghost:' ) embed.set_image(url=image) -- cgit v1.2.3 From 8ea196581e70e149ce998d9c49bf8bf1f9a746db Mon Sep 17 00:00:00 2001 From: Marko Kovačević Date: Wed, 10 Oct 2018 11:21:50 +0200 Subject: Ooops, reversed the emojis. --- bot/cogs/halloweenify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/cogs/halloweenify.py b/bot/cogs/halloweenify.py index c49e0058..226d55db 100644 --- a/bot/cogs/halloweenify.py +++ b/bot/cogs/halloweenify.py @@ -35,7 +35,7 @@ class Halloweenify: embed.description = ( f'**{ctx.author.display_name}** wasn\'t spooky enough for you? That\'s understandable, ' f'{ctx.author.display_name} isn\'t scary at all! Let me think of something better. Hmm... I got it!\n Your ' - f'new nickname will be: \n :jack_o_lantern: **{nickname}** :ghost:' + f'new nickname will be: \n :ghost: **{nickname}** :jack_o_lantern:' ) embed.set_image(url=image) -- cgit v1.2.3 From ff5882981e0fcaba65f8b6ffa0dcbdd756826503 Mon Sep 17 00:00:00 2001 From: Marko Kovačević Date: Wed, 10 Oct 2018 11:26:59 +0200 Subject: Missing newline. --- bot/cogs/halloweenify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/cogs/halloweenify.py b/bot/cogs/halloweenify.py index 226d55db..e4fb787c 100644 --- a/bot/cogs/halloweenify.py +++ b/bot/cogs/halloweenify.py @@ -35,7 +35,7 @@ class Halloweenify: embed.description = ( f'**{ctx.author.display_name}** wasn\'t spooky enough for you? That\'s understandable, ' f'{ctx.author.display_name} isn\'t scary at all! Let me think of something better. Hmm... I got it!\n Your ' - f'new nickname will be: \n :ghost: **{nickname}** :jack_o_lantern:' + f'new nickname will be: \n\n :ghost: **{nickname}** :jack_o_lantern:' ) embed.set_image(url=image) -- cgit v1.2.3 From fb46d8f2dba8a5f00bf7914c8b4a026acbbf55fc Mon Sep 17 00:00:00 2001 From: Marko Kovačević Date: Wed, 10 Oct 2018 11:28:46 +0200 Subject: Another cosmetic mistake. --- bot/cogs/halloweenify.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/cogs/halloweenify.py b/bot/cogs/halloweenify.py index e4fb787c..8a9db3df 100644 --- a/bot/cogs/halloweenify.py +++ b/bot/cogs/halloweenify.py @@ -34,8 +34,8 @@ class Halloweenify: embed.title = 'Not spooky enough?' embed.description = ( f'**{ctx.author.display_name}** wasn\'t spooky enough for you? That\'s understandable, ' - f'{ctx.author.display_name} isn\'t scary at all! Let me think of something better. Hmm... I got it!\n Your ' - f'new nickname will be: \n\n :ghost: **{nickname}** :jack_o_lantern:' + f'{ctx.author.display_name} isn\'t scary at all! Let me think of something better. Hmm... I got it!\n\n ' + f'Your new nickname will be: \n :ghost: **{nickname}** :jack_o_lantern:' ) embed.set_image(url=image) -- cgit v1.2.3 From 11a980feb09012db3e75d8817f908436eb13db68 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 10 Oct 2018 15:11:56 +0200 Subject: Dockerfile and build script --- docker/Dockerfile | 15 +++++++++++++++ docker/build.sh | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 docker/Dockerfile create mode 100755 docker/build.sh diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..9c4406bf --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,15 @@ +FROM python:3.6-alpine3.7 +RUN apk add --update tini git + +RUN mkdir /bot +COPY . /bot +WORKDIR /bot + +ENV LIBRARY_PATH=/lib:/usr/lib + +RUN pip install pipenv +RUN pipenv install --deploy --system + +ENTRYPOINT ["/sbin/tini", "--"] +CMD ["python", "-m", "bot"] + diff --git a/docker/build.sh b/docker/build.sh new file mode 100755 index 00000000..337f47c6 --- /dev/null +++ b/docker/build.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Build and deploy on master branch +#if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then + echo "Connecting to docker hub" + echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin + + echo "Building image" + docker build -t pythondiscord/hacktober-bot:latest -f docker/Dockerfile . + + echo "Pushing image" + docker push pythondiscord/hacktober-bot:latest + +# echo "Deploying container" +# curl -H "token: $AUTODEPLOY_TOKEN" $AUTODEPLOY_WEBHOOK +#else +# echo "Skipping deploy" +#fi + -- cgit v1.2.3 From 5426136e2aa6c492a36aa622f2c2eb2653e5fc24 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 10 Oct 2018 15:18:23 +0200 Subject: Move bot.py to __main__.py (Fixes #39) --- bot/__main__.py | 39 +++++++++++++++++++++++++++++++++++++++ bot/bot.py | 39 --------------------------------------- 2 files changed, 39 insertions(+), 39 deletions(-) create mode 100644 bot/__main__.py delete mode 100644 bot/bot.py diff --git a/bot/__main__.py b/bot/__main__.py new file mode 100644 index 00000000..a40ed0d4 --- /dev/null +++ b/bot/__main__.py @@ -0,0 +1,39 @@ +from os import environ +from pathlib import Path +from sys import stderr +from traceback import print_exc, format_exc + +from discord.ext import commands +import logging + +HACKTOBERBOT_TOKEN = environ.get('HACKTOBERBOT_TOKEN') + +if HACKTOBERBOT_TOKEN: + token_dl = len(HACKTOBERBOT_TOKEN) // 8 + logging.info(f'Bot token loaded: {HACKTOBERBOT_TOKEN[:token_dl]}...{HACKTOBERBOT_TOKEN[-token_dl:]}') +else: + logging.error(f'Bot token not found: {HACKTOBERBOT_TOKEN}') + +ghost_unicode = "\N{GHOST}" +bot = commands.Bot(command_prefix=commands.when_mentioned_or(".", f"{ghost_unicode} ", ghost_unicode)) + +logging.info('Start loading extensions from ./cogs/') + + +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}') + logging.info(f'Successfully loaded extension: {extension}') + except Exception as e: + logging.error(f'Failed to load extension {extension}: {repr(e)} {format_exc()}') + # print(f'Failed to load extension {extension}.', file=stderr) + # print_exc() + +logging.info(f'Spooky Launch Sequence Initiated...') + +bot.run(HACKTOBERBOT_TOKEN) + +logging.info(f'HackBot has been slain!') \ No newline at end of file diff --git a/bot/bot.py b/bot/bot.py deleted file mode 100644 index a40ed0d4..00000000 --- a/bot/bot.py +++ /dev/null @@ -1,39 +0,0 @@ -from os import environ -from pathlib import Path -from sys import stderr -from traceback import print_exc, format_exc - -from discord.ext import commands -import logging - -HACKTOBERBOT_TOKEN = environ.get('HACKTOBERBOT_TOKEN') - -if HACKTOBERBOT_TOKEN: - token_dl = len(HACKTOBERBOT_TOKEN) // 8 - logging.info(f'Bot token loaded: {HACKTOBERBOT_TOKEN[:token_dl]}...{HACKTOBERBOT_TOKEN[-token_dl:]}') -else: - logging.error(f'Bot token not found: {HACKTOBERBOT_TOKEN}') - -ghost_unicode = "\N{GHOST}" -bot = commands.Bot(command_prefix=commands.when_mentioned_or(".", f"{ghost_unicode} ", ghost_unicode)) - -logging.info('Start loading extensions from ./cogs/') - - -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}') - logging.info(f'Successfully loaded extension: {extension}') - except Exception as e: - logging.error(f'Failed to load extension {extension}: {repr(e)} {format_exc()}') - # print(f'Failed to load extension {extension}.', file=stderr) - # print_exc() - -logging.info(f'Spooky Launch Sequence Initiated...') - -bot.run(HACKTOBERBOT_TOKEN) - -logging.info(f'HackBot has been slain!') \ No newline at end of file -- cgit v1.2.3 From eb6a964786f8b42e24c71d5f19bb258fad77e3a2 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 10 Oct 2018 15:49:26 +0200 Subject: Add travis CI YML --- .travis.yml | 15 +++++++++++++++ Pipfile | 3 ++- tox.ini | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..33ea1fa6 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,15 @@ +language: python + +python: + - "3.7" + +sudo: required + +services: + - docker + +install: + - pip install flake8 pipenv + - pipenv install --deploy + - pipenv run lint + - sh docker/build.sh diff --git a/Pipfile b/Pipfile index 90f6f45e..a702616f 100644 --- a/Pipfile +++ b/Pipfile @@ -18,4 +18,5 @@ name = "pypi" python_version = "3.7" [scripts] -start = "python -m bot" \ No newline at end of file +start = "python -m bot" +lint = "flake8 bot" diff --git a/tox.ini b/tox.ini index 780c31d7..bff048cb 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [flake8] max-line-length=120 -application_import_names=proj +application_import_names=bot ignore=P102,B311,W503,E226,S311 exclude=__pycache__, venv, .venv, tests import-order-style=pycharm -- cgit v1.2.3 From fee5701143af0312db438253b06a470bdeadbe08 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 10 Oct 2018 15:52:49 +0200 Subject: Travis only has dev builds of 3.7 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 33ea1fa6..384c548c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: python python: - - "3.7" + - "3.7-dev" sudo: required -- cgit v1.2.3 From 2e85819a1f155c0e098e8928a879b39d07e65048 Mon Sep 17 00:00:00 2001 From: Daniel Brown Date: Wed, 10 Oct 2018 09:13:57 -0500 Subject: Corrected linting errors. --- bot/__init__.py | 5 +++-- bot/__main__.py | 9 ++++----- bot/cogs/hacktoberstats.py | 4 +++- bot/cogs/halloweenify.py | 2 +- bot/cogs/movie.py | 8 +++++--- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/bot/__init__.py b/bot/__init__.py index 8cbcd121..1d320245 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -1,5 +1,6 @@ -import os import logging.handlers +import os + # set up logging @@ -27,4 +28,4 @@ logging.basicConfig(format='%(asctime)s - %(name)s %(levelname)s: %(message)s', level=logging.DEBUG, handlers=[console_handler, file_handler]) -logging.info('Logging Process Started') \ No newline at end of file +logging.info('Logging Process Started') diff --git a/bot/__main__.py b/bot/__main__.py index a40ed0d4..c40836c5 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -1,10 +1,10 @@ +import logging from os import environ from pathlib import Path -from sys import stderr -from traceback import print_exc, format_exc +from traceback import format_exc from discord.ext import commands -import logging + HACKTOBERBOT_TOKEN = environ.get('HACKTOBERBOT_TOKEN') @@ -19,7 +19,6 @@ bot = commands.Bot(command_prefix=commands.when_mentioned_or(".", f"{ghost_unico logging.info('Start loading extensions from ./cogs/') - 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')] @@ -36,4 +35,4 @@ logging.info(f'Spooky Launch Sequence Initiated...') bot.run(HACKTOBERBOT_TOKEN) -logging.info(f'HackBot has been slain!') \ No newline at end of file +logging.info(f'HackBot has been slain!') diff --git a/bot/cogs/hacktoberstats.py b/bot/cogs/hacktoberstats.py index 4e896ae9..0a280443 100644 --- a/bot/cogs/hacktoberstats.py +++ b/bot/cogs/hacktoberstats.py @@ -95,7 +95,9 @@ class Stats: is_query = f"public+author:{username}" date_range = "2018-10-01..2018-10-31" per_page = "300" - query_url = f"{base_url}-label:{not_label}+type:{action_type}+is:{is_query}+created:{date_range}&per_page={per_page}" + query_url = ( + f"{base_url}-label:{not_label}+type:{action_type}+is:{is_query}+created:{date_range}&per_page={per_page}" + ) headers = {"user-agent": "Discord Python Hactoberbot"} async with aiohttp.ClientSession() as session: diff --git a/bot/cogs/halloweenify.py b/bot/cogs/halloweenify.py index 8a9db3df..201f6b95 100644 --- a/bot/cogs/halloweenify.py +++ b/bot/cogs/halloweenify.py @@ -1,5 +1,5 @@ -from pathlib import Path from json import load +from pathlib import Path from random import choice diff --git a/bot/cogs/movie.py b/bot/cogs/movie.py index bb6f8df8..647ee22a 100644 --- a/bot/cogs/movie.py +++ b/bot/cogs/movie.py @@ -1,8 +1,10 @@ -import requests import random from os import environ -from discord.ext import commands + +import requests from discord import Embed +from discord.ext import commands + TMDB_API_KEY = environ.get('TMDB_API_KEY') TMDB_TOKEN = environ.get('TMDB_TOKEN') @@ -72,7 +74,7 @@ class Movie: rating_count = movie.get('vote_average') / 2 rating = '' - for i in range(int(rating_count)): + for _ in range(int(rating_count)): rating += ':skull:' if (rating_count % 1) >= .5: -- cgit v1.2.3 From 99b2dbf0fa4a350ae559f779edae34d654d1ac8b Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 10 Oct 2018 16:22:05 +0200 Subject: Move some build steps to the script stage --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 384c548c..4c9a73f0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,5 +11,7 @@ services: install: - pip install flake8 pipenv - pipenv install --deploy + +script: - pipenv run lint - sh docker/build.sh -- cgit v1.2.3 From 29411f024301ae492c3d3796489d1340754c5336 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 10 Oct 2018 16:27:28 +0200 Subject: Add compose file --- docker/docker-compose.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 docker/docker-compose.yml diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 00000000..0a802ddc --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,11 @@ +version: "3" +services: + dumbo: + image: pythondiscord/hacktober-bot:latest + container_name: hacktoberbot + + restart: always + + environment: + - HACKTOBERBOT_TOKEN + -- cgit v1.2.3 From 64263af7674f6c50ca01e21779cf4a9d9ef49330 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 10 Oct 2018 16:39:37 +0200 Subject: Automatic deployment --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4c9a73f0..2a5a71e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,9 +9,10 @@ services: - docker install: - - pip install flake8 pipenv + - pip install flake8 pipenv salt-pepper - pipenv install --deploy script: - pipenv run lint - sh docker/build.sh + - pepper "glimglam.gserv.me" state.apply docker/hacktoberbot -- cgit v1.2.3 From 05d16a518671842d2ae5ee8905cb86921e86cd1e Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 10 Oct 2018 16:49:20 +0200 Subject: Silence Pepper --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2a5a71e3..8971aa6a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,4 +15,4 @@ install: script: - pipenv run lint - sh docker/build.sh - - pepper "glimglam.gserv.me" state.apply docker/hacktoberbot + - pepper "glimglam.gserv.me" state.apply docker/hacktoberbot &> /dev/null -- cgit v1.2.3 From 83228ce903ab1e6b62d53e3353b074ffb0f12d6a Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 10 Oct 2018 16:55:21 +0200 Subject: Apparently Pepper prompts for the password these days --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8971aa6a..cbd18edd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,4 +15,4 @@ install: script: - pipenv run lint - sh docker/build.sh - - pepper "glimglam.gserv.me" state.apply docker/hacktoberbot &> /dev/null + - echo $SALTAPI_PASS | pepper "glimglam.gserv.me" state.apply docker/hacktoberbot &> /dev/null -- cgit v1.2.3 From 86073bf95f8def1f8489c5dbceec73b4ad0f4c5f Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 10 Oct 2018 17:00:47 +0200 Subject: Attempt to fix Pepper --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index cbd18edd..5e05aac0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,4 +15,4 @@ install: script: - pipenv run lint - sh docker/build.sh - - echo $SALTAPI_PASS | pepper "glimglam.gserv.me" state.apply docker/hacktoberbot &> /dev/null + - pepper "glimglam.gserv.me" state.apply socker/hacktoberbot -u $SALTAPI_URL -a $SALTAPI_EAUTH --username SALTAPI_USER --password SALTAPI_PASS &> /dev/null -- cgit v1.2.3 From 3d2b799408a4d6243f16dbf99208418292f37cf1 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 10 Oct 2018 17:04:20 +0200 Subject: Let's try that again wthout a broken config --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5e05aac0..f4586702 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,4 +15,4 @@ install: script: - pipenv run lint - sh docker/build.sh - - pepper "glimglam.gserv.me" state.apply socker/hacktoberbot -u $SALTAPI_URL -a $SALTAPI_EAUTH --username SALTAPI_USER --password SALTAPI_PASS &> /dev/null + - pepper "glimglam.gserv.me" state.apply docker/hacktoberbot -u $SALTAPI_URL -a $SALTAPI_EAUTH --username $SALTAPI_USER --password $SALTAPI_PASS &> /dev/null -- cgit v1.2.3 From 7698f93144ffa38896fd4ad82cda5a4a44b0dbd7 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 10 Oct 2018 17:16:02 +0200 Subject: Move pepper command to build.sh --- .travis.yml | 1 - docker/build.sh | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f4586702..6f204bdb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,4 +15,3 @@ install: script: - pipenv run lint - sh docker/build.sh - - pepper "glimglam.gserv.me" state.apply docker/hacktoberbot -u $SALTAPI_URL -a $SALTAPI_EAUTH --username $SALTAPI_USER --password $SALTAPI_PASS &> /dev/null diff --git a/docker/build.sh b/docker/build.sh index 337f47c6..f0a98e49 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -10,6 +10,9 @@ echo "Pushing image" docker push pythondiscord/hacktober-bot:latest + + echo "Deploying on server" + pepper "glimglam.gserv.me" state.apply docker/hacktoberbot -u $SALTAPI_URL -a $SALTAPI_EAUTH --username $SALTAPI_USER --password $SALTAPI_PASS &> /dev/null # echo "Deploying container" # curl -H "token: $AUTODEPLOY_TOKEN" $AUTODEPLOY_WEBHOOK -- cgit v1.2.3 From c7d92f8086e951b170f5290ca91edb07adce1851 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 10 Oct 2018 17:32:14 +0100 Subject: Update vars in build.sh --- docker/build.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docker/build.sh b/docker/build.sh index f0a98e49..7e275a9c 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -12,11 +12,10 @@ docker push pythondiscord/hacktober-bot:latest echo "Deploying on server" - pepper "glimglam.gserv.me" state.apply docker/hacktoberbot -u $SALTAPI_URL -a $SALTAPI_EAUTH --username $SALTAPI_USER --password $SALTAPI_PASS &> /dev/null + pepper "glimglam.gserv.me" state.apply docker/hacktoberbot -u ${SALTAPI_URL} -a ${SALTAPI_EAUTH} --username ${SALTAPI_USER} --password ${SALTAPI_PASS} &> /dev/null # echo "Deploying container" # curl -H "token: $AUTODEPLOY_TOKEN" $AUTODEPLOY_WEBHOOK #else # echo "Skipping deploy" #fi - -- cgit v1.2.3 From d9e4d95613b69d9bf420c83f7f7655711fac1a79 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 10 Oct 2018 17:36:21 +0100 Subject: Pepper params are key=value --- docker/build.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docker/build.sh b/docker/build.sh index 7e275a9c..f4b54d4d 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -12,7 +12,10 @@ docker push pythondiscord/hacktober-bot:latest echo "Deploying on server" - pepper "glimglam.gserv.me" state.apply docker/hacktoberbot -u ${SALTAPI_URL} -a ${SALTAPI_EAUTH} --username ${SALTAPI_USER} --password ${SALTAPI_PASS} &> /dev/null + pepper "glimglam.gserv.me" state.apply docker/hacktoberbot \ + --saltapi-url=${SALTAPI_URL} --auth=${SALTAPI_EAUTH} \ + --username=${SALTAPI_USER} --password=${SALTAPI_PASS} \ + &> /dev/null # echo "Deploying container" # curl -H "token: $AUTODEPLOY_TOKEN" $AUTODEPLOY_WEBHOOK -- cgit v1.2.3 From 53b6ad68e2444cd15f2a30ecb5dc223a68b30dd1 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 10 Oct 2018 17:40:29 +0100 Subject: Pepper: See no evil.. --- docker/build.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker/build.sh b/docker/build.sh index f4b54d4d..dd703986 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -12,9 +12,9 @@ docker push pythondiscord/hacktober-bot:latest echo "Deploying on server" - pepper "glimglam.gserv.me" state.apply docker/hacktoberbot \ - --saltapi-url=${SALTAPI_URL} --auth=${SALTAPI_EAUTH} \ - --username=${SALTAPI_USER} --password=${SALTAPI_PASS} \ + pepper "$SALTAPI_TARGET" state.apply docker/hacktoberbot \ + --saltapi-url="$SALTAPI_URL" --auth="$SALTAPI_EAUTH" \ + --username="$SALTAPI_USER" --password="$SALTAPI_PASS" \ &> /dev/null # echo "Deploying container" -- cgit v1.2.3 From 4f6706ef1dc0abfefdf75d384b2cd0f28cf9216b Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 10 Oct 2018 17:49:09 +0100 Subject: Pepper: Fixed syntax again --- docker/build.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker/build.sh b/docker/build.sh index dd703986..7b97afcc 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -12,9 +12,9 @@ docker push pythondiscord/hacktober-bot:latest echo "Deploying on server" - pepper "$SALTAPI_TARGET" state.apply docker/hacktoberbot \ - --saltapi-url="$SALTAPI_URL" --auth="$SALTAPI_EAUTH" \ - --username="$SALTAPI_USER" --password="$SALTAPI_PASS" \ + pepper ${SALTAPI_TARGET} state.apply docker/hacktoberbot \ + --saltapi-url=${SALTAPI_URL} --auth=${SALTAPI_EAUTH} \ + --username=${SALTAPI_USER} --password=${SALTAPI_PASS} \ &> /dev/null # echo "Deploying container" -- cgit v1.2.3 From c758208b85ada40c13b4e0a02cbef0992b4fdd2a Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 10 Oct 2018 17:54:33 +0100 Subject: Make pepper behave more suitably for deployment --- docker/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/build.sh b/docker/build.sh index 7b97afcc..4cf22c6d 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -15,7 +15,7 @@ pepper ${SALTAPI_TARGET} state.apply docker/hacktoberbot \ --saltapi-url=${SALTAPI_URL} --auth=${SALTAPI_EAUTH} \ --username=${SALTAPI_USER} --password=${SALTAPI_PASS} \ - &> /dev/null + --out=no_out --non-interactive # echo "Deploying container" # curl -H "token: $AUTODEPLOY_TOKEN" $AUTODEPLOY_WEBHOOK -- cgit v1.2.3 From 7ca433000e7ad5f1b5e5ba779faf98959c508db2 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 10 Oct 2018 20:29:24 +0100 Subject: Remove extra params to pepper --- docker/build.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docker/build.sh b/docker/build.sh index 4cf22c6d..289f54e2 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -12,10 +12,7 @@ docker push pythondiscord/hacktober-bot:latest echo "Deploying on server" - pepper ${SALTAPI_TARGET} state.apply docker/hacktoberbot \ - --saltapi-url=${SALTAPI_URL} --auth=${SALTAPI_EAUTH} \ - --username=${SALTAPI_USER} --password=${SALTAPI_PASS} \ - --out=no_out --non-interactive + pepper ${SALTAPI_TARGET} state.apply docker/hacktoberbot --out=no_out --non-interactive # echo "Deploying container" # curl -H "token: $AUTODEPLOY_TOKEN" $AUTODEPLOY_WEBHOOK -- cgit v1.2.3 From 1ce65cf745d409550f36fa774825866c98d36cfe Mon Sep 17 00:00:00 2001 From: hundredrab Date: Thu, 11 Oct 2018 01:40:26 +0530 Subject: Fix #27: Add spooky reactions. --- bot/cogs/spookyreact.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 bot/cogs/spookyreact.py diff --git a/bot/cogs/spookyreact.py b/bot/cogs/spookyreact.py new file mode 100644 index 00000000..1afdb196 --- /dev/null +++ b/bot/cogs/spookyreact.py @@ -0,0 +1,32 @@ +from discord.ext import commands + +SPOOKY_TRIGGERS = { + 'spooky': "\U0001F47B", + 'skeleton': "\U0001F480", + 'doot': "\U0001F480", + 'pumpkin': "\U0001F383", + 'halloween': "\U0001F383", + 'jack-o-lantern': "\U0001F383" +} + + +class SpookyReact: + + """ + A cog that makes the bot react to message triggers. + """ + + def __init__(self, bot): + self.bot = bot + + async def on_message(self, ctx): + """ + A command to send the hacktoberbot github project + """ + for trigger in SPOOKY_TRIGGERS.keys(): + if trigger in ctx.content.lower(): + await ctx.add_reaction(SPOOKY_TRIGGERS[trigger]) + + +def setup(bot): + bot.add_cog(SpookyReact(bot)) -- cgit v1.2.3 From af52b46c79aab27500c273cc4262ffe57ae87fe8 Mon Sep 17 00:00:00 2001 From: hundredrab Date: Thu, 11 Oct 2018 01:54:19 +0530 Subject: Add skull-and-crossbones to spookyreacts. --- bot/cogs/spookyreact.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bot/cogs/spookyreact.py b/bot/cogs/spookyreact.py index 1afdb196..f5534626 100644 --- a/bot/cogs/spookyreact.py +++ b/bot/cogs/spookyreact.py @@ -6,7 +6,8 @@ SPOOKY_TRIGGERS = { 'doot': "\U0001F480", 'pumpkin': "\U0001F383", 'halloween': "\U0001F383", - 'jack-o-lantern': "\U0001F383" + 'jack-o-lantern': "\U0001F383", + 'danger': "\U00002620" } -- cgit v1.2.3 From a606e483b3a42357778fc3d4979e800e8dd38739 Mon Sep 17 00:00:00 2001 From: Leon Sandøy Date: Thu, 11 Oct 2018 11:44:28 +0200 Subject: Adding Pale Man, fixing all flake8 issues, converting halloweenify to use aiohttp, fixing broken logging, ignoring irrelevant loggers, and turning the script into a valid module script. --- bot/__init__.py | 19 ++++++++++++------- bot/__main__.py | 39 +++++++++++++++++++++++++++++++++++++++ bot/bot.py | 39 --------------------------------------- bot/cogs/hacktoberstats.py | 9 ++++++++- bot/cogs/halloweenify.py | 4 +--- bot/cogs/movie.py | 33 ++++++++++++++++++++------------- bot/resources/halloweenify.json | 3 +++ 7 files changed, 83 insertions(+), 63 deletions(-) create mode 100644 bot/__main__.py delete mode 100644 bot/bot.py diff --git a/bot/__init__.py b/bot/__init__.py index 8cbcd121..c2ea4ba0 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -1,8 +1,8 @@ -import os import logging.handlers +import os -# set up logging +# set up logging log_dir = 'log' log_file = log_dir + os.sep + 'hackbot.log' os.makedirs(log_dir, exist_ok=True) @@ -22,9 +22,14 @@ if root.handlers: for handler in root.handlers: root.removeHandler(handler) -# setup new logging configuration -logging.basicConfig(format='%(asctime)s - %(name)s %(levelname)s: %(message)s', datefmt="%D %H:%M:%S", - level=logging.DEBUG, - handlers=[console_handler, file_handler]) +# Silence irrelevant loggers +logging.getLogger("discord").setLevel(logging.ERROR) -logging.info('Logging Process Started') \ No newline at end of file +# setup new logging configuration +logging.basicConfig( + format='%(asctime)s - %(name)s %(levelname)s: %(message)s', + datefmt="%D %H:%M:%S", + level=logging.DEBUG, + handlers=[console_handler, file_handler] +) +logging.getLogger().info('Logging initialization complete') diff --git a/bot/__main__.py b/bot/__main__.py new file mode 100644 index 00000000..2c41d2d9 --- /dev/null +++ b/bot/__main__.py @@ -0,0 +1,39 @@ +import logging +from os import environ +from pathlib import Path +from traceback import format_exc + +from discord.ext import commands + +HACKTOBERBOT_TOKEN = environ.get('HACKTOBERBOT_TOKEN') +log = logging.getLogger() + +if HACKTOBERBOT_TOKEN: + token_dl = len(HACKTOBERBOT_TOKEN) // 8 + log.info(f'Bot token loaded: {HACKTOBERBOT_TOKEN[:token_dl]}...{HACKTOBERBOT_TOKEN[-token_dl:]}') +else: + log.error(f'Bot token not found: {HACKTOBERBOT_TOKEN}') + +ghost_unicode = "\N{GHOST}" +bot = commands.Bot(command_prefix=commands.when_mentioned_or(".", f"{ghost_unicode} ", ghost_unicode)) + +log.info('Start loading extensions from ./cogs/') + + +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}') + log.info(f'Successfully loaded extension: {extension}') + except Exception as e: + log.error(f'Failed to load extension {extension}: {repr(e)} {format_exc()}') + # print(f'Failed to load extension {extension}.', file=stderr) + # print_exc() + +log.info(f'Spooky Launch Sequence Initiated...') + +bot.run(HACKTOBERBOT_TOKEN) + +log.info(f'HackBot has been slain!') diff --git a/bot/bot.py b/bot/bot.py deleted file mode 100644 index a40ed0d4..00000000 --- a/bot/bot.py +++ /dev/null @@ -1,39 +0,0 @@ -from os import environ -from pathlib import Path -from sys import stderr -from traceback import print_exc, format_exc - -from discord.ext import commands -import logging - -HACKTOBERBOT_TOKEN = environ.get('HACKTOBERBOT_TOKEN') - -if HACKTOBERBOT_TOKEN: - token_dl = len(HACKTOBERBOT_TOKEN) // 8 - logging.info(f'Bot token loaded: {HACKTOBERBOT_TOKEN[:token_dl]}...{HACKTOBERBOT_TOKEN[-token_dl:]}') -else: - logging.error(f'Bot token not found: {HACKTOBERBOT_TOKEN}') - -ghost_unicode = "\N{GHOST}" -bot = commands.Bot(command_prefix=commands.when_mentioned_or(".", f"{ghost_unicode} ", ghost_unicode)) - -logging.info('Start loading extensions from ./cogs/') - - -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}') - logging.info(f'Successfully loaded extension: {extension}') - except Exception as e: - logging.error(f'Failed to load extension {extension}: {repr(e)} {format_exc()}') - # print(f'Failed to load extension {extension}.', file=stderr) - # print_exc() - -logging.info(f'Spooky Launch Sequence Initiated...') - -bot.run(HACKTOBERBOT_TOKEN) - -logging.info(f'HackBot has been slain!') \ No newline at end of file diff --git a/bot/cogs/hacktoberstats.py b/bot/cogs/hacktoberstats.py index 4e896ae9..ac81b887 100644 --- a/bot/cogs/hacktoberstats.py +++ b/bot/cogs/hacktoberstats.py @@ -95,7 +95,14 @@ class Stats: is_query = f"public+author:{username}" date_range = "2018-10-01..2018-10-31" per_page = "300" - query_url = f"{base_url}-label:{not_label}+type:{action_type}+is:{is_query}+created:{date_range}&per_page={per_page}" + query_url = ( + f"{base_url}" + f"-label:{not_label}" + f"+type:{action_type}" + f"+is:{is_query}" + f"+created:{date_range}" + f"&per_page={per_page}" + ) headers = {"user-agent": "Discord Python Hactoberbot"} async with aiohttp.ClientSession() as session: diff --git a/bot/cogs/halloweenify.py b/bot/cogs/halloweenify.py index 8a9db3df..ddd96bc6 100644 --- a/bot/cogs/halloweenify.py +++ b/bot/cogs/halloweenify.py @@ -1,15 +1,13 @@ -from pathlib import Path from json import load +from pathlib import Path from random import choice - import discord from discord.ext import commands from discord.ext.commands.cooldowns import BucketType class Halloweenify: - """ A cog to change a invokers nickname to a spooky one! """ diff --git a/bot/cogs/movie.py b/bot/cogs/movie.py index bb6f8df8..51529bc9 100644 --- a/bot/cogs/movie.py +++ b/bot/cogs/movie.py @@ -1,8 +1,10 @@ -import requests import random from os import environ -from discord.ext import commands + +import aiohttp from discord import Embed +from discord.ext import commands + TMDB_API_KEY = environ.get('TMDB_API_KEY') TMDB_TOKEN = environ.get('TMDB_TOKEN') @@ -40,19 +42,24 @@ class Movie: } # Get total page count of horror movies - response = requests.get(url=url, params=params, headers=headers) - total_pages = response.json().get('total_pages') + async with aiohttp.ClientSession() as session: + response = await session.get(url=url, params=params, headers=headers) + total_pages = await response.json() + total_pages = total_pages.get('total_pages') - # Get movie details from one random result on a random page - params['page'] = random.randint(1, total_pages) - response = requests.get(url=url, params=params, headers=headers) - selection_id = random.choice(response.json().get('results')).get('id') + # Get movie details from one random result on a random page + params['page'] = random.randint(1, total_pages) + response = await session.get(url=url, params=params, headers=headers) + response = await response.json() + selection_id = random.choice(response.get('results')).get('id') - # Get full details and credits - selection = requests.get(url='https://api.themoviedb.org/3/movie/' + str(selection_id), - params={'api_key': TMDB_API_KEY, 'append_to_response': 'credits'}) + # Get full details and credits + selection = await session.get( + url='https://api.themoviedb.org/3/movie/' + str(selection_id), + params={'api_key': TMDB_API_KEY, 'append_to_response': 'credits'} + ) - return selection.json() + return await selection.json() @staticmethod async def format_metadata(movie): @@ -72,7 +79,7 @@ class Movie: rating_count = movie.get('vote_average') / 2 rating = '' - for i in range(int(rating_count)): + for _ in range(int(rating_count)): rating += ':skull:' if (rating_count % 1) >= .5: diff --git a/bot/resources/halloweenify.json b/bot/resources/halloweenify.json index 458f9342..88c46bfc 100644 --- a/bot/resources/halloweenify.json +++ b/bot/resources/halloweenify.json @@ -74,6 +74,9 @@ }, { "Chatterer": "https://c-5uwzmx78pmca09x24quoqfx2ezivsmzx2ekwu.g00.ranker.com/g00/3_c-5eee.zivsmz.kwu_/c-5UWZMXPMCA09x24pbbx78ax3ax2fx2fquoqf.zivsmz.kwux2fvwlm_quox2f14x2f586061x2fwzqoqvitx2fkpibbmzmz-nqtu-kpizikbmza-x78pwbw-9x3fex3d438x26yx3d48x26nux3drx78ox26nqbx3dkzwx78x26kzwx78x3dnikmax22x26q98k.uizsx3dquiom_$/$/$/$/$/$" + }, + { + "Pale Man": "https://i2.wp.com/macguff.in/wp-content/uploads/2016/10/Pans-Labyrinth-Movie-Header-Image.jpg?fit=630%2C400&ssl=1" } ] } \ No newline at end of file -- cgit v1.2.3 From 5e2abfd06ebe5d3011fbbcc818d85e215f358969 Mon Sep 17 00:00:00 2001 From: Leon Sandøy Date: Thu, 11 Oct 2018 12:12:32 +0200 Subject: Made the movie formatter less naïve. It no longer crashes if TMDB's return data is incomplete. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot/cogs/movie.py | 51 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/bot/cogs/movie.py b/bot/cogs/movie.py index 51529bc9..82b9c682 100644 --- a/bot/cogs/movie.py +++ b/bot/cogs/movie.py @@ -67,36 +67,63 @@ class Movie: Formats raw TMDb data to be embedded in discord chat """ - tmdb_url = 'https://www.themoviedb.org/movie/' + str(movie.get('id')) - poster = 'https://image.tmdb.org/t/p/original' + movie.get('poster_path') + # Build the relevant URLs. + movie_id = movie.get("id") + poster_path = movie.get("poster_path") + tmdb_url = f'https://www.themoviedb.org/movie/{movie_id}' if movie_id else None + poster = f'https://image.tmdb.org/t/p/original{poster_path}' if poster_path else None + # Get cast names cast = [] - for actor in movie.get('credits').get('cast')[:3]: + for actor in movie.get('credits', {}).get('cast', [])[:3]: cast.append(actor.get('name')) - director = movie.get('credits').get('crew')[0].get('name') + # Get director name + director = movie.get('credits', {}).get('crew', []) + if director: + director = director[0].get('name') - rating_count = movie.get('vote_average') / 2 + # Determine the spookiness rating rating = '' + rating_count = movie.get('vote_average', 0) + + if rating_count: + rating_count /= 2 for _ in range(int(rating_count)): rating += ':skull:' - if (rating_count % 1) >= .5: rating += ':bat:' + # Try to get year of release and runtime + year = movie.get('release_date', [])[:4] + runtime = movie.get('runtime') + runtime = f"{runtime} minutes" if runtime else None + + # Not all these attributes will always be present + movie_attributes = { + "Directed by": director, + "Starring": ', '.join(cast), + "Running time": runtime, + "Release year": year, + "Spookiness rating": rating, + } + embed = Embed( colour=0x01d277, title='**' + movie.get('title') + '**', url=tmdb_url, description=movie.get('overview') ) - embed.set_image(url=poster) - embed.add_field(name='Starring', value=', '.join(cast)) - embed.add_field(name='Directed by', value=director) - embed.add_field(name='Year', value=movie.get('release_date')[:4]) - embed.add_field(name='Runtime', value=str(movie.get('runtime')) + ' min') - embed.add_field(name='Spooky Rating', value=rating) + + if poster: + embed.set_image(url=poster) + + # Add the attributes that we actually have data for, but not the others. + for name, value in movie_attributes.items(): + if value: + embed.add_field(name=name, value=value) + embed.set_footer(text='powered by themoviedb.org') return embed -- cgit v1.2.3 From 713bc1157d45f12a92a5c3ee9eedd83ff11d197d Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Thu, 11 Oct 2018 19:35:46 +0100 Subject: Deployment is working now --- docker/build.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docker/build.sh b/docker/build.sh index 289f54e2..ee46bf40 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -1,7 +1,7 @@ #!/bin/bash # Build and deploy on master branch -#if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then +if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then echo "Connecting to docker hub" echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin @@ -12,10 +12,10 @@ docker push pythondiscord/hacktober-bot:latest echo "Deploying on server" - pepper ${SALTAPI_TARGET} state.apply docker/hacktoberbot --out=no_out --non-interactive + pepper ${SALTAPI_TARGET} state.apply docker/hacktoberbot --out=no_out --non-interactive &> /dev/null -# echo "Deploying container" -# curl -H "token: $AUTODEPLOY_TOKEN" $AUTODEPLOY_WEBHOOK -#else -# echo "Skipping deploy" -#fi + echo "Deploying container" + curl -H "token: $AUTODEPLOY_TOKEN" $AUTODEPLOY_WEBHOOK +else + echo "Skipping deploy" +fi -- cgit v1.2.3 From 33c3b4fe7beccd102c4e181d80f533284de1c7f2 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Thu, 11 Oct 2018 19:39:08 +0100 Subject: Run bash script with bash --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6f204bdb..ae1d7653 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,4 +14,4 @@ install: script: - pipenv run lint - - sh docker/build.sh + - bash docker/build.sh -- cgit v1.2.3 From 0c76e002e1da343def4787c6b1bfcc1970aea853 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Thu, 11 Oct 2018 19:57:28 +0100 Subject: Linting. Thanks fellas. --- bot/cogs/spookyreact.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/bot/cogs/spookyreact.py b/bot/cogs/spookyreact.py index f5534626..2652a60e 100644 --- a/bot/cogs/spookyreact.py +++ b/bot/cogs/spookyreact.py @@ -1,5 +1,3 @@ -from discord.ext import commands - SPOOKY_TRIGGERS = { 'spooky': "\U0001F47B", 'skeleton': "\U0001F480", -- cgit v1.2.3 From c3dce15ddc362757cc0e8e989395d80c39f24725 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Thu, 11 Oct 2018 20:25:05 +0100 Subject: Remove extra lines in build script --- docker/build.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/docker/build.sh b/docker/build.sh index ee46bf40..153fbccc 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -13,9 +13,6 @@ if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then echo "Deploying on server" pepper ${SALTAPI_TARGET} state.apply docker/hacktoberbot --out=no_out --non-interactive &> /dev/null - - echo "Deploying container" - curl -H "token: $AUTODEPLOY_TOKEN" $AUTODEPLOY_WEBHOOK else echo "Skipping deploy" fi -- cgit v1.2.3 From 79dc1d87824b6ab1afc2832f4e40c981ac8f0e20 Mon Sep 17 00:00:00 2001 From: Leon Sandøy Date: Fri, 12 Oct 2018 00:27:22 +0200 Subject: improving the .help docstrings, and making the bot load cogs from the correct path. (#43) * Improving some docstrings and making it look in ./bot/cogs for cogs. * Removing pointless stuff from a docstring --- bot/__main__.py | 6 +++--- bot/cogs/halloweenify.py | 3 +++ bot/cogs/movie.py | 5 ++++- bot/cogs/template.py | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/bot/__main__.py b/bot/__main__.py index 2c41d2d9..ccd69b0b 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -17,15 +17,15 @@ else: ghost_unicode = "\N{GHOST}" bot = commands.Bot(command_prefix=commands.when_mentioned_or(".", f"{ghost_unicode} ", ghost_unicode)) -log.info('Start loading extensions from ./cogs/') +log.info('Start loading extensions from ./bot/cogs/') 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')] + cogs = [file.stem for file in Path('bot', 'cogs').glob('*.py')] for extension in cogs: try: - bot.load_extension(f'cogs.{extension}') + bot.load_extension(f'bot.cogs.{extension}') log.info(f'Successfully loaded extension: {extension}') except Exception as e: log.error(f'Failed to load extension {extension}: {repr(e)} {format_exc()}') diff --git a/bot/cogs/halloweenify.py b/bot/cogs/halloweenify.py index ddd96bc6..3bd04b80 100644 --- a/bot/cogs/halloweenify.py +++ b/bot/cogs/halloweenify.py @@ -18,6 +18,9 @@ class Halloweenify: @commands.cooldown(1, 300, BucketType.user) @commands.command() async def halloweenify(self, ctx): + """ + Change your nickname into a much spookier one! + """ with open(Path('../bot/resources', 'halloweenify.json'), 'r') as f: data = load(f) diff --git a/bot/cogs/movie.py b/bot/cogs/movie.py index 82b9c682..925f813f 100644 --- a/bot/cogs/movie.py +++ b/bot/cogs/movie.py @@ -18,8 +18,11 @@ class Movie: def __init__(self, bot): self.bot = bot - @commands.command(name='movie', alias=['tmdb'], brief='Pick a scary movie') + @commands.command(name='movie', alias=['tmdb']) async def random_movie(self, ctx): + """ + Randomly select a scary movie and display information about it. + """ selection = await self.select_movie() movie_details = await self.format_metadata(selection) diff --git a/bot/cogs/template.py b/bot/cogs/template.py index b3f4da21..aa01432c 100644 --- a/bot/cogs/template.py +++ b/bot/cogs/template.py @@ -17,7 +17,7 @@ class Template: """ await ctx.send('https://github.com/discord-python/hacktoberbot') - @commands.group(name='git', invoke_without_command=True) + @commands.group(name='git', invoke_without_command=True, brief="A link to resources for learning Git") async def github(self, ctx): """ A command group with the name git. You can now create sub-commands such as git commit. -- cgit v1.2.3 From 3230a505b1e5aa84e79a0afc09e10da6d433120d Mon Sep 17 00:00:00 2001 From: Leon Sandøy Date: Fri, 12 Oct 2018 00:36:53 +0200 Subject: Fixing halloweenify json path --- bot/cogs/halloweenify.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bot/cogs/halloweenify.py b/bot/cogs/halloweenify.py index ddd96bc6..a5fe45ef 100644 --- a/bot/cogs/halloweenify.py +++ b/bot/cogs/halloweenify.py @@ -18,7 +18,10 @@ class Halloweenify: @commands.cooldown(1, 300, BucketType.user) @commands.command() async def halloweenify(self, ctx): - with open(Path('../bot/resources', 'halloweenify.json'), 'r') as f: + """ + Change your nickname into a much spookier one! + """ + with open(Path('./bot/resources', 'halloweenify.json'), 'r') as f: data = load(f) # Choose a random character from our list we loaded above and set apart the nickname and image url. -- cgit v1.2.3 From 9567aec0929ade42e57e677b66da942abc51e59a Mon Sep 17 00:00:00 2001 From: Leon Sandøy Date: Fri, 12 Oct 2018 01:01:59 +0200 Subject: The app was logging to the wrong directory. This is now fixed. Also silenced websockets logging --- bot/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bot/__init__.py b/bot/__init__.py index c2ea4ba0..c411deb6 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -1,10 +1,11 @@ import logging.handlers import os +from pathlib import Path # set up logging -log_dir = 'log' -log_file = log_dir + os.sep + 'hackbot.log' +log_dir = Path("bot", "log") +log_file = log_dir / "hackbot.log" os.makedirs(log_dir, exist_ok=True) # file handler sets up rotating logs every 5 MB @@ -24,6 +25,7 @@ if root.handlers: # Silence irrelevant loggers logging.getLogger("discord").setLevel(logging.ERROR) +logging.getLogger("websockets").setLevel(logging.ERROR) # setup new logging configuration logging.basicConfig( -- cgit v1.2.3