This repository was archived by the owner on Aug 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
363 lines (318 loc) · 13.2 KB
/
main.py
File metadata and controls
363 lines (318 loc) · 13.2 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
from replit import db
from discord.ext import commands
from flask import Flask, redirect
from threading import Thread
import discord
import os
import json
import urllib.request
import datetime
prefix = "-"
client = commands.Bot(command_prefix=f"{prefix}", intents=discord.Intents.all())
global config_qa
config_qa = 1
if "config_qa" in db.keys():
config_qa = db["config_qa"]
domain = "n8j5srrv39fz.runkit.sh"
allowedChannels = [661017509444714561,822509249740537887]
app = Flask('')
@app.route('/')
def home():
return redirect("https://l.lnk.repl.co/tfIl")
def run():
app.run(host='0.0.0.0', port=8080)
t = Thread(target=run)
t.start()
@client.remove_command("help")
@client.command(no_pm=True, name="status")
async def status(ctx, * , msg="none"):
await permsCalc(ctx)
if msg == "none":
await errorSend(ctx.channel, "Invalid argument at possition 0", "none")
return()
if len(msg) > 1000:
await errorSend(ctx.channel, "The message must be 1000 chars or fewer.", "none")
return()
if permInt < 4:
await errorSend(ctx.channel, "This command requires DEVELOPER permissions to use!", f"{perm}")
return()
await client.change_presence(activity=discord.Game(msg))
embed = discord.Embed(timestamp=(datetime.datetime.now()), color=0xfff9b3)
embed.set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
#await setStatus(statusType, msg)
embed.add_field(name="Succesful!", value=f"Sucsessfuly set status to: ```Playing {msg}```")
await ctx.send(embed=embed)
db["discordPresence"] = msg
async def setStatus(statusType, msg):
if statusType == "playing":
await client.change_presence(activity=discord.Game(msg))
@client.command(no_pm=True, name="say")
async def say(ctx,* , msg="none"):
await permsCalc(ctx)
if msg == "none":
await errorSend(ctx.channel, "Invalid argument at possition 0", "none")
return()
if permInt < 2:
await errorSend(ctx.channel, "This command requires CONTRIBUTOR permissions to use!", f"{perm}")
return()
if len(msg) > 1000:
await errorSend(ctx.channel, "The message must be 1000 chars or fewer.", "none")
return()
await ctx.send(msg)
await ctx.message.delete()
@client.command(no_pm=True, name="test")
async def test(ctx):
guild = client.get_guild(660239763479068713)
msg = guild.get_msg(822507216061464586)
print(msg)
@client.command(no_pm=True, name="help")
async def help(ctx):
if ctx.channel.id in allowedChannels:
await permsCalc(ctx)
embed = discord.Embed(timestamp=(datetime.datetime.now()), color=0xfff9b3)
embed.set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
embed.add_field(name="Help Menu:", value="-help - Shows this menu.\n-faq - Most asked questions and answers.\n-status - Set the bots status.\n-player [player] - View a players profile.\n-autorespond - Toggles autoresponder.", inline=False)
embed.set_footer(text=f"Permissions: {perm}")
await ctx.send(embed=embed)
@client.command(no_pm=True, name="autorespond")
async def autorespond(ctx):
await permsCalc(ctx)
if permInt < 4:
await errorSend(ctx.channel, "This command requires DEVELOPER permissions to use!", f"{perm}")
return()
embed = discord.Embed(timestamp=(datetime.datetime.now()), color=0xfff9b3)
embed.set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
global config_qa
if config_qa == 1:
config_qa = 0
embed.add_field(name="Succesful!", value="Autoresponder has been disabled.")
else:
config_qa = 1
embed.add_field(name="Succesful!", value="Autoresponder has been enabled.")
db["config_qa"] = config_qa
await ctx.send(embed=embed)
@client.command(no_pm=True, name="faq")
async def faq(ctx, tag="list"):
await permsCalc(ctx)
#if permInt < 3:
# await errorSend(ctx.channel, "This command requires CONTRIBUTOR permissions to use!", f"{perm}")
# return()
tags = ["nbs","install","schem2df","itemapi","nbslength","optifine","darkmode"]
tagDes = ["nbs - View how to import and use nbs songs on DiamondFire.","install - View how to install CodeUtilities.","schem2df - View how to use Schem2DF on DiamondFire.","itemapi - View how to use codeutilities item api.","nbslength - View how to get a songs length in seconds.","optifine - View how to use optifine on fabric.","darkmode - View how to use menu darkmode."]
if tag not in tags:
embed = discord.Embed(timestamp=(datetime.datetime.now()), color=0xfff9b3)
embed.set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
embed.add_field(name="F&Q List:", value="\n".join(tagDes))
await ctx.send(embed=embed)
return()
if tag == "schem2df":
await tagReply(ctx, ctx.channel, ctx.author, "How do I use Schem2DF on DiamondFire?", f"https://{domain}?doc=Importing-Structure-Files-to-DiamondFire-(Schem2DF) ")
if tag == "install":
await tagReply(ctx, ctx.channel, ctx.author, "How do I install CodeUtilities?", f"https://{domain}?doc=Installation")
if tag == "nbs":
await tagReply(ctx, ctx.channel, ctx.author, "How do I use NBS Songs on DiamondFire?", f"https://{domain}?doc=Importing-Music-(NBS-Files)")
if tag == "itemapi":
await tagReply(ctx, ctx.channel, ctx.author, "How do I use CodeUtilities Item API?", "https://raw.githubusercontent.com/CodeUtilities/bot/main/faq/itemapi")
if tag == "nbslength":
await tagReply(ctx, ctx.channel, ctx.author, "How do I get a songs length in seconds?", "https://raw.githubusercontent.com/CodeUtilities/bot/main/faq/nbslength")
if tag == "optifine":
await tagReply(ctx, ctx.channel, ctx.author, "How do I use optifine on fabric?", "https://raw.githubusercontent.com/CodeUtilities/bot/main/faq/optifine")
if tag == "darkmode":
await tagReply(ctx, ctx.channel, ctx.author, "How do I use menu darkmode?", "https://raw.githubusercontent.com/CodeUtilities/bot/main/faq/darkmode")
@client.command(no_pm=True, name="player")
async def player(ctx, player="a"):
if player == "a":
if ctx.author.nick == None:
player = ctx.author.name
else:
player = ctx.author.nick
await permsCalc(ctx)
try:
with urllib.request.urlopen(f"https://api.mojang.com/users/profiles/minecraft/{player}") as url:
data = json.loads(url.read().decode())
uuid = data["id"]
uuidFormat = [8,4,4,4,12]
i = 0
count = 0
uuidFormatI = 0
finaluuid = []
while i != 32:
count += 1
finaluuid.append(uuid[i])
if count == uuidFormat[uuidFormatI]:
if count != 12:
finaluuid.append("-")
uuidFormatI += 1
count = 0
i += 1
uuid = "".join(finaluuid)
except:
await errorSend(ctx.channel, "Player not found!", "none")
return()
try:
with urllib.request.urlopen(f"https://codeutilities.github.io/data/cosmetics/players/{uuid}.json") as url:
cosmetics = json.loads(url.read().decode())
cape = cosmetics["cape"]
hat = cosmetics["hat"]
image = f"https://raw.githubusercontent.com/CodeUtilities/bot/main/capesHD/{cape}"
except:
cosmetics = "none"
hat = "None"
cape = "None"
image = "https://raw.githubusercontent.com/CodeUtilities/bot/main/capesHD/None.png"
try:
cape = cape.replace("_", " ")
cape = cape.replace(".png", "")
cape = cape.title()
except:
cape = "None"
try:
hat = hat.replace("_", " ")
hat = hat.replace(".json", "")
hat = hat.title()
except:
hat = "None"
embed = discord.Embed(timestamp=(datetime.datetime.now()), color=0xfff9b3, title=data["name"])
embed.set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
embed.add_field(name="UUID", value=uuid, inline=False)
embed.add_field(name="Cape", value=cape, inline=False)
embed.add_field(name="Hat", value=hat, inline=False)
if image != "https://raw.githubusercontent.com/CodeUtilities/bot/main/capesHD/None.png":
embed.set_thumbnail(url=image)
await ctx.send(embed=embed)
@client.event
async def on_ready():
print(f"Logged in as: {client.user}")
if "discordPresence" in db.keys():
await client.change_presence(activity=discord.Game(db["discordPresence"]))
else:
await client.change_presence(activity=discord.Game("DiamondFire!"))
async def errorSend(channel, error, showPerm):
embed = discord.Embed(timestamp=(datetime.datetime.now()), color=0xff0000)
embed.add_field(name="Error!", value=error, inline=False)
if showPerm != "none":
embed.set_footer(text=f"Permissions: {showPerm}")
await channel.send(embed=embed)
async def suggestionMsg(ctx, channel, type="suggestion"):
#Suggestion Post
if type != "suggestion":
return
member = ctx.author
embed = discord.Embed(color=0xfff9b3)
embed.add_field(name=f"📨 New {type} posted", value=f"{ctx.content}")
embed.set_author(name=f"{member.name}", icon_url=f"{member.avatar_url}")
embed.set_footer(text=f"Posted in #{ctx.channel}")
channel = client.get_channel(channel)
await channel.send(embed=embed)
@client.event
async def on_raw_message_delete(payload):
if f"{payload.message_id}msg" in db.keys():
ctx = db[f"{payload.message_id}msg"]
author = ctx[0]
authorID = ctx[1]
content = ctx[2]
url = ctx[3]
channel = ctx[4]
embed = discord.Embed(color=0xfff9b3)
embed.add_field(name=f"📨 Message deleted!", value=f"{content}")
embed.set_author(name=f"{author} ({authorID})", icon_url=f"{url}")
embed.set_footer(text=f"In #{channel}")
guild = client.get_guild(660239763479068713)
channel = guild.get_channel(747381895511146577)
del db[f"{payload.message_id}msg"]
await channel.send(embed=embed)
@client.event
async def on_message(ctx):
db[f"{ctx.id}msg"] = [f"{ctx.author.name}", f"{ctx.author.id}", f"{ctx.content}", f"{ctx.author.avatar_url}", f"{ctx.channel}"]
await client.process_commands(ctx)
if ctx.channel.id == 678590504232812544:
await ctx.add_reaction("<:upvote:682245287170801716>")
await ctx.add_reaction("<:downvote:682245297795104803>")
await suggestionMsg(ctx, 831063611073232926, "suggestion")
return()
if ctx.channel.id == 812998310612828182:
if ctx.author.bot:
await ctx.publish()
return()
if ctx.channel.id == 660493054498701313:
await suggestionMsg(ctx, 660239763936378883, "bug report")
return()
if ctx.channel.id == 675741807912419328:
await suggestionMsg(ctx, 675650117033787392, "beta bug report")
return()
guild = client.get_guild(660239763479068713)
ignore = guild.get_role(822760217640435733)
if ignore in ctx.author.roles:
return()
if config_qa == 1:
chars = ["?","!"]
msg = ctx.content.lower()
for char in chars:
msg = msg.replace(f"{char}", "")
msg = msg.split()
if "how" in msg:
if "install" in msg:
await tagReply(ctx, ctx.channel, ctx.author, "How do I install CodeUtilities?", f"https://{domain}?doc=Installation")
await ctx.channel.send(f"{ctx.author.mention} please read the above info first! If you are still having issues please ask in <#661550032344055850>")
if "schem2df" in msg:
await tagReply(ctx, ctx.channel, ctx.author, "How do I use Schem2DF on DiamondFire?", f"https://{domain}?doc=Importing-Structure-Files-to-DiamondFire-(Schem2DF) ")
await ctx.channel.send(f"{ctx.author.mention} please read the above info first! If you are still having issues please ask in <#661550032344055850>")
if "nbs" in msg:
await tagReply(ctx, ctx.channel, ctx.author, "How do I use NBS Songs on DiamondFire?", f"https://{domain}?doc=Importing-Music-(NBS-Files)")
await ctx.channel.send(f"{ctx.author.mention} please read the above info first! If you are still having issues please ask in <#661550032344055850>")
async def tagReply(ctx, channel, user, question, url):
file = urllib.request.urlopen(url)
text = []
text2 = []
chars = 0
for line in file:
decoded_line = line.decode("utf-8")
chars += len(decoded_line)
if chars >= 1950:
text2.append(decoded_line)
else:
text.append(decoded_line)
if chars >= 1950:
embed = discord.Embed(color=0xfff9b3, title=question, description=" ".join(text))
await ctx.channel.send(embed=embed)
embed = discord.Embed(timestamp=(datetime.datetime.now()), color=0xfff9b3, description=" ".join(text2))
await ctx.channel.send(embed=embed)
else:
embed = discord.Embed(timestamp=(datetime.datetime.now()), color=0xfff9b3, title=question, description=" ".join(text))
embed.set_author(name=user, icon_url=user.avatar_url)
if url == "https://raw.githubusercontent.com/CodeUtilities/bot/main/faq/darkmode":
await ctx.channel.send(embed=embed, content="https://youtu.be/_ebN_uLh4lU")
else:
await ctx.channel.send(embed=embed)
async def permsCalc(ctx):
global perm
global permInt
for role in reversed(ctx.author.roles):
role = role.id
if ctx.author.id in [711974603387306490, 605506592200327178]:
permInt = 5
perm = "BOT DEVELOPER"
return()
if ctx.author.id == 511653192942092289:
permInt = 4
perm = "RETIRED DEVELOPER"
return()
if role == 660627197735731212:
permInt = 4
perm = "DEVELOPER"
return()
if role == 780033350735495168:
permInt = 3
perm = "CONTRIBUTOR"
return()
if role == 661568558660059177:
permInt = 2
perm = "SAMMAN"
return()
if role == 675646859473322005:
permInt = 1
perm = "BETA TESTER"
return()
permInt = 0
perm = "USER"
client.run(os.environ["DISCORD_TOKEN"])