Skip to content

Commit

Permalink
changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
ririnto committed Feb 6, 2020
1 parent 5b74dca commit d096fed
Show file tree
Hide file tree
Showing 9 changed files with 284 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .idea/-python3-KMS_Discord_Bot.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 20 additions & 4 deletions KMS_Bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from module.additional_options import *
from module.defense_percentage_ignore import *
from module.level import *
from module.information import *
from module.information1 import *
from module.information2 import *
from module.hangang import *
from module.logging import *
from module.gambling import *
Expand Down Expand Up @@ -58,14 +59,29 @@ async def on_message(message):
output = level_main(msg)
await message.channel.send(embed=output)

if message.content.startswith("#정보") \
or message.content.startswith("#무릉") \
elif message.content.startswith("#정보"):
status = information_reader(message)
msg = message.content.split(" ")
if status is 1:
output = information_none()
await message.channel.send(embed=output)
elif status is 2:
path = information1(msg)
await message.channel.send(file=discord.File(path, filename=msg[1] + '.png'))
output = discord.Embed()
output.set_footer(text="https://maple.gg/u/%s" % msg[1])
await message.channel.send(embed=output)
else:
output = information_help()
await message.channel.send(embed=output)

elif message.content.startswith("#무릉") \
or message.content.startswith("#시드") \
or message.content.startswith("#더시드") \
or message.content.startswith("#유니온") \
or message.content.startswith("#업적"):
msg = message.content.split(" ")
output = information_main(msg)
output = information2_main(msg)
await message.channel.send(embed=output)

if message.content.startswith("#한강"):
Expand Down
81 changes: 81 additions & 0 deletions module/information1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import discord
import requests
from bs4 import BeautifulSoup
import imgkit
import random


def information1(msg):

f = open('./module/css/style.css', "r", encoding="utf8")
css_data = f.read()
f.close()

data = '<style>\n%s\n</style>\n' % css_data
result = [[]]

url = "https://maple.gg/u/%s" % (msg[1])
url = requests.get(url)
html = url.content
soup = BeautifulSoup(html, 'html.parser')
finder = soup.select("div#exampleModal > div > div.character-card")

for i in range(0, 3, 2):
p_tag = finder[0].select('img')[i]
del p_tag['crossorigin']

result.append(finder[0])
data += '<body>\n'
data += '%s' % result[1]
data += '\n</body>'
f = open('/var/www/html/information/temp.html', "w", encoding="UTF-8")
f.write(data)
f.close()
options = {
'format': 'png',
'encoding': "UTF-8",
"xvfb": "",
'quiet': '',
'crop-w': '303',
'crop-h': '442',
'crop-x': '360',
'crop-y': '8'
}
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_footer(text="https://maple.gg/u/%s" % msg[1])
path = '/var/www/html/information/temp.png'
return 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
147 changes: 147 additions & 0 deletions module/information2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import discord
import requests
from bs4 import BeautifulSoup
import imgkit
import random


def achievement(msg, data, i): # 업적
temp = [[], [], [], []]
result = [[], [], [], []]
temp[0].append(data[i].select('div')[2].text.strip()) # 등급
temp[1].append(data[i].select('span')[0].text.strip()) # 점수
temp[2].append(
data[i].select('span')[1].text.replace("\n", "").replace(" ", "").replace("/", " / ").strip()) # 레벨 / 직업
temp[3].append(data[i].select('span')[4].text.strip()) # 기준일

rank = temp[0]

if "브론즈" in rank:
rank = "bronze"
elif "실버" in rank:
rank = "silver"
elif "골드" in rank:
rank = "gold"
elif "플래티넘" in rank:
rank = "platinum"
elif "다이아몬드" in rank:
rank = "diamond"
elif "마스터" in rank:
rank = "master"

for k in range(0, 4, 1):
result[k] = temp[k][0]
output = discord.Embed(title=msg[1],
description='%s\n%s\n%s\n%s' % (result[0], result[1], result[2], result[3]),
color=0x0000ff)
output.set_thumbnail(
url="http://ec2-52-79-205-251.ap-northeast-2.compute.amazonaws.com/image/achievement/%s.png" % rank)
output.set_footer(text="https://maple.gg/u/%s" % msg[1])

return output


def union(msg, data, i): # 유니온
temp = [[], [], [], []]
result = [[], [], [], []]
temp[0].append(data[i].select('div')[2].text.strip()) # 등급
temp[1].append(data[i].select('span')[0].text.strip()) # 레벨
temp[2].append(data[i].select('span')[1].text.lstrip('전투력 ').replace(",", "").strip()) # 전투력
temp[3].append(data[i].select('span')[4].text.strip()) # 기준일

num = int(temp[2][0]) * 0.000000864
num = int(num)
rank = temp[0][0]

if "그랜드" in rank:
rank1 = "grandmaster"
rank2 = rank.lstrip('그랜드마스터 ')
elif "마스터" in rank:
rank1 = "master"
rank2 = rank.lstrip('마스터 ')
elif "베테랑" in rank:
rank1 = "veteran"
rank2 = rank.lstrip('베테랑 ')
elif "노비스" in rank:
rank1 = "novice"
rank2 = rank.lstrip('노비스 ')

for k in range(0, 4, 1):
result[k] = temp[k][0]
output = discord.Embed(title=msg[1],
description='%s\n등급 : %s\n전투력 : %s\n%s\n일일 코인 획득량 : %d' % (
result[1], result[0], format(int(result[2]), ','), result[3], num),
color=0x0000ff)
output.set_thumbnail(
url="http://ec2-52-79-205-251.ap-northeast-2.compute.amazonaws.com/image/union/%s/%s.png" % (rank1, rank2))
output.set_footer(text="https://maple.gg/u/%s" % msg[1])

return output


def information2(msg, data, i): # 무릉, 더시드
temp = [[], [], [], []]
result = [[], [], [], []]
temp[0].append(data[i].select('h1')[0].text.replace(" ", "").replace("\n", " ")) # 최고층
temp[1].append(data[i].select('small')[0].text.strip()) # 시간
temp[2].append(
data[i].select('span')[1 - i].text.replace("\n", "").replace(" ", "").replace("/", " / ").strip()) # 레벨 / 직업
temp[3].append(data[i].select('span')[4 - i].text.lstrip('기준일: ').strip()) # 날짜

for k in range(0, 4, 1):
result[k] = temp[k][0]
output = discord.Embed(title=msg[1],
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_main(msg):
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 == '검색결과가 없습니다.':
output = discord.Embed(title="Warning!!!", description='검색결과가 없습니다.', color=0xff0000)
output.set_footer(text="캐릭터 이름을 다시 한 번 확인해주세요. 대소문자를 구분하며, 메이플지지의 정보를 기반으로 합니다.")
else:
if '정보' in msg[0]:
output = information1(msg)
else:
data = soup.select("div.bg-light > section > div > div")
if '무릉' in msg[0]:
if data[0].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, 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)
elif '유니온' in msg[0]:
if data[2].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 = union(msg, data, 2)
elif '업적' in msg[0]:
if data[3].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 = achievement(msg, data, 3)
else:
output = discord.Embed(title="#정보",
description='#정보 (닉네임)을 입력하여 프로필을 확인할 수 있습니다.\n상세 정보 확인을 위해서는 #정보 대신 #무릉, #시드, #유니온, #업적 을 입력해주세요.',
color=0x00ff00)
output.set_footer(text="예) #정보 RIRINTO, #무릉 RIRINTO")

return output

0 comments on commit d096fed

Please sign in to comment.