-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
108 lines (75 loc) · 2.95 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import discord
from discord.ext import commands, tasks
import string
import re
import json
import random
import asyncio
import dataget
rootname = "data/server"
intents = discord.Intents.all()
tokenfile = open("token.json", "r", encoding="UTF-8")
bot = commands.Bot(command_prefix=["cc!", "CC!"], intents=intents)
@bot.event
async def on_ready():
print("bot login test")
print(bot.user.name)
print(bot.user.id)
print("-----------")
await bot.change_presence(
status=discord.Status.online,
activity=discord.Game("메세지 관리"),
)
bot.loop.create_task(job())
async def job():
while True:
sendch = bot.get_channel(importdata["channel"])
sendmsg = dataget.get_chat_data()
if sendmsg == "fail":
continue
send_text = dataget.CheckMessage(sendmsg)
lunaday = "누군가"
embed = discord.Embed(title=f"{lunaday}", url="https://127.0.0.1",
description=send_text,
color=0xFF5733)
await sendch.send(embed=embed)
await asyncio.sleep(5)
testinfo = {}
@bot.event
async def on_member_join(member):
global testinfo
testrole = discord.utils.get(member.guild.roles, name="입장테스트")
await member.add_roles(testrole)
channel = await member.guild.create_text_channel("입장채널")
selfbot = discord.utils.get(member.guild.members, id=bot.user.id)
await channel.set_permissions(member, read_messages=True)
await channel.set_permissions(selfbot, read_messages=True)
await channel.set_permissions(member.guild.default_role, read_messages=False)
testcode = random.sample(string.ascii_lowercase, 10)
testinfo[str(channel.id)] = {"userid": member.id, "testcode": testcode}
print(testinfo)
await channel.send(f"{testinfo[str(channel.id)]['testcode']} 순서대로 채팅")
@bot.event
async def on_message(tempmessage):
if re.match("[a-z]{1}", tempmessage.content) and len(tempmessage.content) == 1:
channelid = tempmessage.channel.id
if str(channelid) in testinfo.keys():
if testinfo[str(channelid)]["testcode"][0] == tempmessage.content and testinfo[str(channelid)][
"userid"] == tempmessage.author.id:
del testinfo[str(channelid)]["testcode"][0]
print(testinfo[str(channelid)])
if len(testinfo[str(channelid)]["testcode"]) == 0:
testrole = discord.utils.get(tempmessage.guild.roles, name="입장테스트")
await tempmessage.author.remove_roles(testrole)
del testinfo[str(channelid)]
await bot.get_channel(channelid).delete()
else:
await bot.process_commands(tempmessage)
testcheck = input("test모드 > 'test'입력")
token = ""
importdata = json.load(tokenfile)
if testcheck == "test":
token = importdata["testtoken"]
else:
token = importdata["token"]
bot.run(token)