Skip to content

Commit 0a744f9

Browse files
committed
Added p1p1 functionality v1
1 parent 4194b67 commit 0a744f9

File tree

6 files changed

+143
-0
lines changed

6 files changed

+143
-0
lines changed

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
__pycache__/
2+
pip-selfcheck.json
3+
bin
4+
include
5+
lib
6+
lib64
7+
pyvenv.cfg
8+
share

cubebot.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from discord.ext import commands
2+
import asyncio
3+
import os
4+
import logging
5+
import sys
6+
from functions import cubebot
7+
8+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
9+
logger = logging.getLogger('cubebot.main')
10+
11+
#EnvironmentLoaders
12+
botToken = os.environ['CUBEBOT']
13+
14+
#Initializing bot
15+
description = '''CubeBot Commands'''
16+
bot = commands.Bot(command_prefix='$', description=description)
17+
18+
@bot.event
19+
async def on_ready():
20+
logger.info('Logged in as')
21+
logger.info(bot.user.name)
22+
logger.info(bot.user.id)
23+
logger.info('------')
24+
25+
26+
bot.load_extension("functions.cubebot")
27+
28+
bot.run(botToken)

functions/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__all__ = ["cubebot", "cubetutor"]

functions/cubebot.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from functions import cubetutor
2+
import logging
3+
import discord
4+
import sys
5+
import asyncio
6+
import random
7+
import requests
8+
from discord.ext import commands
9+
10+
#shahrazad token ed98810941cf53fa9806f9aa9299c2 - This is only available internally and only executes the shahrazad test pipeline
11+
logger = logging.getLogger('cubebot.cubebot')
12+
13+
logger.info("cubebot cog loaded")
14+
15+
class Application:
16+
def __init__(self, bot):
17+
self.bot = bot
18+
19+
@commands.command(pass_context=True)
20+
async def p1p1(self, ctx):
21+
"""Generate a P1P1 image given a cubetutor cube ID"""
22+
command = ctx.message.content.split()
23+
if len(command) > 1:
24+
try:
25+
cubeId = int(command[1])
26+
logger.info(str(ctx.message.author) + " pulled a pack")
27+
await ctx.channel.send("Looking up pack...")
28+
cubeId = command[1]
29+
packLoader = self.bot.loop.create_task(cubetutor.CubeTutorPackChrome(cubeId, ctx))
30+
except:
31+
await ctx.channel.send("Please give me a real ID at least. ")
32+
if len(command) is 1:
33+
await ctx.channel.send("I need an ID.")
34+
35+
def setup(bot):
36+
bot.add_cog(Application(bot))

functions/cubetutor.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from selenium import webdriver
2+
from selenium.webdriver.common.keys import Keys
3+
import os
4+
import discord
5+
6+
selenium = os.environ["HUB"]
7+
8+
async def CubeTutorPackChrome(cubeId, ctx):
9+
try:
10+
cubeId = int(cubeId)
11+
except Exception as e:
12+
print(e)
13+
return False
14+
endpoint = "http://www.cubetutor.com/samplepack/"+str(cubeId)
15+
driver = webdriver.Remote(
16+
command_executor = selenium + "wd/hub",
17+
desired_capabilities = {"browserName": "chrome", "javascriptEnabled": True}
18+
)
19+
try:
20+
driver.get(endpoint)
21+
except Exception as e:
22+
print(e)
23+
await tearDownClass(driver)
24+
25+
try:
26+
gtfo = webdriver.common.action_chains.ActionChains(driver)
27+
footer = driver.find_element_by_id('footer')
28+
gtfo.move_to_element(footer)
29+
element = driver.find_element_by_id('main')
30+
elementPng = element.screenshot_as_png
31+
32+
await tearDownClass(driver, png=elementPng, ctx=ctx)
33+
except Exception as e:
34+
print(e)
35+
await tearDownClass(driver)
36+
37+
async def tearDownClass(driver, png=None, ctx=None):
38+
driver.quit()
39+
if png:
40+
packImage = discord.File(png, "crack.png")
41+
await ctx.channel.send("You're pack, friend. ", file=packImage)
42+
if not png:
43+
await ctx.channel.send("Sorry, your pack couldn't be found. Please try again later.")
44+
45+
if __name__ == "__main__":
46+
setUpClass()
47+

requirements.txt

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
aiohttp==3.4.4
2+
git+https://github.com/Rapptz/discord.py@rewrite#egg=discord.py[voice]
3+
async-timeout==3.0.1
4+
attrs==18.2.0
5+
certifi==2018.11.29
6+
cffi==1.11.5
7+
chardet==3.0.4
8+
docutils==0.14
9+
idna==2.8
10+
idna-ssl==1.1.0
11+
jmespath==0.9.3
12+
multidict==4.5.2
13+
pycparser==2.19
14+
PyNaCl==1.2.1
15+
python-dateutil==2.7.5
16+
python-gitlab==1.7.0
17+
requests==2.21.0
18+
six==1.12.0
19+
urllib3==1.24.1
20+
websockets==6.0
21+
yarl==1.1.1
22+
selenium==3.141.0
23+

0 commit comments

Comments
 (0)