Merge branch 'master' into 'weather'
# Conflicts: # .gitlab-ci.yml # Dockerfile # Dockerfile-test-env Resolved by importing both PyOWM and BeautifulSoup4
This commit is contained in:
commit
2c5907d6ec
@ -4,7 +4,7 @@ services:
|
|||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- apk add --no-cache python3
|
- apk add --no-cache python3
|
||||||
- pip3 install pylint requests discord.py docker pylint wolframalpha pyowm
|
- pip3 install pylint requests discord.py docker pylint wolframalpha pyowm beautifulsoup4
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- test
|
- test
|
||||||
|
@ -2,7 +2,7 @@ FROM python:3.6.2-alpine3.6
|
|||||||
LABEL name="Dragon Bot"
|
LABEL name="Dragon Bot"
|
||||||
RUN apk update && apk add --no-cache docker
|
RUN apk update && apk add --no-cache docker
|
||||||
|
|
||||||
RUN pip install requests discord.py docker wolframalpha pyowm
|
RUN pip install requests discord.py docker wolframalpha pyowm beautifulsoup4
|
||||||
ADD app /app
|
ADD app /app
|
||||||
|
|
||||||
CMD python app/dragon-bot.py
|
CMD python app/dragon-bot.py
|
||||||
|
@ -2,7 +2,7 @@ FROM python:3.6.2-alpine3.6
|
|||||||
LABEL name="Dragon Bot Test environment"
|
LABEL name="Dragon Bot Test environment"
|
||||||
RUN apk update && apk add --no-cache vim docker
|
RUN apk update && apk add --no-cache vim docker
|
||||||
|
|
||||||
RUN pip install requests discord.py docker pylint wolframalpha pyowm
|
RUN pip install requests discord.py docker pylint wolframalpha pyowm beautifulsoup4
|
||||||
ADD app /app
|
ADD app /app
|
||||||
|
|
||||||
RUN printf "\n\nTesting your python code for errors\n\n" && \
|
RUN printf "\n\nTesting your python code for errors\n\n" && \
|
||||||
|
@ -19,7 +19,7 @@ A discord bot for the trifecta discord channel
|
|||||||
* The dragon-bot-test bot will connect to the server.
|
* 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
|
* 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
|
* 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 ###
|
### Contribution guidelines ###
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ async def on_message(message):
|
|||||||
|
|
||||||
def is_bot(m):
|
def is_bot(m):
|
||||||
return m.author == client.user
|
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'):
|
if message.content.startswith('!decide'):
|
||||||
await client.send_message(
|
await client.send_message(
|
||||||
@ -105,8 +105,9 @@ async def on_message(message):
|
|||||||
await client.send_message(message.channel, excuse.get_excuse())
|
await client.send_message(message.channel, excuse.get_excuse())
|
||||||
|
|
||||||
if message.content.startswith('!help'):
|
if message.content.startswith('!help'):
|
||||||
|
await client.send_message(message.channel, "ok {}, check your private messages".format(message.author.mention))
|
||||||
await client.send_message(
|
await client.send_message(
|
||||||
message.channel,
|
message.author,
|
||||||
help_methods.parse_message(message.content)
|
help_methods.parse_message(message.content)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -131,12 +132,27 @@ async def on_message(message):
|
|||||||
return
|
return
|
||||||
await client.purge_from(message.channel, limit=num, check=is_me)
|
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'):
|
if message.content.startswith('!wallpaper'):
|
||||||
await client.send_message(
|
await client.send_message(
|
||||||
message.channel,
|
message.channel,
|
||||||
wallpaper.get_wall(message.content)
|
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'):
|
if message.content.startswith('!docker'):
|
||||||
# Check permissions
|
# Check permissions
|
||||||
if not role_check.docker_permissions(message.author.roles):
|
if not role_check.docker_permissions(message.author.roles):
|
||||||
|
@ -10,56 +10,72 @@ def get_help_message(method):
|
|||||||
supported_methods = {
|
supported_methods = {
|
||||||
'8ball': [
|
'8ball': [
|
||||||
'Ask dragon bot a question and it will give you an 8ball response',
|
'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': [
|
'decide': [
|
||||||
'Dragon-bot will help make the tough decisions for you',
|
'Dragon-bot will help make the tough decisions for you',
|
||||||
'\n\n!decide option 1 or option 2.\n\nIf thre is only',
|
' If there is only one option, it will give you a yes or no',
|
||||||
'one option, it will give you a yes or no'
|
'\nUsage: !decide cake or pie\n!decide should I do my homework'
|
||||||
],
|
],
|
||||||
'define': [
|
'define': [
|
||||||
'Returns a definiton of a word from urban dictionary',
|
'Returns a definiton of a word from urban dictionary',
|
||||||
'\n\nUsage: !define loli'
|
'\nUsage: !define loli'
|
||||||
],
|
],
|
||||||
'docker': [
|
'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',
|
'last X number of lines from the minecraft server. If no number',
|
||||||
'is specified, defaults to 10.\n\nrestart: will restart the min',
|
' is specified, defaults to 10.\nrestart: will restart the min',
|
||||||
'ecraft server if something is fucky'
|
'ecraft server.'
|
||||||
],
|
],
|
||||||
'excuse': [
|
'excuse': [
|
||||||
'Generates a random excuse you can give your boss'],
|
'Generates a random excuse you can give your boss',
|
||||||
|
'\nUsage: !excuse'
|
||||||
|
],
|
||||||
'help': [
|
'help': [
|
||||||
'Prints out a list of everything dragon-bot can do'
|
'Shows you this message'
|
||||||
],
|
],
|
||||||
'lewd': [
|
'lewd': [
|
||||||
'Returns a URL for a lewd image.',
|
'Returns a URL for a lewd image.',
|
||||||
'Can only be used in NSFW channels'
|
'Can only be used in NSFW channels.',
|
||||||
|
'\nUsage: !lewd'
|
||||||
],
|
],
|
||||||
'purge': [
|
'purge': [
|
||||||
'Deletes the last 20 messages you sent from the channel you',
|
'By default, will delete your last 20 messages. You can override this',
|
||||||
'typed purge in, unless otherwise specified. eg. !purge 8'
|
' 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': [
|
'wallpaper': [
|
||||||
'Returns the URL for a 4k wallpaper. You can enter',
|
'Returns the URL for a 4k wallpaper. You can enter',
|
||||||
'a search term as well, for example, !wallpaper, or',
|
'a search term as well. Supports multiple search terms as well',
|
||||||
', !wallpaper flowers. Supports multiple tags.'
|
'\nUsage: !wallpaper flowers or !wallpaper mountain flowers sky '
|
||||||
],
|
],
|
||||||
'message': [
|
'message': [
|
||||||
'You can ask me a question directly and I will do my best to answer it.',
|
'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',
|
'\nUsage: @dragon-bot what is the capital of France?'
|
||||||
'\n@dragon-bot how many calories in a bottle of wine?'
|
],
|
||||||
|
'homepage': [
|
||||||
|
'This function now outputs the SWEET-ASS picture of the day.',
|
||||||
|
' Note this picture only changes once a day.',
|
||||||
|
'\nUsage: !homepage'
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Print out every help method
|
||||||
if method == 'show_all':
|
if method == 'show_all':
|
||||||
count = len(supported_methods)
|
# Might be a better way to do this, but build a list of method : description
|
||||||
keys = ', '.join(supported_methods.keys())
|
build_message = []
|
||||||
|
for key, value in supported_methods.items():
|
||||||
message = "I currently have `{}` methods,\n\n```{}```\n\nYou can get in formation about a specific method by typing !help <method>".format(count, keys)
|
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:
|
else:
|
||||||
message = ' '.join(supported_methods[method])
|
# Join key : value of the help method they passed in
|
||||||
return message
|
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):
|
def parse_message(message):
|
||||||
if len(message.split()) > 1:
|
if len(message.split()) > 1:
|
||||||
@ -68,6 +84,6 @@ def parse_message(message):
|
|||||||
explanation = get_help_message(method)
|
explanation = get_help_message(method)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return "I can't help you with that"
|
return "I can't help you with that"
|
||||||
return "```{}```".format(explanation)
|
return "```css\n{}\n```".format(explanation)
|
||||||
|
|
||||||
return get_help_message('show_all')
|
return get_help_message('show_all')
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
import requests
|
import requests
|
||||||
|
import requests
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
import urllib
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
def get_wall(message):
|
def get_wall(message):
|
||||||
unsplash_url = "https://source.unsplash.com/3840x2160/?"
|
unsplash_url = "https://source.unsplash.com/3840x2160/?"
|
||||||
@ -26,3 +29,17 @@ def get_wall(message):
|
|||||||
return "Could not find an image for those tags."
|
return "Could not find an image for those tags."
|
||||||
else:
|
else:
|
||||||
return response
|
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])
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user