From 50605eb589e2a5e605ca14d40bf9c9b3ab5912ca Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Sat, 2 Sep 2017 00:56:34 -0400 Subject: [PATCH 1/6] Rewrite of the help output. now it will PM you --- app/dragon-bot.py | 3 ++- app/help_methods.py | 54 ++++++++++++++++++++++++++------------------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/app/dragon-bot.py b/app/dragon-bot.py index 191cd2d7..325a9caa 100644 --- a/app/dragon-bot.py +++ b/app/dragon-bot.py @@ -105,8 +105,9 @@ async def on_message(message): await client.send_message(message.channel, excuse.get_excuse()) if message.content.startswith('!help'): + await client.send_message(message.channel, "ok {}, check your private messages".format(message.author.mention)) await client.send_message( - message.channel, + message.author, help_methods.parse_message(message.content) ) diff --git a/app/help_methods.py b/app/help_methods.py index d1b8a720..17b81cec 100644 --- a/app/help_methods.py +++ b/app/help_methods.py @@ -10,56 +10,64 @@ def get_help_message(method): supported_methods = { '8ball': [ 'Ask dragon bot a question and it will give you an 8ball response', - '\n\nUsage: !8ball Will I win the lottery tomorrow?' + '\nUsage: !8ball Will I win the lottery tomorrow?' ], 'decide': [ 'Dragon-bot will help make the tough decisions for you', - '\n\n!decide option 1 or option 2.\n\nIf thre is only', - 'one option, it will give you a yes or no' + ' If there is only one option, it will give you a yes or no', + '\nUsage: !decide cake or pie\n!decide should I do my homework' ], 'define': [ 'Returns a definiton of a word from urban dictionary', - '\n\nUsage: !define loli' + '\nUsage: !define loli' ], 'docker': [ - 'Two supported actions: logs and restart\n\nlogs: Shows you the', + 'Two supported actions: logs and restart\nlogs: Shows you the', 'last X number of lines from the minecraft server. If no number', - 'is specified, defaults to 10.\n\nrestart: will restart the min', - 'ecraft server if something is fucky' + ' is specified, defaults to 10.\nrestart: will restart the min', + 'ecraft server.' ], 'excuse': [ - 'Generates a random excuse you can give your boss'], + 'Generates a random excuse you can give your boss', + '\nUsage: !excuse' + ], 'help': [ - 'Prints out a list of everything dragon-bot can do' + 'Shows you this message' ], 'lewd': [ 'Returns a URL for a lewd image.', - 'Can only be used in NSFW channels' + 'Can only be used in NSFW channels.', + '\nUsage: !lewd' ], 'purge': [ - 'Deletes the last 20 messages you sent from the channel you', - 'typed purge in, unless otherwise specified. eg. !purge 8' + 'By default, will delete your last 20 messages. You can override this', + ' with your own number. \nUsage: !purge or !purge 15' ], 'wallpaper': [ 'Returns the URL for a 4k wallpaper. You can enter', - 'a search term as well, for example, !wallpaper, or', - ', !wallpaper flowers. Supports multiple tags.' + 'a search term as well. Supports multiple search terms as well', + '\nUsage: !wallpaper flowers or !wallpaper mountain flowers sky ' ], 'message': [ 'You can ask me a question directly and I will do my best to answer it.', - '\nUsage:\n\n@dragon-bot what is the capital of France?\n@dragon-bot 94*37', - '\n@dragon-bot how many calories in a bottle of wine?' + '\nUsage: @dragon-bot what is the capital of France?' ] } + # Print out every help method if method == 'show_all': - count = len(supported_methods) - keys = ', '.join(supported_methods.keys()) - - message = "I currently have `{}` methods,\n\n```{}```\n\nYou can get in formation about a specific method by typing !help ".format(count, keys) + # Might be a better way to do this, but build a list of method : description + build_message = [] + for key, value in supported_methods.items(): + build_message.append("\n{} : {}\n".format(key, ' '.join(supported_methods[key]))) + # Join every element of the list with a space + message = ' '.join(build_message) else: - message = ' '.join(supported_methods[method]) - return message + # Join key : value of the help method they passed in + message = "{} : {}".format(method, ' '.join(supported_methods[method])) + + # Return the message wrapped in css formatting so we get pretty colors + return "```css\n{}\n```".format(message) def parse_message(message): if len(message.split()) > 1: @@ -68,6 +76,6 @@ def parse_message(message): explanation = get_help_message(method) except KeyError: return "I can't help you with that" - return "```{}```".format(explanation) + return "```css\n{}\n```".format(explanation) return get_help_message('show_all') From 3ca9a13aa6718932b0a6f95d2e16c1f265f9e6a8 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Mon, 11 Sep 2017 11:02:20 -0700 Subject: [PATCH 2/6] Updating pipeline url --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9c456087..aab0f8ee 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ A discord bot for the trifecta discord channel * The dragon-bot-test bot will connect to the server. * If you want to test what the bot is seeing when you type commands, add LOTS of of print statements to dragon-bot.py * you will see the output in the terminal. This is useful for debugging -* pipeline [here](https://cloud.docker.com/app/ldooks/repository/docker/ldooks/dragon-bot/builds) +* pipeline [here](https://gitlab.com/ldooks/dragon-bot/pipelines) ### Contribution guidelines ### From 1e48dc1d10e20dd1ec50eb949ab1353fac5595af Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Thu, 14 Sep 2017 20:28:04 +0000 Subject: [PATCH 3/6] Send users a PM with their roles --- app/dragon-bot.py | 10 ++++++++++ app/help_methods.py | 3 +++ 2 files changed, 13 insertions(+) diff --git a/app/dragon-bot.py b/app/dragon-bot.py index 325a9caa..8a6ec695 100644 --- a/app/dragon-bot.py +++ b/app/dragon-bot.py @@ -132,6 +132,16 @@ async def on_message(message): return await client.purge_from(message.channel, limit=num, check=is_me) + if message.content.startswith('!roles'): + await client.send_message( + message.channel, + "ok {}. Check your PMs".format(message.author.mention) + ) + await client.send_message( + message.author, + "```{}```".format(' '.join(list(map(lambda x: x.name, message.author.roles)))) + ) + if message.content.startswith('!wallpaper'): await client.send_message( message.channel, diff --git a/app/help_methods.py b/app/help_methods.py index 17b81cec..3356e357 100644 --- a/app/help_methods.py +++ b/app/help_methods.py @@ -43,6 +43,9 @@ def get_help_message(method): 'By default, will delete your last 20 messages. You can override this', ' with your own number. \nUsage: !purge or !purge 15' ], + 'roles': [ + 'Dragon bot will PM you a message with all the roles you have on the server' + ], 'wallpaper': [ 'Returns the URL for a 4k wallpaper. You can enter', 'a search term as well. Supports multiple search terms as well', From 9a7d24bcbb8f5b7561ee7250f7fb43b1458ce644 Mon Sep 17 00:00:00 2001 From: Zoid Date: Tue, 19 Sep 2017 17:08:51 -0600 Subject: [PATCH 4/6] Add support for fuckinghomepage.com. Fixes #23 --- .gitlab-ci.yml | 4 ++-- Dockerfile | 4 ++-- Dockerfile-test-env | 2 +- app/dragon-bot.py | 5 +++++ app/wallpaper.py | 19 ++++++++++++++++++- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f7bb5601..515a5fe7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ services: before_script: - apk add --no-cache python3 - - pip3 install pylint requests discord.py docker pylint wolframalpha + - pip3 install pylint requests discord.py docker pylint wolframalpha beautifulsoup4 stages: - test @@ -28,4 +28,4 @@ build_and_push_container: only: - master tags: - - docker \ No newline at end of file + - docker diff --git a/Dockerfile b/Dockerfile index f3aeb963..708a215b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM python:3.6.2-alpine3.6 LABEL name="Dragon Bot" RUN apk update && apk add --no-cache docker -RUN pip install requests discord.py docker wolframalpha +RUN pip install requests discord.py docker wolframalpha beautifulsoup4 ADD app /app -CMD python app/dragon-bot.py \ No newline at end of file +CMD python app/dragon-bot.py diff --git a/Dockerfile-test-env b/Dockerfile-test-env index 0f629ee9..bfab36c8 100644 --- a/Dockerfile-test-env +++ b/Dockerfile-test-env @@ -2,7 +2,7 @@ FROM python:3.6.2-alpine3.6 LABEL name="Dragon Bot Test environment" RUN apk update && apk add --no-cache vim docker -RUN pip install requests discord.py docker pylint wolframalpha +RUN pip install requests discord.py docker pylint wolframalpha beautifulsoup4 ADD app /app RUN printf "\n\nTesting your python code for errors\n\n" && \ diff --git a/app/dragon-bot.py b/app/dragon-bot.py index 8a6ec695..6a8aaae3 100644 --- a/app/dragon-bot.py +++ b/app/dragon-bot.py @@ -147,7 +147,12 @@ async def on_message(message): message.channel, wallpaper.get_wall(message.content) ) + if message.content.startswith('!homepage'): + await client.send_message( + message.channel, + wallpaper.get_picture(message.content) + ) if message.content.startswith('!docker'): # Check permissions if not role_check.docker_permissions(message.author.roles): diff --git a/app/wallpaper.py b/app/wallpaper.py index 6cf89456..072da295 100644 --- a/app/wallpaper.py +++ b/app/wallpaper.py @@ -1,5 +1,8 @@ import requests - +import requests +from bs4 import BeautifulSoup +import urllib +from urllib.parse import urlparse def get_wall(message): unsplash_url = "https://source.unsplash.com/3840x2160/?" @@ -26,3 +29,17 @@ def get_wall(message): return "Could not find an image for those tags." else: return response + +def get_picture(find): + + url = requests.get("http://fuckinghomepage.com") + soup = BeautifulSoup(url.content) + soup.prettify(formatter=None) + for parse in soup.find_all("p"): + if 'SWEET-ASS PICTURE' in ''.join(parse.findAll(text=True)): + link = parse.find_next_sibling('p') + if "http://" or "https://" in link.get('href', ''): + link = link.find('small').find_next('a', href=True)['href'] + return urllib.parse.unquote(link.split('http://t.umblr.com/redirect?z=')[1].split('&')[0]) + + From 8b00f273b31fe23d8ca9579da8f8a04c12c42846 Mon Sep 17 00:00:00 2001 From: Tyler Hodapp Date: Wed, 20 Sep 2017 16:37:33 +0000 Subject: [PATCH 5/6] added help message for homepage --- app/help_methods.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/help_methods.py b/app/help_methods.py index 3356e357..647e3731 100644 --- a/app/help_methods.py +++ b/app/help_methods.py @@ -54,6 +54,11 @@ def get_help_message(method): 'message': [ 'You can ask me a question directly and I will do my best to answer it.', '\nUsage: @dragon-bot what is the capital of France?' + ], + 'homepage': [ + 'This function now outputs the SWEET-ASS picture of the day.', + ' Note this picture only changes once a day.', + '\nUsage: !homepage' ] } From bae7b00f757f69f8048793d02e320a02fd2b7046 Mon Sep 17 00:00:00 2001 From: luke Date: Thu, 21 Sep 2017 16:18:46 -0700 Subject: [PATCH 6/6] change cleanup number to 10 --- app/dragon-bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/dragon-bot.py b/app/dragon-bot.py index 6a8aaae3..113078bd 100644 --- a/app/dragon-bot.py +++ b/app/dragon-bot.py @@ -84,7 +84,7 @@ async def on_message(message): def is_bot(m): return m.author == client.user - await client.purge_from(message.channel, limit=100, check=is_bot) + await client.purge_from(message.channel, limit=10, check=is_bot) if message.content.startswith('!decide'): await client.send_message(