-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
108 lines (87 loc) · 3.22 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
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 import app_commands
from sdk import Client as SdkClient
from base64 import b64encode, b64decode
from json import load, dumps, loads
import asyncio
try:
import uvloop
except ImportError:
uvloop.install()
class MyClient(discord.Client):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
with open("config.json", "r") as f:
self.config = load(f)
self.sdk = SdkClient(self.config["ugc"])
def on(self, name):
return self.sdk.on(name)
async def close(self):
await self.sdk.close()
await super().close()
client = MyClient(intents=discord.Intents.all())
tree = app_commands.CommandTree(client)
@client.event
async def on_ready():
print("ready")
await tree.sync()
await client.sdk.connect()
await client.sdk.reconnect()
@tree.command(description="Pong")
async def ping(interaction):
await interaction.response.send_message("{}ms".format(round(client.sdk.latency * 1000)))
@client.on("ready")
async def ready_for_ugc():
print("Ready for ugc")
@client.on("message")
async def message(message):
if message.source == str(client.user.id):
return
if message.author.bot:
return
for ch in client.get_all_channels():
if ch.name == "ugc-test":
embed = discord.Embed(description=message.content, color=0x07cff7)
embed.set_author(name=message.author.name, icon_url=message.author.avatar_url)
await ch.send(embed=embed)
"""
@client.on("message")
async def on_ugc_message(message):
if message.where == str(client.user.id):
return
channel = client.get_channel(949862388969119755)
await channel.send(embed=discord.Embed(description=b64encode(dumps(message.data).encode()).decode()))
async def recieve_message(message):
if message.author.id == str(client.user.id):
return
if message.channel.id == 949862388969119755:
await client.sdk.request("POST", "/channels", json=loads(b64decode(message.embeds[0].description.encode()).decode()))
"""
@client.event
async def on_message(message):
#await recieve_message(message)
if message.author.bot:
return
if message.channel.name != "ugc-test":
return
for ch in client.get_all_channels():
if message.channel.id == ch.id:
continue
if ch.name == "ugc-test":
await message.add_reaction("🔄")
embed = discord.Embed(description=message.content, color=0x07cff7)
embed.set_author(name=message.author.name, icon_url=getattr(
message.author.avatar, "url", None))
embeds = [embed]
if len(message.attachments) != 0:
for attachment in message.attachments:
e = discord.Embed(color=0x07cff7)
e.set_image(url=attachment.url)
embeds.append(e)
await ch.send(embeds=embeds)
await client.sdk.send(message)
await message.remove_reaction("🔄", client.user)
await message.add_reaction("✅")
await asyncio.sleep(3)
await message.remove_reaction("✅", client.user)
client.run(client.config["token"])