-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
216 lines (163 loc) · 5.18 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
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
import os, random
import discord
from discord.ext import commands
import requests
import json, pickle
prefix = "get help"
def get_prefix(client, message):
global prefix
with open(
'prefixes.json', 'r'
) as f: # open and read the prefixes.json, assuming it's in the same file
prefixes = json.load(f)
prefix = prefixes[str(message.guild.id)] #load the json as prefixes
return prefixes[str(
message.guild.id)] #recieve the prefix for the guild id give
client = commands.Bot(command_prefix=(get_prefix), case_insensetive=True)
class NewHelpName(commands.MinimalHelpCommand):
async def send_pages(self):
destination = self.get_destination()
for page in self.paginator.pages:
emby = discord.Embed(description=page, colour=0xCCFF00)
emby.set_footer(text= "Made by @NotSujal#1616. Current version is maintained by @Roboticol#4533. Version- 1.0")
await destination.send(embed=emby)
client.help_command = NewHelpName()
def savedata(user, value):
with open("data.tcm", 'rb') as f:
data = pickle.load(f)
data[user]= value
with open("data.tcm", 'wb') as f:
pickle.dump(data, f)
def createuser(user):
if os.path.getsize("data.tcm") > 0:
with open("data.tcm", 'rb') as f:
data = pickle.load(f)
else:
data = {}
data[user] = 0
with open("data.tcm", 'wb') as f:
pickle.dump(data, f)
def deletedata(user):
with open("data.tcm", 'rb') as f:
data = pickle.load(f)
del data[user]
with open("data.tcm", 'wb') as f:
pickle.dump(data, f)
def getdata(user):
with open("data.tcm", 'rb') as f:
data = pickle.load(f)
value = data[user]
return value
#give command
@client.command(aliases= ["g"])
@commands.has_role("Challenge Creators")
@commands.cooldown(1,15)
async def give(ctx, mention: discord.User = None, points=0):
"""
Give Points to a Member
"""
user = mention.id
try:
player_pts = getdata(user)
except:
createuser(user)
player_pts = 0
pass
player_pts += points
savedata(user, player_pts)
await ctx.send(f"Successfully added {points} points to {mention.mention}.")
@client.command(aliases= ["pts","p"])
@commands.cooldown(1, 20)
async def points(ctx, mention: discord.User = None):
"""
View points of members
"""
if mention == None:
user = ctx.message.author.id
else:
user = mention.id
player_pts = getdata(user)
try:
await ctx.send(
f"{mention.mention} currently has **{player_pts}** points")
except:
await ctx.send(
f"{ctx.message.author.mention} currently has **{player_pts}** points"
)
#points error handler
@points.error
async def points_error_handler(ctx,error):
await ctx.send(f"```{error}```")
#leaderboard command
@client.command(aliases= ["lb"])
@commands.cooldown(1,20)
async def leaderboard(ctx):
"""
Leaderboard of the server
"""
with open("data.tcm","rb") as f:
data = pickle.load(f)
emby = discord.Embed(title="Leaderboard",colour= 0xBEBEBE)
rank =1
txt = ''
sort_orders = sorted(data.items(), key=lambda x: x[1], reverse=True)
for i in sort_orders:
#user = client.fetch_user(user)
user = await client.fetch_user(int(i[0]))
txt += "#" + str(rank) + " " + str(user) + " - "+ str(i[1]) + "\r\n"
rank += 1
emby.description = txt
await ctx.send(embed = emby)
#Leaderboard error handler
@leaderboard.error
async def leaderboard_error_handler(ctx,error):
await ctx.send(f"```{error}```")
#give command error
@give.error
async def givepoints_error_handler(ctx, error):
await ctx.send(f"```{error}```")
@client.event
async def on_ready():
global prefix
print("Successfully Logged In!")
activity = discord.Game(name="prefix is //", type=3)
await client.change_presence(status=discord.Status.idle, activity=activity)
@client.event
async def on_guild_join(guild):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
prefixes[str(guild.id)] = '//'
with open('prefixes.json', 'w') as f:
json.dump(prefixes, f, indent=4)
@client.event
async def on_guild_remove(guild):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
prefixes.pop(str(guild.id))
with open('prefixes.json', 'w') as f:
json.dump(prefixes, f, indent=4)
@client.command(aliases= ["latency"])
@commands.cooldown(1,5)
async def ping (ctx):
await ctx.send(f"Pong!, latency {round(client.latency*1000)} ms")
#prefix command
@client.command()
@commands.is_owner()
@commands.cooldown(1, 20)
async def prefix(ctx, prefix):
"""
Change the prefix of server
"""
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
prefixes[str(ctx.guild.id)] = prefix
with open('prefixes.json', 'w') as f:
json.dump(prefixes, f, indent=4)
await ctx.send(f'Prefix changed to: {prefix}')
#error handleing for prefix
@prefix.error
async def prefix_error_handler(ctx, error):
await ctx.send(f"```{error}```")
TOKEN = os.environ.get('TCM_TOKEN')
print(TOKEN)
client.run(TOKEN)