Merged in feature/test_script (pull request #3)

Feature/test script
This commit is contained in:
Luke Robles 2017-08-08 19:33:58 +00:00
commit bafbd21183
2 changed files with 47 additions and 39 deletions

View File

@ -9,22 +9,23 @@
options:
docker: true
image: python:3.6.2
pipelines:
default:
- step:
script:
- echo "Making sure the python actually runs"
- 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)
- 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 .
- docker push $IMAGE_NAME

View File

@ -1,20 +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 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")
@ -113,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))
@ -124,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',
@ -140,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 <method>".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 ###########
@ -171,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]
@ -197,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()))
@ -213,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']
@ -255,4 +256,10 @@ async def on_message(message):
else:
await client.send_message(message.channel, "There arent {} lines of output yet".format(num_lines))
client.run(botToken)
# 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()
token = "MzM5NDQ2NTgwMTU3MzQ5ODg4.DFkGYg.z-XD17nFP4rtBq-YsNbOJHuBWfQ" # get from the bot page. must be a bot, not a discord app
client.run(token)