-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathmain.py
More file actions
388 lines (295 loc) · 11.7 KB
/
Copy pathmain.py
File metadata and controls
388 lines (295 loc) · 11.7 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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
import discord
from discord.ext import commands , tasks
import datetime
import json
import os
from colorama import Fore
intents = discord.Intents().all()
bot = commands.Bot(command_prefix=',', intents = intents)
bot.remove_command("help")
@bot.event
async def on_ready():
print(f"{bot.user.name} is Ready")
await expire()
with open("config.json", "r") as file:
hmm = json.load(file)
rid = hmm["premiumeroleid"]
cid = hmm["categoryid"]
staff = hmm["staffrole"]
print(rid)
@tasks.loop(hours=1)
async def expire():
try:
with open("data.json", "r") as file:
data = json.load(file)
except FileNotFoundError:
data = []
nowtime = datetime.datetime.now()
nt = nowtime.strftime("%Y%m%d")
remove = []
for xd in data:
for item in xd:
slottime = item["endtime"]
st = datetime.datetime.fromtimestamp(int(slottime))
print(st.strftime("%Y%m%d"))
finalse = st.strftime("%Y%m%d")
print(f"Slot end {finalse}")
print(f"now time {nt}")
print(nt >= finalse)
if nt >= finalse:
with open("data.json", "w") as file:
json.dump(data, file, indent=4)
channel = bot.get_channel(item["channelid"])
guild = bot.get_guild(int(hmm["guildid"]))
member = guild.get_member(item["userid"])
if member and channel:
print(member.id)
await channel.send(f"Slot expired")
role = discord.utils.get(guild.roles, id=rid)
print(role)
await member.remove_roles(role)
await channel.set_permissions(member, send_messages=False)
print(xd)
data.remove(xd)
with open("./data.json","w") as nice:
json.dump(data, nice,indent=4)
@bot.event
async def on_message(message):
await bot.process_commands(message)
category = discord.utils.get(message.guild.categories, id=int(cid))
if category:
if "@here" in message.content:
try:
with open("pingcount.json", "r") as file:
data = json.load(file)
except FileNotFoundError:
data = []
print(message.channel.id)
print(data)
nice = False
if not data:
dataz = {
"channelid": message.channel.id,
"time": datetime.datetime.now().timestamp(),
"count": 2
}
data.append(dataz)
with open("pingcount.json", "w") as file:
json.dump(data, file, indent=4)
await message.channel.send("1/2")
return
for c in data:
print(c)
if message.channel.id == c["channelid"]:
nice = True
print(c["time"])
print(datetime.datetime.now().timestamp())
nowt = datetime.datetime.now().timestamp()
slotdata = int(c["time"])
print(slotdata)
sl = datetime.datetime.fromtimestamp(slotdata)
slot = sl.strftime("%Y%m%d")
cx = datetime.datetime.now()
print(cx.timestamp())
nowtime = cx.strftime("%Y%m%d")
if slot == nowtime:
xxx = c["count"]
if c["count"] >= 3:
channel = bot.get_channel(c["channelid"])
await channel.set_permissions(message.author, send_messages=False)
await message.channel.send("3/2 Slot Revoked <@&your staff role id>\n**Reason:** 3 here ping")
return
c["count"] = c["count"] + 1
await message.channel.send(f"{xxx}/{xxx}")
with open("pingcount.json", "w") as file:
json.dump(data, file, indent=4)
return
else:
c["time"] = datetime.datetime.now().timestamp()
c["count"] = 2
with open("pingcount.json", "w") as file:
json.dump(data, file, indent=4)
await message.channel.send("1/2")
if not nice:
datazx = {
"channelid": message.channel.id,
"time": datetime.datetime.now().timestamp(),
"count": 2
}
data.append(datazx)
with open("pingcount.json", "w") as file:
json.dump(data, file, indent=4)
await message.channel.send("1/2")
@bot.command()
async def help(ctx):
embed = discord.Embed(description="**,create** - Use To Create Slot\n**,add** - Use To Add User In Slot\n**,remove** - Use To Remove User In SLot\n**,renew** - Use To Renew Slot",color=0xFFFF00)
embed.set_thumbnail(url=ctx.guild.icon)
embed.set_author(name="Slot Bot Help Menu")
await ctx.send(embed=embed,delete_after=30)
@bot.command()
@commands.has_role(int(staff))
async def add(ctx,member: discord.Member=None, channel: discord.TextChannel = None):
rr = []
with open("./data.json","r") as rr:
rr = json.load(rr)
ftf = False
for x in rr:
for xx in x:
if (xx["channelid"] == channel.id):
ftf = True
if (ftf == False):
await ctx.send("Slot Not In DataBase")
return
if (member == False):
await ctx.reply("Member Not Found")
if (channel == False):
await ctx.reply("Channel Not Found")
await channel.set_permissions(member,view_channel=True, send_messages=True,mention_everyone=True)
await ctx.reply("successfully Added")
@bot.command()
@commands.has_role(int(staff))
async def renew(ctx,member: discord.Member = None,channel: discord.TextChannel=None,yoyo: int = None,cx=None):
rr = []
with open("./data.json","r") as rr:
rr = json.load(rr)
ftf = False
for x in rr:
for xx in x:
if (xx["channelid"] == channel.id):
ftf = True
if (ftf == False):
await ctx.send("Slot Not In DataBase")
return
print("ru")
if (member == None):
await ctx.reply("Member Not Found")
return
if (channel == None):
await ctx.reply("Channel Not Found")
return
if (cx.lower() == "d"):
yoyo = (yoyo * 24 * 60 * 60) + datetime.datetime.now().timestamp()
elif (cx.lower() == "m"):
yoyo = (yoyo * 30 * 24 * 60 * 60) + datetime.datetime.now().timestamp()
else:
await ctx.reply("Use valid Formate: ,add @user 1 m his Slot")
await channel.set_permissions(member,view_channel=True,send_messages=True,mention_everyone=True)
role = discord.utils.get(ctx.guild.roles, id=int(rid))
await member.add_roles(role)
print("ruw")
async for message in channel.history(limit=1000):
await message.delete()
dataz = {
"endtime": yoyo,
"userid": member.id,
"channelid": channel.id
},
try:
with open("data.json", "r") as file:
data = json.load(file)
except FileNotFoundError:
data = []
data.append(dataz)
with open("data.json", "w") as file:
json.dump(data, file,indent=4)
embed = discord.Embed(description="""Your Slot Rules""",color=0xFFFF00)
embed.set_author(name="Slot Rules")
embed.set_thumbnail(url=f"{ctx.guild.icon}")
await channel.send(embed=embed)
embed = discord.Embed(description=f'**Slot Owner:** {member.mention}\n**End:** <t:{int(yoyo)}:R>',color=0xFFFF00)
embed.set_footer(text=ctx.guild.name)
embed.set_author(name=member)
await channel.send(embed=embed)
await ctx.reply(f"successfully renew Slot {channel.mention}")
@bot.command()
@commands.has_role(int(staff))
async def remove(ctx,member: discord.Member=None, channel: discord.TextChannel = None):
rr = []
with open("./data.json","r") as rr:
rr = json.load(rr)
ftf = False
for x in rr:
for xx in x:
if (xx["channelid"] == channel.id):
ftf = True
if (ftf == False):
await ctx.send("Slot Not In DataBase")
return
if (member == False):
await ctx.reply("Member Not Found")
if (channel == False):
await ctx.reply("Channel Not Found")
await channel.set_permissions(member, send_messages=True,mention_everyone=False)
await ctx.reply("successfully removed")
@bot.command()
@commands.has_role(int(staff))
async def revoke(ctx,member: discord.Member=None, channel: discord.TextChannel = None):
rr = []
with open("./data.json","r") as rr:
rr = json.load(rr)
ftf = False
for x in rr:
for xx in x:
if (xx["channelid"] == channel.id):
ftf = True
if (ftf == False):
await ctx.send("Slot Not In DataBase")
return
if (member == False):
await ctx.reply("Member Not Found")
if (channel == False):
await ctx.reply("Channel Not Found")
await channel.set_permissions(member, send_messages=True,mention_everyone=False)
await ctx.reply("successfully removed")
@bot.command()
@commands.has_role(int(staff))
async def create(ctx,member: discord.Member=None,yoyo: int = None,cx=None,*,x=None):
if member == None:
await ctx.reply("User Not Found")
return
if yoyo == None:
await ctx.reply("Use valid Formate: ,add @user 1 m his Slot")
return
if cx == None:
await ctx.reply("Use valid Formate: ,add @user 1 m his Slot")
return
if (x == None):
x = member.display_name
overwrites = {
ctx.guild.default_role: discord.PermissionOverwrite(view_channel=True,send_messages=False),
member: discord.PermissionOverwrite(view_channel=True,send_messages=True,mention_everyone=True)
}
category = discord.utils.get(ctx.guild.categories, id=int(cid))
a = await ctx.guild.create_text_channel(x,category=category,overwrites=overwrites)
await a.set_permissions(ctx.guild.default_role, send_messages=False)
role = discord.utils.get(ctx.author.guild.roles, id=int(rid))
await member.add_roles(role)
embed = discord.Embed(description="""Your Slot Rules *""",color=0xFFFF00)
embed.set_author(name="Slot Rules")
embed.set_thumbnail(url=ctx.guild.icon)
await a.send(embed=embed)
if (cx.lower() == "d"):
yoyo = (yoyo * 24 * 60 * 60) + datetime.datetime.now().timestamp()
elif (cx.lower() == "m"):
yoyo = (yoyo * 30 * 24 * 60 * 60) + datetime.datetime.now().timestamp()
else:
await ctx.reply("Use valid Formate: ,add @user 1 m his Slot")
embed = discord.Embed(description=f'**Slot Owner:** {member.mention}\n**End:** <t:{int(yoyo)}:R>',color=0xFFFF00)
embed.set_footer(text=ctx.guild.name)
embed.set_author(name=member)
await a.send(embed=embed)
await ctx.reply(f"successfully Create Slot {a.mention}")
dataz = {
"endtime": yoyo,
"userid": member.id,
"channelid": a.id
},
try:
with open("data.json", "r") as file:
data = json.load(file)
except FileNotFoundError:
data = []
data.append(dataz)
with open("data.json", "w") as file:
json.dump(data, file,indent=4)
bot.run("Your bot Token")