Last active
March 21, 2021 05:03
-
-
Save HyunsDev/6b1885c3bb09464c3e016883060caaad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import discord, asyncio, json, datetime, os, re | |
with open("./config/config.json", encoding="utf-8") as f: | |
config = json.load(f) | |
with open("./config/topic_list.json", encoding="utf-8") as f: | |
glo_topic_list = json.load(f) | |
with open("./config/topic.json", encoding="utf-8") as f: | |
glo_topic = json.load(f) | |
token = config["bot_token"] | |
client = discord.Client() | |
def config_refresh(): | |
global config | |
global glo_topic_list | |
global glo_topic | |
with open("./config/config.json", encoding="utf-8") as f: | |
config = json.load(f) | |
with open("./config/topic_list.json", encoding="utf-8") as f: | |
glo_topic_list = json.load(f) | |
with open("./config/topic.json", encoding="utf-8") as f: | |
glo_topic = json.load(f) | |
def now(): | |
now = datetime.datetime.now() | |
date = now.strftime("%Y-%m-%d %H:%M:%S") | |
return date | |
def name_now(): | |
now = datetime.datetime.now() | |
date = now.strftime("%Y%m%d%H%M%S") | |
return date | |
@client.event | |
async def on_ready(): | |
await client.change_presence(activity=discord.Game("주제토론")) | |
print(f"[Wakeup] {client.user.name} ({client.user.id})") | |
@client.event | |
async def on_message_delete(message): # 메세지 삭제 로그 | |
# try: | |
if True: | |
if message.channel.id in config["channels"]["protect_channels_id"]: | |
if message.author.bot: | |
return None | |
embed = discord.Embed(title="[메세지 삭제됨]", description=None, color=0xff0000) | |
embed.set_footer(text=f"사용자 : {message.author.display_name}") | |
await client.get_channel(message.channel.id).send(embed=embed) | |
if message.content.find("```") != -1: | |
embed.set_footer(text=f"사용자 : {message.author.display_name}({message.author.id})") | |
await client.get_channel(config["channels"]["dashboard_channel_id"]).send(embed=embed) | |
await client.get_channel(config["channels"]["dashboard_channel_id"]).send(">>> 삭제된 메세지\n" + message.content) | |
else: | |
await client.get_channel(config["channels"]["dashboard_channel_id"]).send(embed=embed) | |
await client.get_channel(config["channels"]["dashboard_channel_id"]).send(f">>> 삭제된 메세지\n```\n{message.content}\n```") | |
# except Exception as e: | |
# print(e) | |
@client.event | |
async def on_message_edit(before, after): #메세지 변경 로그 | |
# try: | |
if True: | |
if before.channel.id in config["channels"]["protect_channels_id"]: | |
if before.author.bot: | |
return None | |
if before.content.find("```") != -1: | |
if after.content.find("```") != -1: | |
await client.get_channel(config["channels"]["dashboard_channel_id"]).send(f">>> 메세지 변경 <@{before.author.id}>({before.author.id})\n{before.content}\n{after.content}") | |
else: | |
await client.get_channel(config["channels"]["dashboard_channel_id"]).send(f">>> 메세지 변경 <@{before.author.id}>({before.author.id})\n{before.content}\n```\n{after.content}\n```") | |
else: | |
if after.content.find("```") != -1: | |
await client.get_channel(config["channels"]["dashboard_channel_id"]).send(f">>> 메세지 변경 <@{before.author.id}>({before.author.id})\n```\n{before.content}\n```\n{after.content}") | |
else: | |
await client.get_channel(config["channels"]["dashboard_channel_id"]).send(f">>> 메세지 변경 <@{before.author.id}>({before.author.id})\n```\n{before.content}\n```\n```\n{after.content}\n```") | |
# except Exception as e: | |
# print(e) | |
@client.event | |
async def on_message(message): | |
global config | |
global glo_topic_list | |
global glo_topic | |
if message.channel.id == 701947403653218375: | |
if message.content == "": | |
return None | |
if re.match(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$\-@\.&+:/?=]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+$', message.content) == None: | |
await message.delete() | |
return None | |
return None | |
try: | |
message.guild | |
except AttributeError: | |
pass | |
def check_emoji_ox_users(reaction, user): | |
return not user.bot and ( str(reaction.emoji) == '⭕' or str(reaction.emoji) == '❌') | |
def check_emoji_ox_author(reaction, user): | |
return user == message.author and ( str(reaction.emoji) == '⭕' or str(reaction.emoji) == '❌') | |
def check_channel_author(msg): | |
return msg.author == message.author and msg.channel == message.channel | |
if message.author.bot: #대상 봇이면 반응 안함 | |
return None | |
if message.guild is None: #DM채널 차단 | |
return None | |
# 관리자 명령어 | |
if message.author.top_role.id == config["admin_rule_id"]: | |
if message.content == "ping": #봇 살아 있는지 확인 | |
await message.channel.send("pong") | |
if message.content == "/config_reload": | |
config = json.load(open('./config/config.json')) | |
embed = discord.Embed(title="Config Reload", description=None, color=0x62c1cc) | |
await message.channel.send(embed=embed) | |
if message.content == "/kill": | |
await message.channel.send("주제토론 봇을 종료합니다") | |
exit() | |
#주제토론 하위 명령어 | |
if message.content.startswith("/topic"): | |
# 주제토론 주제 관련 관리자 명령어 | |
if message.content == "/topic": | |
embed = discord.Embed(title="주제토론 Admin", description=None, url="노션주소", color=0x62c1cc) | |
embed.add_field(name="주제 진행", value="/topic start [주제 아이디] [#채널]", inline=False) | |
embed.add_field(name="주제 종료", value="/topic stop [#채널]", inline=False) | |
embed.add_field(name="주제 대기열 리스트", value="/topic list", inline=False) | |
embed.add_field(name="주제 세부정보", value="/topic info [주제 아이디]", inline=False) | |
embed.add_field(name="진행중인 주제", value="/topic now", inline=False) | |
embed.add_field(name="config 내용 수정", value="/topic edit config", inline=False) | |
embed.add_field(name="config 파일 내용 적용", value="/topic file reflesh", inline=False) | |
embed.add_field(name="주제 강제 등록", value="/topic add [토론/토의] 주제", inline=False) | |
embed.add_field(name="주제 삭제", value="/topic del [주제 아이디]", inline=False) | |
embed.add_field(name="파일 다운로드", value="/topic download", inline=False) | |
await message.channel.send(embed=embed) | |
content = message.content[7:] | |
# 주제토론 리스트 | |
if content == "list": | |
with open("./config/topic_list.json", encoding="utf-8") as f: | |
glo_topic_list = json.load(f) | |
debate_text = "" | |
for i in glo_topic_list["debate"]: | |
if i["status"] == 0: a = "진행전" | |
elif i["status"] == 1: a = "진행중" | |
elif i["status"] == 2: a = "진행완료" | |
else: a = "오류" | |
debate_text = debate_text + f"[{i['id']}] [{a}] {i['topic']}\n" | |
await message.channel.send(f"토론 주제 대기열\n```cs\n{debate_text}\n```") | |
discus_text = "" | |
for i in glo_topic_list["discus"]: | |
if i["status"] == 0: a = "진행전" | |
elif i["status"] == 1: a = "진행중" | |
elif i["status"] == 2: a = "진행완료" | |
else: a == "오류" | |
discus_text = discus_text + f"[{i['id']}] [{a}] {i['topic']}\n" | |
await message.channel.send(f"토의 주제 대기열\n```cs\n{discus_text}\n```") | |
# config 파일 내용 적용 | |
if content == "file reflesh": | |
config_refresh() | |
await message.channel.send("파일 내용을 봇에 적용하였습니다.") | |
# config 파일 내용 수정 | |
if content == "edit config": | |
try: | |
with open(f"./config/config.json", encoding="utf-8") as f: # 파일 읽기 | |
await message.channel.send(f"> config.json\n```json\n{json.dumps(json.load(f), indent=4, sort_keys=True, ensure_ascii=False)}\n```\n수정할 데이터를 입력하세요. 취소하려면 \"취소\"를 입력하세요.") | |
except Exception as e: | |
await message.channel.send("파일을 읽을 수 없습니다.\n`" + str(e) + "`") | |
return None | |
try: # 수정할 내용 입력 | |
msg = await client.wait_for('message', timeout=180.0, check=check_channel_author) | |
except asyncio.TimeoutError: | |
await message.channel.send('제한 시간을 초과하였습니다.') | |
else: | |
if msg.content == "취소": | |
await message.channel.send("취소하였습니다.") | |
return None | |
with open(f"./config/config.json", 'w', encoding="utf-8") as f: # 수정 내용 반영 | |
f.write(msg.content) | |
await message.channel.send("수정하였습니다. `/topic file reflesh` 명령어를 입력하여 파일 변경 내역을 봇에 적용시키십시오.") | |
if content == "download": | |
files = [] | |
dirctory = os.path.dirname(__file__) | |
files.append(discord.File(dirctory + "/config/config.json")) | |
files.append( discord.File(dirctory + "/config/topic.json")) | |
files.append(discord.File(dirctory + "/config/topic_list.json")) | |
await message.channel.send(files=files) | |
# 주제 세부정보 | |
if content.startswith("info d"): | |
topic_id = content[5:] # 주제 아이디 | |
if topic_id[0:6] == "debate": | |
chan = "debate" | |
elif topic_id[0:6] == "discus": | |
chan = "discus" | |
else: | |
await message.channel.send(f"올바른 아이디를 입력해주세요.") | |
return None | |
for i in glo_topic_list[chan]: | |
if topic_id in i["id"]: | |
i = json.dumps(i, indent=4, sort_keys=True, ensure_ascii=False) | |
await message.channel.send(f"```json\n{i}\n```") | |
return None | |
await message.channel.send(f"주제를 찾을 수 없습니다.") | |
return None | |
# 주제 삭제 | |
if content.startswith("del d"): | |
topic_id = content[4:] # 주제 아이디 | |
if topic_id[0:6] == "debate": | |
chan = "debate" | |
elif topic_id[0:6] == "discus": | |
chan = "discus" | |
else: | |
await message.channel.send(f"올바른 아이디를 입력해주세요.") | |
return None | |
a = -1 | |
for i in glo_topic_list[chan]: | |
a += 1 | |
if topic_id in i["id"]: | |
msg = await client.get_channel(config["channels"]["topic_channel_id"]).fetch_message(i["message_id"]) | |
await msg.delete() | |
del glo_topic_list[chan][a] | |
await message.channel.send(f"주제를 삭제했습니다.") | |
with open("./config/topic_list.json", 'w', encoding="utf-8") as f: | |
json.dump(glo_topic_list, f, indent=4, ensure_ascii=False) | |
config_refresh() | |
return None | |
await message.channel.send(f"주제를 찾을 수 없습니다.") | |
return None | |
# 주제 강제 등록 | |
if content.startswith("add "): | |
args = content.split() | |
try: | |
if args[1] not in ["토론", "토의"]: | |
embed = discord.Embed(title="토론, 토의를 정확하게 적어주세요.", description=None, color=0xff0000) | |
embed.set_footer(text="/topic add [토론|토의] [주제]") | |
await message.channel.send(embed=embed) | |
return None | |
except IndexError: | |
embed = discord.Embed(title="토론, 토의를 정확하게 적어주세요.", description=None, color=0xff0000) | |
embed.set_footer(text="/주제등록 [토론|토의] [주제]") | |
await message.channel.send(embed=embed) | |
return None | |
if args[1] == "토론": | |
chan = "debate" | |
elif args[1] == "토의": | |
chan = "discus" | |
if message.author.display_name != message.author.name: | |
author_name = f"{message.author.name}#{message.author.discriminator}" | |
else: | |
author_name = f"{message.author.display_name} ({message.author.name}#{message.author.discriminator})" | |
topic = message.content[14:] | |
if len(topic) > config["topic_max_length"]: # 너무 긴 주제 컷 | |
await message.channel.send(embed=discord.Embed(title="주제가 너무 길어요", description=f"{config['topic_max_length']}자 이내로 적어주세요.", color=0xff0000)) | |
return None | |
if len(topic) < 3: | |
await message.channel.send(embed=discord.Embed(title="주제가 너무 짧아요", description=None, color=0xff0000)) | |
return None | |
embed = discord.Embed(title=topic, description=f"{author_name}", color=0x62c1cc) | |
msg = await client.get_channel(config["channels"]["topic_channel_id"]).send(embed=embed) | |
await msg.add_reaction("👍") | |
await msg.add_reaction("⚠") | |
glo_topic_list[chan].append({"id": chan + "_" + name_now(), | |
"topic": topic, | |
"author": f"{author_name}", | |
"author_id" : message.author.id, | |
"now": now(), | |
"status": 0, | |
"message_id": msg.id}) | |
with open("./config/topic_list.json", 'w', encoding="utf-8") as f: | |
json.dump(glo_topic_list, f, indent=4, ensure_ascii=False) | |
embed = discord.Embed(title="주제를 등록했어요.", description=topic, color=0x00ff00) | |
embed.set_footer(text=f"{author_name}") | |
await message.channel.send(embed=embed) | |
return None | |
# 토론/토의 종료 | |
if content.startswith("stop "): | |
args = content.split() | |
try: | |
args[1] | |
except IndexError: | |
embed = discord.Embed(title="#채널을 입력해주세요.", description=None, color=0xff0000) | |
await message.channel.send(embed=embed) | |
return None | |
args[1] = args[1].replace("<#", "") | |
args[1] = args[1].replace(">", "") | |
channels = [config["channels"]["debate_channel_1_id"],config["channels"]["debate_channel_2_id"],config["channels"]["discus_channel_1_id"],config["channels"]["discus_channel_2_id"]] | |
if int(args[1]) not in channels: | |
embed = discord.Embed(title=None, description="올바른 채널이 아닙니다.", color=0xff0000) | |
await message.channel.send(embed=embed) | |
return None | |
else: | |
if int(args[1]) == config["channels"]["debate_channel_1_id"]: | |
chan_name = "debate_channel_1" | |
chan_korean = "토론장-1" | |
chan = "debate" | |
elif int(args[1]) == config["channels"]["debate_channel_2_id"]: | |
chan_name = "debate_channel_2" | |
chan_korean = "토론장-2" | |
chan = "debate" | |
elif int(args[1]) == config["channels"]["discus_channel_1_id"]: | |
chan_name = "discus_channel_1" | |
chan_korean = "토의장-1" | |
chan = "discus" | |
elif int(args[1]) == config["channels"]["discus_channel_2_id"]: | |
chan_name = "discus_channel_2" | |
chan_korean = "토의장-2" | |
chan = "discus" | |
topic_info = glo_topic[chan_name] | |
if topic_info["topic"] == "": | |
embed = discord.Embed(title=None, description="진행중인 토론이 없습니다.", color=0xff0000) | |
await message.channel.send(embed=embed) | |
return None | |
glo_topic[chan_name] = {"topic": "", "topic_id": "", "user": [], "start_day": "", "message_id": 0} | |
with open("./config/topic.json", 'w', encoding="utf-8") as f: | |
json.dump(glo_topic, f, indent=4, ensure_ascii=False) | |
a = -1 | |
for i in glo_topic_list[chan]: | |
a = a + 1 | |
if glo_topic[chan_name]["topic_id"] in i["id"]: | |
break | |
glo_topic_list[chan][a]["status"] = 2 | |
with open("./config/topic_list.json", 'w', encoding="utf-8") as f: | |
json.dump(glo_topic_list, f, indent=4, ensure_ascii=False) | |
await client.get_channel(int(args[1])).edit(topic="토론이 종료되었습니다.") | |
embed = discord.Embed(title=None, description="토론이 종료되었습니다.", color=0xff0000) | |
await client.get_channel(int(args[1])).send(embed=embed) | |
msg = await client.get_channel(config["channels"]["topic_channel_id"]).fetch_message(glo_topic_list[chan][a]["message_id"]) | |
await msg.edit(embed=discord.Embed(title=glo_topic_list[chan][a]['topic'], description=glo_topic_list[chan][a]['author'], color=0x0000ff)) | |
embed = discord.Embed(title=None, description="토론이 종료되었습니다.", color=0xff0000) | |
await message.channel.send(embed=embed) | |
return None | |
if content == "now": | |
with open("./config/topic.json", encoding="utf-8") as f: | |
glo_topic = json.load(f) | |
i = json.dumps(glo_topic, indent=4, sort_keys=True, ensure_ascii=False) | |
await message.channel.send(f"```json\n{i}\n```") | |
# 토론/토의 시작 | |
if content.startswith("start "): | |
args = content.split() | |
try: | |
args[1] | |
except IndexError: | |
embed = discord.Embed(title="주제 아이디를 입력해주세요.", description=None, color=0xff0000) | |
await message.channel.send(embed=embed) | |
return None | |
try: | |
args[2] | |
except IndexError: | |
embed = discord.Embed(title="채널 이름을 입력해주세요.", description=None, color=0xff0000) | |
await message.channel.send(embed=embed) | |
return None | |
args[2] = args[2].replace("<#", "") | |
args[2] = args[2].replace(">", "") | |
channels = [config["channels"]["debate_channel_1_id"],config["channels"]["debate_channel_2_id"],config["channels"]["discus_channel_1_id"],config["channels"]["discus_channel_2_id"]] | |
topic_id = args[1] | |
if topic_id[0:6] == "debate": | |
chan = "debate" | |
elif topic_id[0:6] == "discus": | |
chan = "discus" | |
else: | |
await message.channel.send(f"올바른 주제 아이디를 입력해주세요.") | |
return None | |
if int(args[2]) in channels: | |
if int(args[2]) == config["channels"]["debate_channel_1_id"]: | |
chan_name = "debate_channel_1" | |
chan_korean = "토론장-1" | |
elif int(args[2]) == config["channels"]["debate_channel_2_id"]: | |
chan_name = "debate_channel_2" | |
chan_korean = "토론장-2" | |
elif int(args[2]) == config["channels"]["discus_channel_1_id"]: | |
chan_name = "discus_channel_1" | |
chan_korean = "토의장-1" | |
elif int(args[2]) == config["channels"]["discus_channel_2_id"]: | |
chan_name = "discus_channel_2" | |
chan_korean = "토의장-2" | |
if chan != chan_name[0:6]: | |
warning = "주의! 주제와 채널이 맞지 않습니다." | |
else: | |
warning = "" | |
with open("./config/topic_list.json", encoding="utf-8") as f: | |
glo_topic_list = json.load(f) | |
a = -1 | |
for i in glo_topic_list[chan]: | |
a = a + 1 | |
if topic_id in i["id"]: | |
if i["status"] == 1: | |
tmp_text = f"{chan_korean} 에서 토론/토의를 시작하시겠습니까? (주의! 진행중인 주제입니다,) " | |
elif i["status"] == 2: | |
tmp_text = f"{chan_korean} 에서 토론/토의를 시작하시겠습니까? (이미 진행했던 주제입니다,) " | |
else: | |
tmp_text = f"{chan_korean} 에서 토론/토의를 시작하시겠습니까?" | |
embed = discord.Embed(title=tmp_text, description=warning, color=0x62c1cc) | |
embed.set_footer(text=f"주제 : {i['topic']} ({i['id']})") | |
check_msg = await message.channel.send(embed=embed) | |
await check_msg.add_reaction("⭕") | |
await check_msg.add_reaction("❌") | |
try: | |
res = await client.wait_for('reaction_add', timeout=60.0, check=check_emoji_ox_author) | |
except asyncio.TimeoutError: | |
await message.channel.send("제한 시간이 지났어요..") | |
return None | |
else: | |
if str(res[0]) == "⭕": #토론 시작 | |
glo_topic[chan_name] = {"topic": i['topic'], "topic_id": i['id'], "user": [], "start_day": now(), "message_id": i["message_id"]} | |
with open("./config/topic.json", 'w', encoding="utf-8") as f: | |
json.dump(glo_topic, f, indent=4, ensure_ascii=False) | |
glo_topic_list[chan][a]["status"] = 1 | |
with open("./config/topic_list.json", 'w', encoding="utf-8") as f: | |
json.dump(glo_topic_list, f, indent=4, ensure_ascii=False) | |
embed = discord.Embed(title=f"{chan_korean} 에서 토론/토의가 시작되었습니다.", description=None, color=0x62c1cc) | |
embed.set_footer(text=f"주제 : {i['topic']} ({i['id']})") | |
await check_msg.edit(embed=embed) | |
await client.get_channel(int(args[2])).edit(topic=i["topic"]) | |
embed = discord.Embed(title=f"새로운 주제가 열렸습니다.", description=f"<#{int(args[2])}>", color=0x62c1cc) | |
embed.set_footer(text=f"주제 : {i['topic']} ({i['id']})") | |
await client.get_channel(config["channels"]["notice_channel_id"]).send(embed=embed) | |
msg = await client.get_channel(config["channels"]["topic_channel_id"]).fetch_message(i["message_id"]) | |
await msg.edit(embed=discord.Embed(title=i['topic'], description=i['author'], color=0x00ff00)) | |
await client.get_channel(int(args[2])).send( | |
f'''새로운 주제가 열렸어요! 이번 주제는 다음과 같습니다. | |
> {i["topic"]} | |
정답은 없습니다. 자신의 의견을 알려주세요! | |
주제 토론 안내 | |
``` | |
1. 주제 토론은 "슬로우 모드 10초" 가 적용되어 있습니다. 한 글을 올릴 때 여러번에 나누어 올리지 말고 한 번에 올려주세요. | |
2. 주제 토론은 다른 채팅방과 달리 민감한 주제로 진행되므로 "다른 방에 비해 더욱 엄격한 규칙과 제제가 적용됩니다" | |
3. 주제 토론은 하나의 정답을 추구하기 위한 것이 아닙니다. 서로의 생각을 존중하고, 근거를 들어 반론을 해주세요. | |
4. 중재가 필요하면 주제토론 담당 운영진인 @혀느현스#3891 을 맨션해주세요! | |
``` | |
자세한 규칙과 도움말은 <#{config["channels"]["rule_channel_id"]}>을 참고해주세요! | |
담당/중재 운영진 : <@{config["chat_admin_id"]}> | |
<@&{config["mention_role_id"]}>''') | |
return None | |
elif str(res[0]) == "❌": | |
embed = discord.Embed(title=f"{chan_korean} 토론/토의 시작이 취소되었습니다.", description=None, color=0x62c1cc) | |
embed.set_footer(text=f"주제 : {i['topic']} ({i['id']})") | |
await check_msg.edit(embed=embed) | |
return None | |
return None | |
await message.channel.send(f"주제를 찾을 수 없습니다.") | |
return None | |
await message.channel.send(f"채널을 찾을 수 없습니다.") | |
return None | |
#유저 명령어 | |
if message.content.startswith("/") and message.channel.category_id == config["channel_category_id"]: #사용자 명령어 | |
message.content = message.content[1:] | |
# 도움말 | |
if message.content == "주제토론": | |
embed = discord.Embed(title="주제토론 도움말", description=None, color=0x62c1cc) | |
embed.add_field(name="새로운 주제를 등록합니다.", value="/주제등록 [토론|토의] [주제]", inline=False) | |
embed.add_field(name="새로운 주제가 열렸을 때 멘션을 받습니다.", value="/주제토론 알림 [허용|차단]", inline=False) | |
await message.channel.send(embed=embed) | |
# 알림 | |
if message.content == "주제토론 알림 허용": | |
await message.author.add_roles(client.get_guild(config["guild_id"]).get_role(config["mention_role_id"])) | |
await message.channel.send(embed= discord.Embed(title=None, description="다음 주제가 열리면 멘션을 받습니다.", color=0x00ff00)) | |
if message.content == "주제토론 알림 차단": | |
await message.author.remove_roles(client.get_guild(config["guild_id"]).get_role(config["mention_role_id"])) | |
await message.channel.send(embed= discord.Embed(title=None, description="더 이상 새로운 주제에 대하여 멘션을 받지 않습니다.", color=0xff0000)) | |
# 주제등록 | |
if message.content.startswith("주제등록") and message.channel.id == config["channels"]["topic_chat_channel_id"]: | |
msg = message.content.split() | |
if message.content == "주제등록": | |
embed = discord.Embed(title="주제등록", description=None, color=0x62c1cc) | |
embed.add_field(name="도움말", value="/주제등록 [토론|토의] [주제]", inline=False) | |
embed.add_field(name="등록 조건", value=f"등록 후 {config['topic_vote_accept_count']}표 이상의 동의를 얻어야 하며, {config['topic_vote_decline_count']}표 이상의 반대표를 받으면 등록이 거절됩니다. (토의후 재등록해주세요!)", inline=False) | |
await message.channel.send(embed=embed) | |
return None | |
try: | |
if msg[1] not in ["토론", "토의"]: | |
embed = discord.Embed(title="토론, 토의를 정확하게 적어주세요.", description=None, color=0xff0000) | |
embed.set_footer(text="/주제등록 [토론|토의] [주제]") | |
await message.channel.send(embed=embed) | |
return None | |
except IndexError: | |
embed = discord.Embed(title="토론, 토의를 정확하게 적어주세요.", description=None, color=0xff0000) | |
embed.set_footer(text="/주제등록 [토론|토의] [주제]") | |
await message.channel.send(embed=embed) | |
return None | |
if msg[1] == "토론": | |
chan = "debate" | |
elif msg[1] == "토의": | |
chan = "discus" | |
glo_topic = message.content[8:] | |
if len(glo_topic) > config["topic_max_length"]: # 너무 긴 주제 컷 | |
await message.channel.send(embed=discord.Embed(title="주제가 너무 길어요", description=f"{config['topic_max_length']}자 이내로 적어주세요.", color=0xff0000)) | |
return None | |
if len(glo_topic) < 2: | |
await message.channel.send(embed=discord.Embed(title="주제를 적어주세요", description=None, color=0xff0000)) | |
return None | |
if len(glo_topic) < 5: | |
await message.channel.send(embed=discord.Embed(title="주제가 너무 짧아요", description="최소한 5자 이상은 적어주세요.", color=0xff0000)) | |
return None | |
embed = discord.Embed(title="주제를 투표해주세요.", description=glo_topic, color=0x62c1cc) | |
if message.author.display_name != message.author.name: | |
author_name = f"{message.author.name}#{message.author.discriminator}" | |
else: | |
author_name = f"{message.author.display_name} ({message.author.name}#{message.author.discriminator})" | |
embed.set_footer(text=f"제안 : {author_name} {config['topic_vote_accept_count']}명 이상의 동의를 얻으면 등록되며, {config['topic_vote_decline_count']}표 이상의 반대를 받을경우 취소됩니다.") | |
check_msg = await message.channel.send(embed=embed) | |
await check_msg.add_reaction("⭕") | |
await check_msg.add_reaction("❌") | |
user_id = [] | |
go = 0 | |
stop = 0 | |
while True: | |
try: | |
res = await client.wait_for('reaction_add', check=check_emoji_ox_users) | |
except asyncio.TimeoutError: | |
await message.channel.send("제한 시간이 지났어요..") | |
return None | |
else: | |
if res[1].id in user_id: | |
continue | |
if str(res[0]) == "⭕": | |
user_id.append(res[1].id) | |
go = go + 1 | |
elif str(res[0]) == "❌": | |
user_id.append(res[1].id) | |
stop = stop + 1 | |
if go >= config["topic_vote_accept_count"]: | |
embed = discord.Embed(title=glo_topic, description=f"{author_name}", color=0x62c1cc) | |
msg = await client.get_channel(config["channels"]["topic_channel_id"]).send(embed=embed) | |
await msg.add_reaction("👍") | |
await msg.add_reaction("⚠") | |
glo_topic_list[chan].append({"id": chan + "_" + name_now(), "topic": glo_topic, "author": f"{author_name}", "author_id" : message.author.id, "now": now(), "status": 0, "message_id": msg.id}) | |
with open("./config/topic_list.json", 'w', encoding="utf-8") as f: | |
json.dump(glo_topic_list, f, indent=4, ensure_ascii=False) | |
embed = discord.Embed(title="주제를 등록했어요.", description=glo_topic, color=0x00ff00) | |
embed.set_footer(text=f"{author_name}") | |
await check_msg.edit(embed=embed) | |
return None | |
elif stop >= config["topic_vote_decline_count"]: | |
embed = discord.Embed(title="등록이 거절되었어요.", description=glo_topic, color=0xff0000) | |
embed.set_footer(text=f"{author_name}") | |
await check_msg.edit(embed=embed) | |
return None | |
client.run(config["bot_token"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment