From 15f047d7ac6898abb065e8f7bd4f8d0ef0c1511c Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Sat, 5 Aug 2017 12:14:08 -0700 Subject: [PATCH 1/9] Testing that the script gets tested in the build --- bitbucket-pipelines.yml | 6 ++++++ dragon-bot.py | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index 3fa6710f..f6bb14f0 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -10,6 +10,12 @@ options: docker: true pipelines: +image: python:3.6.2-slim +pipelines: + default: + - step: + script: + - python dragon-bot.py test branches: master: - step: diff --git a/dragon-bot.py b/dragon-bot.py index de719b59..f76836b5 100644 --- a/dragon-bot.py +++ b/dragon-bot.py @@ -7,6 +7,7 @@ import logging import os import random import requests +import sys import time # Client object @@ -255,4 +256,8 @@ async def on_message(message): else: await client.send_message(message.channel, "There arent {} lines of output yet".format(num_lines)) +# Check if there is a command line argument after script +if len(sys.argv) > 1: + print("If you're seeing this, the python compiled") + sys.exit() client.run(botToken) \ No newline at end of file From 745f0bcb033db2e0e88ef48f9285f217d9ff74c8 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Sat, 5 Aug 2017 12:19:51 -0700 Subject: [PATCH 2/9] trying again --- bitbucket-pipelines.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index f6bb14f0..820c17c5 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -10,12 +10,6 @@ options: docker: true pipelines: -image: python:3.6.2-slim -pipelines: - default: - - step: - script: - - python dragon-bot.py test branches: master: - step: @@ -28,6 +22,11 @@ pipelines: # push the new Docker image to the Docker registry - docker push $IMAGE_NAME feature/*: + - step: + script: + - echo "Making sure the python actually runs" + - pip install docker discord.py pybooru requests + - python dragon-bot.py test - step: script: # Only build iamges, dont push when we're on a feature branch From 75c77744a80d473bf162163621f16058c69d9855 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Sat, 5 Aug 2017 12:20:57 -0700 Subject: [PATCH 3/9] trying again --- bitbucket-pipelines.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index 820c17c5..e039dc8c 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -27,9 +27,7 @@ pipelines: - echo "Making sure the python actually runs" - pip install docker discord.py pybooru requests - python dragon-bot.py test - - step: - script: - # Only build iamges, dont push when we're on a feature branch - - export IMAGE_NAME=ldooks/dragon-bot:latest - # build the Docker image (this will use the Dockerfile in the root of the repo) - - docker build -t $IMAGE_NAME . \ No newline at end of file + # Only build iamges, dont push when we're on a feature branch + - export IMAGE_NAME=ldooks/dragon-bot:latest + # build the Docker image (this will use the Dockerfile in the root of the repo) + - docker build -t $IMAGE_NAME . \ No newline at end of file From 8110531b9ba8f16302142bb4997d93403eedf19b Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Sat, 5 Aug 2017 12:21:38 -0700 Subject: [PATCH 4/9] trying again --- bitbucket-pipelines.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index e039dc8c..2a4ed12b 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -9,6 +9,7 @@ options: docker: true +image: python:3.6.2 pipelines: branches: master: From 5234d91d4b13870f9195150242517d0afc3cee46 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Sat, 5 Aug 2017 12:28:40 -0700 Subject: [PATCH 5/9] testing a change to the pipeline --- bitbucket-pipelines.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index 2a4ed12b..3a4fa233 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -11,6 +11,12 @@ options: image: python:3.6.2 pipelines: + default: + - step: + script: + - echo "Making sure the python actually runs" + - pip install docker discord.py pybooru requests + - python dragon-bot.py test branches: master: - step: @@ -25,9 +31,6 @@ pipelines: feature/*: - step: script: - - echo "Making sure the python actually runs" - - pip install docker discord.py pybooru requests - - python dragon-bot.py test # Only build iamges, dont push when we're on a feature branch - export IMAGE_NAME=ldooks/dragon-bot:latest # build the Docker image (this will use the Dockerfile in the root of the repo) From ec0a52bd8d3a1a71457f96d723c6afa715d161a9 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Sat, 5 Aug 2017 12:33:55 -0700 Subject: [PATCH 6/9] testing if itll build on a branch --- bitbucket-pipelines.yml | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index 3a4fa233..6ef8601b 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -17,21 +17,14 @@ pipelines: - echo "Making sure the python actually runs" - pip install docker discord.py pybooru requests - python dragon-bot.py test + - export IMAGE_NAME=ldooks/dragon-bot:latest + # build the Docker image (this will use the Dockerfile in the root of the repo) + - docker build -t $IMAGE_NAME . branches: master: - step: script: - - export IMAGE_NAME=ldooks/dragon-bot:latest - # build the Docker image (this will use the Dockerfile in the root of the repo) - - docker build -t $IMAGE_NAME . # authenticate with the Docker Hub registry - docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD # push the new Docker image to the Docker registry - - docker push $IMAGE_NAME - feature/*: - - step: - script: - # Only build iamges, dont push when we're on a feature branch - - export IMAGE_NAME=ldooks/dragon-bot:latest - # build the Docker image (this will use the Dockerfile in the root of the repo) - - docker build -t $IMAGE_NAME . \ No newline at end of file + - docker push $IMAGE_NAME \ No newline at end of file From a1ab2d731ee6d3a7819ef581ca21c450b9c06aee Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Sat, 5 Aug 2017 12:35:01 -0700 Subject: [PATCH 7/9] Adding the export for image name back to the master section of the build --- bitbucket-pipelines.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index 6ef8601b..6a55fd29 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -24,6 +24,7 @@ pipelines: master: - step: script: + - export IMAGE_NAME=ldooks/dragon-bot:latest # authenticate with the Docker Hub registry - docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD # push the new Docker image to the Docker registry From c0701e91f4fea6ea79a3442d7d1f9f17ac681ded Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Sat, 5 Aug 2017 12:36:12 -0700 Subject: [PATCH 8/9] indent --- bitbucket-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index 6a55fd29..d11a3be8 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -24,7 +24,7 @@ pipelines: master: - step: script: - - export IMAGE_NAME=ldooks/dragon-bot:latest + - export IMAGE_NAME=ldooks/dragon-bot:latest # authenticate with the Docker Hub registry - docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD # push the new Docker image to the Docker registry From e4109dffac89a5e1b90f1868de1ee4826a1dfd41 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Tue, 8 Aug 2017 12:29:32 -0700 Subject: [PATCH 9/9] Adding definition function and doing some code cleanup --- bitbucket-pipelines.yml | 2 +- dragon-bot.py | 62 +++++++++++++++++++++-------------------- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index d11a3be8..46e4b564 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -15,7 +15,7 @@ pipelines: - step: script: - echo "Making sure the python actually runs" - - pip install docker discord.py pybooru requests + - pip install docker discord.py pybooru requests pylint - python dragon-bot.py test - export IMAGE_NAME=ldooks/dragon-bot:latest # build the Docker image (this will use the Dockerfile in the root of the repo) diff --git a/dragon-bot.py b/dragon-bot.py index f76836b5..bac6dc40 100644 --- a/dragon-bot.py +++ b/dragon-bot.py @@ -1,21 +1,13 @@ -from pybooru import Danbooru -import asyncio +import random +import sys +import requests + import discord import docker -import json -import logging -import os -import random -import requests -import sys -import time - +from pybooru import Danbooru # Client object client = discord.Client() -botToken = "MzM5NDQ2NTgwMTU3MzQ5ODg4.DFkGYg.z-XD17nFP4rtBq-YsNbOJHuBWfQ" # get from the bot page. must be a bot, not a discord app -discord_server_id = '97456282729996288' - @client.event async def on_ready(): print("Dragon bot up and ready to roll.\n") @@ -114,7 +106,7 @@ async def on_message(message): ] response = requests.get( "https://reddit.com/r/{}.json?limit=500".format(random.choice(boards)), - headers = {'User-agent': 'discord dragon-bot'} + headers = {'User-agent':'discord dragon-bot'} ).json()['data']['children'] image_urls = list(filter(lambda x: x['data']['domain'] in domains, response)) @@ -125,9 +117,20 @@ async def on_message(message): if client.user.mentioned_in(message): print('fuck u') - if(message.content.startswith('!help')): + if message.content.startswith('!define'): + word = message.content.split()[1:] + try: + definition = requests.get( + "https://api.urbandictionary.com/v0/define?term={}".format('%20'.join(word)) + ).json()['list'][0]['definition'] + except IndexError: + definition = 'No definition found' + await client.send_message(message.channel, "`{}`\n```{}```".format(' '.join(word), definition)) + + if message.content.startswith('!help'): supported_methods = { 'decide': 'Dragon-bot will help make the tough decisions for you\n!decide option 1 or option 2.\n\nIf only one option, it will give you a yes or no', + 'deine': 'Returns a definiton of a word from urban dictionary\n\nUsage: !define loli', 'docker': 'Two supported actions: logs and restart\n\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 minecraft server if something is fucky', 'excuse': 'Generates a random excuse you can give your boss', 'help': 'Prints out a list of everything dragon-bot can do', @@ -141,28 +144,25 @@ async def on_message(message): if method not in supported_methods.keys(): await client.send_message(message.channel, "I cant help you with that") return - await client.send_message(message.channel,"```{}```".format(supported_methods[method])) + await client.send_message(message.channel, "```{}```".format(supported_methods[method])) else: await client.send_message(message.channel, "I currently have {} methods,\n\n```{}```\n\nYou can get information about a specific method by typing !help ".format(len(supported_methods), ', '.join(supported_methods.keys()))) - if('autis' in message.content): + if 'autis' in message.content or message.content.startswith('!triggered'): await client.send_message(message.channel, 'https://i.imgur.com/g6yOJjp.gif') - if(message.content.startswith('!triggered')): - await client.send_message(message.channel, 'https://i.imgur.com/g6yOJjp.gif') - - if(message.content.startswith('!excuse')): + if message.content.startswith('!excuse'): excuses = requests.get( 'https://gist.githubusercontent.com/AndrewBrinker/6763cdd5d79d6e3eaa3f/raw/624b946ebcca71ac76b74afa5ea41280540c1b97/excuses.txt' ).text.split("\n") await client.send_message(message.channel, random.choice(excuses)) - if(message.content.startswith('!purge')): - deleted = await client.purge_from(message.channel, limit=20, check=is_me) + if message.content.startswith('!purge'): + await client.purge_from(message.channel, limit=20, check=is_me) # await client.send_message(message.channel, 'Deleted {} message(s)'.format(len(deleted))) - if(message.content.startswith('!decide')): + if message.content.startswith('!decide'): choices = message.content.replace('!decide', '').lstrip().split(' or ') if len(choices) > 1: ####### debug ########### @@ -172,13 +172,13 @@ async def on_message(message): else: await client.send_message(message.channel, "{} {}".format(message.author.mention, random.choice(['yes', 'no']))) - if(message.content.startswith('!cleanup')) and '144986109804412928' == message.author.id: + if message.content.startswith('!cleanup') and message.author.id == '144986109804412928': def is_bot(m): return m.author == client.user - deleted = await client.purge_from(message.channel, limit=100, check=is_bot) + await client.purge_from(message.channel, limit=100, check=is_bot) # await client.send_message(message.channel, 'Deleted {} message(s)'.format(len(deleted))) - if(message.content.startswith('!wallpaper')): + if message.content.startswith('!wallpaper'): url = 'https://source.unsplash.com/3840x2160/' if len(message.content.split()) > 1: keyword = message.content.split()[1] @@ -198,7 +198,7 @@ async def on_message(message): ###### | | ###### ###### +-------------------+ ###### ################################### - if(message.content.startswith('!lewd')): + if message.content.startswith('!lewd'): if 'nsfw' in message.channel.name: if random.randint(0, 100) % 2 == 0: await client.send_message(message.channel, "Heres a random image from reddit\n{}".format(get_from_reddit())) @@ -214,7 +214,7 @@ async def on_message(message): ###### | | ###### ###### +-------------------+ ###### ################################### - if(message.content.startswith('!docker') and (message.author != client.user)): + if message.content.startswith('!docker') and (message.author != client.user): # Check permissions roles = [] allowed_roles = ['MOD', 'Greasemonkey', 'Adminimodistrator'] @@ -260,4 +260,6 @@ async def on_message(message): if len(sys.argv) > 1: print("If you're seeing this, the python compiled") sys.exit() -client.run(botToken) \ No newline at end of file + +token = "MzM5NDQ2NTgwMTU3MzQ5ODg4.DFkGYg.z-XD17nFP4rtBq-YsNbOJHuBWfQ" # get from the bot page. must be a bot, not a discord app +client.run(token)