-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.py
267 lines (250 loc) · 9.03 KB
/
bot.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
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
import os
from commands.cf_commands import cfupcoming_contest
import discord
import requests
from dotenv import load_dotenv
load_dotenv(".env")
# from keep_alive import keep_alive
from commands.cs_commands import csuser_info, csproblem_info, csupcoming, cspresent
from commands.cf_commands import cfuser_info, cfupcoming_contest
from commands.run import make_Token, count_problem
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
client = discord.Client(intents=intents)
# client=discord.Client(Intents.)
token = None
expires_at = None
@client.event
async def on_ready():
print("We have logged in as {0.user}".format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
msg = message.content
if msg.startswith("$Run"):
try:
try:
str2 = msg.split("$Input", 1)[0]
inp = msg.split("$Input ", 1)[1]
st = str2.split("$Run ", 1)[1]
except:
st = msg.split("$Run ", 1)[1]
inp = "NO INPUT"
url = "https://api.codechef.com/ide/run"
key2 = make_Token()
headers = {"Authorization": f"Bearer {key2}"}
data = {"sourceCode": st, "language": "PYTH 3.6", "input": inp}
response = requests.post(url, headers=headers, json=data)
code = response.json()
import time
time.sleep(2)
url = (
"https://api.codechef.com/ide/status?link="
+ code["result"]["data"]["link"]
)
headers = {"Authorization": "Bearer %s" % key2}
response = requests.get(url, headers=headers)
data = response.json()
myembed = discord.Embed(title="IDE Result", discription="", color=0x444444)
try:
myembed.add_field(
name="Input", value=data["result"]["data"]["input"], inline=False
)
except:
myembed.add_field(name="Input", value="s", inline=False)
try:
myembed.add_field(
name="Output", value=data["result"]["data"]["output"], inline=False
)
except:
myembed.add_field(name="Output", value="s", inline=False)
try:
myembed.add_field(
name="memory", value=data["result"]["data"]["memory"], inline=False
)
except:
myembed.add_field(name="memory", value="s", inline=False)
try:
myembed.add_field(
name="time", value=data["result"]["data"]["time"], inline=False
)
except:
myembed.add_field(name="time", value="s", inline=False)
await message.channel.send(embed=myembed)
except:
await message.channel.send("Erorr...")
if msg.startswith("$C+Run"):
try:
try:
str2 = msg.split("$Input", 1)[0]
inp = msg.split("$Input ", 1)[1]
st = str2.split("$C+Run ", 1)[1]
except:
st = msg.split("$C+Run ", 1)[1]
inp = "NO INPUT"
url = "https://api.codechef.com/ide/run"
key2 = make_Token()
headers = {"Authorization": f"Bearer {key2}"}
data = {"sourceCode": st, "language": "C++ 4.3.2", "input": inp}
response = requests.post(url, headers=headers, json=data)
code = response.json()
import time
time.sleep(2)
url = (
"https://api.codechef.com/ide/status?link="
+ code["result"]["data"]["link"]
)
headers = {"Authorization": "Bearer %s" % key2}
response = requests.get(url, headers=headers)
data = response.json()
myembed = discord.Embed(title="IDE Result", discription="", color=0x444444)
try:
myembed.add_field(
name="Input", value=data["result"]["data"]["input"], inline=False
)
except:
myembed.add_field(name="Input", value="s", inline=False)
try:
myembed.add_field(
name="Output", value=data["result"]["data"]["output"], inline=False
)
except:
myembed.add_field(name="Output", value="s", inline=False)
try:
myembed.add_field(
name="memory", value=data["result"]["data"]["memory"], inline=False
)
except:
myembed.add_field(name="memory", value="s", inline=False)
try:
myembed.add_field(
name="time", value=data["result"]["data"]["time"], inline=False
)
except:
myembed.add_field(name="time", value="s", inline=False)
await message.channel.send(embed=myembed)
except:
await message.channel.send("Erorr...")
if msg.startswith("$csupcoming"):
try:
await message.channel.send(embed=csupcoming())
except:
await message.channel.send(csupcoming())
if msg.startswith("$cspresent"):
try:
await message.channel.send(embed=cspresent())
except:
await message.channel.send(cspresent())
if msg.startswith("$csuser"):
try:
user_name = msg.split("$csuser ", 1)[1]
csuser_info(user_name)
await message.channel.send(embed=csuser_info(user_name))
except:
await message.channel.send(csuser_info(user_name))
if msg.startswith("$csproblem"):
user_name = msg.split("$csproblem ", 1)[1]
try:
await message.channel.send(embed=csproblem_info(user_name))
except:
await message.channel.send(csproblem_info(user_name))
if msg.startswith("$cscountproblem"):
try:
await message.channel.send(embed=count_problem())
except:
await message.channel.send(count_problem())
if msg.startswith("$help"):
myembed = discord.Embed(title="Help Commands", description="", color=0x444444)
myembed.add_field(
name="$csupcoming",
value="To Get The Info About Upcoming Codechef Contest\nEg. $csupcoming",
inline=False,
)
myembed.add_field(
name="$cspresent",
value="To Get The Info About Present Codechef Contest\nEg. $cspresent",
inline=False,
)
myembed.add_field(
name="$csuser",
value="To Get The Basic Info About Codechef User\nEg. $csuser gkcs",
inline=False,
)
myembed.add_field(
name="$cscountproblem",
value="To Get The Total Problem in CodeChef with respective of there complexity\nEg. $cscountproblem",
inline=False,
)
myembed.add_field(
name="$csproblem",
value="To Get The Info About The Problem Solved By Codechef User\nEg. $csproblem priyansh19077",
inline=False,
)
myembed.add_field(
name="$cfuser",
value="To Get The Info About The Codeforces User\nEg. $cfuser tourist",
inline=False,
)
myembed.add_field(
name="$cfupcoming",
value="To Get The Info About Upcoming Codeforces Contest\nEg. $cfupcoming",
inline=False,
)
myembed.add_field(
name="$Run",
value="""Virtual Compiler For Python\nEg.1)Without $Input\n$Run import json
x = {
"name": "John",
"age": 30,
"city": "New York"
}
y = json.dumps(x)
print(y)\n2)With $Input\n$Run INDIA=int(input())
for i in range(INDIA):print('Happy Independence Day') $Input 5""",
inline=False,
)
myembed.add_field(
name="$C+Run",
value="""Virtual Compiler For C++\nEg.1)Without $Input\n$C+Run #include <iostream>
using namespace std;
int main()
{
for (int i=0;i<5;i++)
{
cout<<"Hello World";
}
return 0;
}\n2)With $Input\n$C+Run #include <iostream>
using namespace std;
int main()
{
int a;
cin >> a;
for (int i=0;i<a;i++)
{
cout<<"Hello World";
}
return 0;
} $Input 5""",
inline=False,
)
await message.channel.send(embed=myembed)
if msg.startswith("$cfupcoming"):
try:
await message.channel.send(embed=cfupcoming_contest())
except:
await message.channel.send(cfupcoming_contest())
if msg.startswith("$cfuser"):
name = message.content.split("$cfuser ", 1)[1]
try:
await message.channel.send(embed=cfuser_info(name))
except:
await message.channel.send(cfuser_info(name))
if msg.startswith("$test"):
tem = msg.split("$test ", 1)[1]
tes = tem.split("$te ", 1)[1]
await message.channel.send("Y")
# keep_alive()
client.run(os.environ.get("DISCORD_BOT_TOKEN"))