From d096fedf943bcfe5ecb5495b34dc6554147b7d21 Mon Sep 17 00:00:00 2001 From: RIRINTO <54238243+RIRINTO@users.noreply.github.com> Date: Fri, 7 Feb 2020 01:05:26 +0900 Subject: [PATCH] changed. --- .idea/-python3-KMS_Discord_Bot.iml | 8 + .idea/.gitignore | 2 + .../inspectionProfiles/profiles_settings.xml | 6 + .idea/misc.xml | 6 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + KMS_Bot.py | 24 ++- module/information1.py | 81 ++++++++++ module/information2.py | 147 ++++++++++++++++++ 9 files changed, 284 insertions(+), 4 deletions(-) create mode 100644 .idea/-python3-KMS_Discord_Bot.iml create mode 100644 .idea/.gitignore create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 module/information1.py create mode 100644 module/information2.py diff --git a/.idea/-python3-KMS_Discord_Bot.iml b/.idea/-python3-KMS_Discord_Bot.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/-python3-KMS_Discord_Bot.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..28a804d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..ce37b15 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/KMS_Bot.py b/KMS_Bot.py index 6088ec2..410e459 100644 --- a/KMS_Bot.py +++ b/KMS_Bot.py @@ -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 * @@ -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("#한강"): diff --git a/module/information1.py b/module/information1.py new file mode 100644 index 0000000..afb9895 --- /dev/null +++ b/module/information1.py @@ -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 = '\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 += '\n' + data += '%s' % result[1] + data += '\n' + 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 diff --git a/module/information2.py b/module/information2.py new file mode 100644 index 0000000..0e0bd11 --- /dev/null +++ b/module/information2.py @@ -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