-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
60 lines (46 loc) · 2.06 KB
/
main.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
import discord
import myconfig
import asyncio
import websockets
import json
class discordbot(discord.Client):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# self.loop = asyncio.get_event_loop()
self.mykkutu = self.loop.create_task(self.kkutu_websocket())
async def kkutu_websocket(self):
global websocket # < 좋지않은 예...
async with websockets.connect(myconfig.ws) as websocket:
while True:
message = await websocket.recv()
jsonstring = json.loads(message)
if jsonstring['type'] == 'chat':
if not jsonstring['profile']['id'] == myconfig.wsid:
# print(jsonstring['value'])
try:
name = jsonstring["profile"]["title"]
except:
name = jsonstring["profile"]["name"]
value = jsonstring['value']
value = value.replace("@here","")
value = value.replace("@everyone","")
print('[끄투] ' + name + ': ' + value )
await self.get_channel(myconfig.channelid).send('[끄투] `' + name + '`: ' + value )
async def on_ready(self):
print("======")
print("Discord2KKuTu Discord 로그인 완료.")
print("======")
async def on_message(self, message):
if message.author.bot:
return
if not message.channel.id == myconfig.channelid:
return
else:
a = message.attachments
b = len(a)
if b > 0:
for n in a:
await websocket.send('{"type":"talk","value":"' + '[디코] ' + message.author.name + ': ' + n.url + '"}')
await websocket.send('{"type":"talk","value":"' + '[디코] ' + message.author.name + ': ' + message.content + '"}')
client = discordbot()
client.run(myconfig.token)