Skip to content

Commit

Permalink
최적화
Browse files Browse the repository at this point in the history
  • Loading branch information
ririnto committed May 15, 2020
1 parent 1dc8baf commit c1d1f5b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 414 deletions.
22 changes: 8 additions & 14 deletions KMS_Bot.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
from discord.ext import commands

from module.help import *
from module.simbol import *
from module.additional_options import *
from module.defense_percentage_ignore import *
from module.level import *
from module.information1 import *
from module.informaiton2 import *
from module.information import *
from module.hangang import *
from module.logging import *
from module.gambling import *
from module.homepage import *
from module.linknunion import *
from module.BodyAndMindTrainingCenter import *


PREFIX = '#'

extension_list = ['module.help', 'module.simbol',
Expand All @@ -23,16 +20,14 @@
'module.linknunion',
'module.BodyAndMindTrainingCenter']

todolist = ['module.gambling', 'module.information', 'module.homepage']
todolist=['module.gambling','module.information','module.homepage']

bot = commands.AutoShardedBot(command_prefix=PREFIX)
bot.remove_command('help')

for extension in extension_list:
bot.load_extension(extension)


# client = discord.Client()
#client = discord.Client()


@bot.event
Expand All @@ -53,17 +48,17 @@ async def on_message(message):
if message.content.startswith("#"):
logging_main(message)

elif message.content.startswith("#정보") \
if message.content.startswith("#정보") \
or message.content.startswith("#무릉") \
or message.content.startswith("#시드") \
or message.content.startswith("#더시드") \
or message.content.startswith("#유니온") \
or message.content.startswith("#업적"):
msg = message.content.split(" ")
(output1, output2) = information_main(msg)
if not output2 < 1:
await message.channel.send(file=discord.File(output2, filename=msg[1] + '.png'))
await message.channel.send(embed=output1)
outputs = information_main(msg)
if len(outputs) is 2:
await message.channel.send(file=discord.File(outputs[1], filename=msg[1] + '.png'))
await message.channel.send(embed=outputs[0])

if message.content.startswith("#골드") \
or message.content.startswith("#애플") \
Expand Down Expand Up @@ -91,7 +86,6 @@ async def on_message(message):

try:
import keys

key = keys.key
except:
key = ''
Expand Down
74 changes: 49 additions & 25 deletions module/information.py → information.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
from bs4 import BeautifulSoup
import imgkit
import random
from module.hidden import *

server_url = "ec2-52-79-237-159.ap-northeast-2.compute.amazonaws.com"
server_url = server_url()


def achievement(msg, data, i): # 업적
Expand Down Expand Up @@ -43,7 +44,7 @@ def achievement(msg, data, i): # 업적
url="http://" + server_url + "/image/achievement/%s.png" % rank)
output.set_footer(text="https://maple.gg/u/%s" % msg[1])

return output
return output,


def union(msg, data, i): # 유니온
Expand Down Expand Up @@ -81,10 +82,10 @@ def union(msg, data, i): # 유니온
url="http://" + server_url + "/image/union/%s/%s.png" % (rank1, rank2))
output.set_footer(text="https://maple.gg/u/%s" % msg[1])

return output
return output,


def information3(msg, data, i): # 무릉, 더시드
def information2(msg, data, i): # 무릉, 더시드
temp = [[], [], [], []]
result = [[], [], [], []]
temp[0].append(data[i].select('h1')[0].text.replace(" ", "").replace("\n", " ")) # 최고층
Expand All @@ -99,21 +100,15 @@ def information3(msg, data, i): # 무릉, 더시드
description='%s\n기록 : %s\n시간 : %s\n날짜 : %s' % (result[2], result[0], result[1], result[3]),
color=0x0000ff)
output.set_footer(text="https://maple.gg/u/%s" % msg[1])
return output


def information2():
f = open('./module/css/style.css', "r", encoding="utf8")
css_data = f.read()
f.close()
return css_data
return output,


def information1(msg):
css_data = information2()
with open('./module/css/style.css', "r", encoding="utf8") as data:
css_data = data.read()

data = '<style>\n%s\n</style>\n' % css_data
result = [[]]
rannum = random.randrange(1, 10000000)

url = "https://maple.gg/u/%s" % (msg[1])
url = requests.get(url)
Expand All @@ -129,7 +124,7 @@ def information1(msg):
data += '<body>\n'
data += '%s' % result[1]
data += '\n</body>'
f = open('/var/www/html/information/%s.html' % msg[1], "w", encoding="UTF-8")
f = open('/var/www/html/information/temp.html', "w", encoding="UTF-8")
f.write(data)
f.close()
options = {
Expand All @@ -142,15 +137,42 @@ def information1(msg):
'crop-x': '360',
'crop-y': '8'
}
with open('/var/www/html/information/%s.html' % msg[1], 'r', encoding="UTF-8") as f:
imgkit.from_file(f, '/var/www/html/information/%s%d.png' % (msg[1], rannum), options=options)
with open('/var/www/html/information/temp.html', 'r', encoding="UTF-8") as f:
imgkit.from_file(f, '/var/www/html/information/temp.png', options=options)

output = discord.Embed()
output.set_image(
url="http://" + server_url + "/information/%s%d.png" % (msg[1], rannum))
output.set_footer(text="https://maple.gg/u/%s" % msg[1])

return output
path = '/var/www/html/information/temp.png'
return output, path


#
# def information_help(msg):
# output = discord.Embed(title="#정보",
# description='#정보 (닉네임)을 입력하여 프로필을 확인할 수 있습니다.\n상세 정보 확인을 위해서는 #정보 대신 #무릉, #시드, #유니온, #업적 을 입력해주세요.',
# color=0x00ff00)
# output.set_footer(text="예) #정보 RIRINTO, #무릉 RIRINTO")
# return output


# def information_none():
# output = discord.Embed(title="Warning!!!", description='검색결과가 없습니다.', color=0xff0000)
# output.set_footer(text="캐릭터 이름을 다시 한 번 확인해주세요. 대소문자를 구분하며, 메이플지지의 정보를 기반으로 합니다.")
# return output

# def information_reader(message):
# msg = message.content.split(" ")
# if len(msg) is 2:
# url = 'https://maple.gg/u/%s' % msg[1]
# url = requests.get(url)
# html = url.content
# soup = BeautifulSoup(html, 'html.parser')
# finder = soup.select(".bg-light")
# if finder[0].select('h3')[0].text == '검색결과가 없습니다.':
# return 1
# return 2
# else:
# return 3


def information_main(msg):
Expand All @@ -173,13 +195,13 @@ def information_main(msg):
output = discord.Embed(title="Warning!!!", description='기록이 없습니다.', color=0xff0000)
output.set_footer(text="https://maple.gg/u/%s" % msg[1])
else:
output = information3(msg, data, 0)
output = information2(msg, data, 0)
elif '시드' in msg[0]:
if data[1].select('div')[2].text == '기록이 없습니다.':
output = discord.Embed(title="Warning!!!", description='기록이 없습니다.', color=0xff0000)
output.set_footer(text="https://maple.gg/u/%s" % msg[1])
else:
output = information3(msg, data, 1)
output = information2(msg, data, 1)
elif '유니온' in msg[0]:
if data[2].select('div')[2].text == '기록이 없습니다.':
output = discord.Embed(title="Warning!!!", description='기록이 없습니다.', color=0xff0000)
Expand All @@ -197,5 +219,7 @@ def information_main(msg):
description='#정보 (닉네임)을 입력하여 프로필을 확인할 수 있습니다.\n상세 정보 확인을 위해서는 #정보 대신 #무릉, #시드, #유니온, #업적 을 입력해주세요.',
color=0x00ff00)
output.set_footer(text="예) #정보 RIRINTO, #무릉 RIRINTO")

return output
if type(output) is tuple:
return output
else:
return output,
Loading

0 comments on commit c1d1f5b

Please sign in to comment.