269 lines
10 KiB
Python
269 lines
10 KiB
Python
import random
|
|
import sys
|
|
import requests
|
|
|
|
import help_methods
|
|
import discord
|
|
import docker
|
|
from pybooru import Danbooru
|
|
from termcolor import colored
|
|
|
|
# Client object
|
|
client = discord.Client()
|
|
|
|
@client.event
|
|
async def on_ready():
|
|
print("Dragon bot up and ready to roll.\n")
|
|
|
|
|
|
@client.event
|
|
async def on_message(message):
|
|
def is_me(m):
|
|
"""
|
|
is_me(m)
|
|
|
|
takes a message as an argument and checks that the author of the message
|
|
is the same as the person who initiated the command
|
|
"""
|
|
return m.author == message.author
|
|
def get_from_danbooru():
|
|
"""
|
|
get_from_danbooru()
|
|
|
|
returns a URL to an image on danbooru that matches a random tag
|
|
defined in the tag_list list
|
|
"""
|
|
booru = Danbooru('danbooru')
|
|
tag_list = [
|
|
'1girl',
|
|
'2girls',
|
|
'ass_visible_through_thighs',
|
|
'bare_legs'
|
|
'bikini',
|
|
'black_bikini',
|
|
'black_panties',
|
|
'blue_eyes',
|
|
'bra_pull',
|
|
'bra',
|
|
'breasts',
|
|
'cameltoe',
|
|
'clevage',
|
|
'condom_in_mouth',
|
|
'condom',
|
|
'from_below',
|
|
'gloves',
|
|
'highleg_bikini',
|
|
'highleg',
|
|
'highres',
|
|
'horns',
|
|
'large_breasts',
|
|
'leash',
|
|
'medium_breasts'
|
|
'miniskirt',
|
|
'nier_automata',
|
|
'nier',
|
|
'nipples',
|
|
'partially_visible_vulva',
|
|
'pencil_skirt',
|
|
'pussy_juice',
|
|
'pussy',
|
|
'skirt',
|
|
'small_breasts',
|
|
'thong_bikini',
|
|
'topless',
|
|
'wet_clothes',
|
|
'wet_panties',
|
|
'wet',
|
|
]
|
|
|
|
tag = random.choice(tag_list)
|
|
return "https://danbooru.donmai.us{}".format(
|
|
random.choice(
|
|
booru.post_list(
|
|
limit=500,
|
|
tags=tag,
|
|
random=True,
|
|
)
|
|
)['large_file_url'])
|
|
|
|
def get_from_reddit():
|
|
"""
|
|
get_from_reddit()
|
|
|
|
returns a URL to an image on reddit from a random board in the boards list
|
|
as long as it is hosted on one of the domains in the domains list
|
|
"""
|
|
boards = [
|
|
'2Booty',
|
|
'bakunyuu_hentai',
|
|
'ecchi',
|
|
'hentai',
|
|
'rule34',
|
|
'WesternHentai',
|
|
]
|
|
domains = [
|
|
'my.mixtape.moe',
|
|
'i.imgur.com',
|
|
'i.redd.it',
|
|
'imgur.com',
|
|
]
|
|
response = requests.get(
|
|
"https://reddit.com/r/{}.json?limit=500".format(random.choice(boards)),
|
|
headers = {'User-agent':'discord dragon-bot'}
|
|
).json()['data']['children']
|
|
|
|
image_urls = list(filter(lambda x: x['data']['domain'] in domains, response))
|
|
return random.choice(image_urls)['data']['url'].replace('http://', 'https://')
|
|
|
|
##### Looks like discord supports mentioning the bot.
|
|
#### Need to think of something to do here
|
|
if client.user.mentioned_in(message):
|
|
print('fuck u')
|
|
|
|
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'):
|
|
if len(message.content.split()) > 1:
|
|
method = message.content.split()[1]
|
|
try:
|
|
explanation = help_methods.return_help_message(method)
|
|
except KeyError:
|
|
await client.send_message(
|
|
message.channel,
|
|
"I can't help you with that"
|
|
)
|
|
return
|
|
await client.send_message(
|
|
message.channel,
|
|
"```{}```".format(explanation)
|
|
)
|
|
else:
|
|
await client.send_message(
|
|
message.channel,
|
|
help_methods.return_help_message('show_all')
|
|
)
|
|
|
|
|
|
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('!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'):
|
|
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'):
|
|
choices = message.content.replace('!decide', '').lstrip().split(' or ')
|
|
if len(choices) > 1:
|
|
####### debug ###########
|
|
# await client.send_message(message.channel, "I see {} choices, {}".format(len(choices), 'and '.join(choices)))
|
|
print("{} has initated a decide between {}".format(message.author, choices))
|
|
await client.send_message(message.channel, "{} {}".format(message.author.mention, random.choice(choices)))
|
|
else:
|
|
await client.send_message(message.channel, "{} {}".format(message.author.mention, random.choice(['yes', 'no'])))
|
|
|
|
if message.content.startswith('!cleanup') and message.author.id == '144986109804412928':
|
|
def is_bot(m):
|
|
return m.author == client.user
|
|
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'):
|
|
url = 'https://source.unsplash.com/3840x2160/'
|
|
if len(message.content.split()) > 1:
|
|
keyword = message.content.split()[1]
|
|
url = "?".join((url, keyword))
|
|
|
|
if 'waifu' in keyword:
|
|
url = 'https://media0.giphy.com/media/C79RKZ7nOcK8U/giphy.gif'
|
|
|
|
results = requests.get(url).url
|
|
await client.send_message(message.channel, results)
|
|
|
|
|
|
###################################
|
|
###### +-------------------+ ######
|
|
###### | | ######
|
|
###### | Lewd Functions | ######
|
|
###### | | ######
|
|
###### +-------------------+ ######
|
|
###################################
|
|
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()))
|
|
else:
|
|
await client.send_message(message.channel, "Heres a random image from danbooru\n{}".format(get_from_danbooru()))
|
|
else:
|
|
await client.send_message(message.channel, 'You can only use this command in NSFW channels')
|
|
|
|
###################################
|
|
###### +-------------------+ ######
|
|
###### | | ######
|
|
###### | Docker Functions | ######
|
|
###### | | ######
|
|
###### +-------------------+ ######
|
|
###################################
|
|
if message.content.startswith('!docker') and (message.author != client.user):
|
|
# Check permissions
|
|
roles = []
|
|
allowed_roles = ['MOD', 'Greasemonkey', 'Adminimodistrator']
|
|
for role in message.author.roles:
|
|
roles.append(role.name)
|
|
docker_privleges = not set(roles).isdisjoint(allowed_roles)
|
|
if not docker_privleges:
|
|
await client.send_message(message.channel, "Sorry {}, You dont have permission to run docker commands".format(message.author.mention))
|
|
return
|
|
|
|
if len(message.content.split()) == 1:
|
|
actions = ['restart', 'status', 'logs']
|
|
await client.send_message(message.channel, "\nSupported actions:\n{}".format(", ".join(actions)))
|
|
else:
|
|
docker_client = docker.from_env()
|
|
minecraft_container = docker_client.containers.get('skyfactory')
|
|
# Figure out what action they want to take
|
|
action = message.content.split()[1]
|
|
if action == 'restart':
|
|
await client.send_message(message.channel, "{}, Are you sure you want to restart the container? [!yes/!no]".format(message.author.mention))
|
|
confirm_restart = await client.wait_for_message(author=message.author, channel=message.channel, content='!yes')
|
|
|
|
if confirm_restart:
|
|
await client.send_message(message.channel, "Sending restart action to {} container".format(minecraft_container.name))
|
|
minecraft_container.restart()
|
|
|
|
if action == 'status':
|
|
await client.send_message(message.channel, "{} is {}".format(minecraft_container.name, minecraft_container.status))
|
|
if action == 'logs':
|
|
if len(message.content.split()) == 3:
|
|
num_lines = int(message.content.split()[2])
|
|
else:
|
|
num_lines = 10
|
|
|
|
log_stream = minecraft_container.logs(tail=num_lines).decode('utf-8')
|
|
if len(log_stream) >= num_lines:
|
|
await client.send_message(message.channel, "Pulling last {} lines from {} container".format(num_lines, minecraft_container.name))
|
|
await client.send_message(message.channel, "```{}```".format(minecraft_container.logs(tail=num_lines).decode('utf-8')))
|
|
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(colored("If you're seeing this, the python compiled", 'green'))
|
|
sys.exit()
|
|
|
|
token = "MzM5NDQ2NTgwMTU3MzQ5ODg4.DFkGYg.z-XD17nFP4rtBq-YsNbOJHuBWfQ" # get from the bot page. must be a bot, not a discord app
|
|
client.run(token)
|