99
1010
1111class Codeforces (commands .Cog ):
12- cf_red = 0xff0000 # 2400+
13- cf_orange = 0xff8c00 # 2200 - 2399
14- cf_violet = 0xb200aa # 1900 - 2199
15- cf_blue = 0x0000ff # 1600 - 1899
16- cf_cyan = 0x03a89e # 1400 - 1599
17- cf_green = 0x008000 # 1200 - 1399
18- cf_gray = 0x808080 # 0 - 1199
12+ cf_red = 0xff0000 # 2400+
13+ cf_orange = 0xff8c00 # 2200 - 2399
14+ cf_violet = 0xb200aa # 1900 - 2199
15+ cf_blue = 0x0000ff # 1600 - 1899
16+ cf_cyan = 0x03a89e # 1400 - 1599
17+ cf_green = 0x008000 # 1200 - 1399
18+ cf_gray = 0x808080 # 0 - 1199
19+
1920 def __init__ (self , bot ):
2021 self .bot = bot
2122 # ----------------------------------------------------------------------------------------------------------------------
@@ -29,220 +30,43 @@ async def get_user(self, username):
2930
3031 @commands .command (name = "cf-handle" , aliases = ["cf-user" ], help = "shows details of the requested codeforces handle" )
3132 async def send_user (self , ctx , username ):
32- handle = await self .get_user (username )
33- if handle ["status" ]== "FAILED" :
33+ handle = await self .get_user (username )
34+ if handle ["status" ] == "FAILED" :
3435 async with ctx .typing ():
3536 embed = discord .Embed (title = "Error" ,
36- description = handle ["comment" ],
37- colour = 0xff0000 ,
38- timestamp = datetime .datetime .utcnow ())
37+ description = handle ["comment" ],
38+ colour = 0xff0000 ,
39+ timestamp = datetime .datetime .utcnow ())
3940 await ctx .send (embed = embed )
4041 return
4142 async with ctx .typing ():
4243 embed = discord .Embed (title = username ,
43- description = (handle ["result" ][0 ]["firstName" ] if "firstName" in handle ["result" ][0 ] else "" ) + " " + (handle ["result" ][0 ]["lastName" ] if "lastName" in handle ["result" ][0 ] else "" ),
44- colour = self .cf_red if handle ["result" ][0 ]["maxRating" ]>= 2400 else self .cf_orange if handle ["result" ][0 ]["maxRating" ]>= 2200 else self .cf_violet if handle ["result" ][0 ]["maxRating" ]>= 1900 else self .cf_blue if handle ["result" ][0 ]["maxRating" ]>= 1600 else self .cf_cyan if handle ["result" ][0 ]["maxRating" ]>= 1400 else self .cf_green if handle ["result" ][0 ]["maxRating" ]>= 1200 else self .cf_gray ,
45- timestamp = datetime .datetime .utcnow ())
46- embed .add_field (name = "City" , value = handle ["result" ][0 ]["city" ] if "city" in handle ["result" ][0 ] else "Unknown" , inline = True )
47- embed .add_field (name = "Country" , value = handle ["result" ][0 ]["country" ] if "country" in handle ["result" ][0 ] else "Unknown" , inline = True )
48- embed .add_field (name = "Friend of" , value = handle ["result" ][0 ]["friendOfCount" ], inline = True )
49- embed .add_field (name = "Max Rating" , value = handle ["result" ][0 ]["maxRating" ], inline = True )
50- embed .add_field (name = "Max Rank" , value = handle ["result" ][0 ]["maxRank" ], inline = True )
51- embed .add_field (name = "Organization" , value = handle ["result" ][0 ]["organization" ] if handle ["result" ][0 ]["organization" ]!= "" else "Unknown" , inline = True )
52- embed .add_field (name = "Rating" , value = handle ["result" ][0 ]["rating" ], inline = True )
53- embed .add_field (name = "Rank" , value = handle ["result" ][0 ]["rank" ], inline = True )
54- embed .add_field (name = "Last Online" , value = datetime .datetime .utcfromtimestamp (handle ["result" ][0 ]["lastOnlineTimeSeconds" ]).strftime ('%Y-%m-%d %H:%M:%S' ), inline = True )
44+ description = (handle ["result" ][0 ]["firstName" ] if "firstName" in handle ["result" ][0 ] else "" ) + " " + (
45+ handle ["result" ][0 ]["lastName" ] if "lastName" in handle ["result" ][0 ] else "" ),
46+ colour = self .cf_red if handle ["result" ][0 ]["maxRating" ] >= 2400 else self .cf_orange if handle ["result" ][0 ]["maxRating" ] >= 2200 else self .cf_violet if handle ["result" ][0 ]["maxRating" ] >= 1900 else self .cf_blue if handle [
47+ "result" ][0 ]["maxRating" ] >= 1600 else self .cf_cyan if handle ["result" ][0 ]["maxRating" ] >= 1400 else self .cf_green if handle ["result" ][0 ]["maxRating" ] >= 1200 else self .cf_gray ,
48+ timestamp = datetime .datetime .utcnow ())
49+ embed .add_field (name = "City" , value = handle ["result" ][0 ]["city" ]
50+ if "city" in handle ["result" ][0 ] else "Unknown" , inline = True )
51+ embed .add_field (name = "Country" , value = handle ["result" ][0 ]["country" ]
52+ if "country" in handle ["result" ][0 ] else "Unknown" , inline = True )
53+ embed .add_field (
54+ name = "Friend of" , value = handle ["result" ][0 ]["friendOfCount" ], inline = True )
55+ embed .add_field (name = "Max Rating" ,
56+ value = handle ["result" ][0 ]["maxRating" ], inline = True )
57+ embed .add_field (name = "Max Rank" ,
58+ value = handle ["result" ][0 ]["maxRank" ], inline = True )
59+ embed .add_field (name = "Organization" , value = handle ["result" ][0 ]["organization" ]
60+ if handle ["result" ][0 ]["organization" ] != "" else "Unknown" , inline = True )
61+ embed .add_field (
62+ name = "Rating" , value = handle ["result" ][0 ]["rating" ], inline = True )
63+ embed .add_field (
64+ name = "Rank" , value = handle ["result" ][0 ]["rank" ], inline = True )
65+ embed .add_field (name = "Last Online" , value = datetime .datetime .utcfromtimestamp (
66+ handle ["result" ][0 ]["lastOnlineTimeSeconds" ]).strftime ('%Y-%m-%d %H:%M:%S' ), inline = True )
5567 embed .set_thumbnail (url = handle ["result" ][0 ]["avatar" ])
5668 await ctx .send (embed = embed )
5769 # ----------------------------------------------------------------------------------------------------------------------
58-
59- # async def get_nasa(self):
60- # API_URL = "https://api.nasa.gov/planetary/apod?api_key=" + \
61- # str(os.getenv('NASA_API_KEY'))
62- # async with aiohttp.ClientSession() as session:
63- # async with session.get(API_URL) as resp:
64- # data_json = await resp.json()
65- # return (data_json)
66-
67- # @commands.command(name="apod", aliases=["napod", "astropic", "astropicotd"], help="sends astronomy pic of the day from NASA")
68- # async def send_nasa_pic_otd(self, ctx):
69- # embed = discord.Embed(title="NASA",
70- # description="Picture of the day",
71- # colour=0x0B3D91,
72- # timestamp=datetime.datetime.utcnow())
73- # embed.set_thumbnail(
74- # url="https://user-images.githubusercontent.com/63065397/156291255-4af80382-836c-4801-8b4f-47da33ea36c5.png")
75- # embed.set_footer(text="updated daily at 05:00:00 UTC [00:00:00 ET]")
76- # nasa_api = await self.get_nasa()
77- # embed.set_image(url=nasa_api["url"])
78- # embed.add_field(name="Date", value=nasa_api["date"], inline=False)
79- # embed.add_field(name="Image Title",
80- # value=nasa_api["title"], inline=False)
81- # await ctx.send(embed=embed)
82- # # ----------------------------------------------------------------------------------------------------------------------
83-
84- # async def get_covid19_details(self):
85- # API_URL = "https://api.covid19api.com/summary"
86- # async with aiohttp.ClientSession() as session:
87- # async with session.get(API_URL) as resp:
88- # data_json = await resp.json()
89- # return (data_json)
90-
91- # @commands.command(name="covid19", help="sends COVID-19 stats of the given country (global stats if country == null)")
92- # async def covid19_data(self, ctx, *args):
93- # countr = ""
94- # for arg in args:
95- # countr += arg + " "
96- # size = len(countr)
97- # country = countr[:size - 1]
98- # original = country
99- # found = False
100- # stats = await self.get_covid19_details()
101- # if country:
102- # for k in stats["Countries"]:
103- # if ((k["CountryCode"]).lower() == country.lower()) or ((k["Country"]).lower() == country.lower()):
104- # embed = discord.Embed(
105- # title=(k["Country"]).title(),
106- # description="COVID-19 Statistics",
107- # colour=0xff0000,
108- # timestamp=datetime.datetime.utcnow()
109- # )
110- # flag_url = "https://flagcdn.com/w640/" + \
111- # str(k["CountryCode"]).lower() + ".jpg"
112- # embed.set_thumbnail(url=flag_url)
113- # fields = [
114- # ("New Confirmed Cases", k["NewConfirmed"], True),
115- # ("Total Confirmed Cases", k["TotalConfirmed"], True),
116- # ("Country Code", k["CountryCode"], True),
117- # ("New Deaths", k["NewDeaths"], True),
118- # ("Total Deaths", k["TotalDeaths"], True),
119- # ("Report Time (UTC)", "Date: " +
120- # k["Date"][0:10] + " & Time: " + k["Date"][11:19], True),
121- # ]
122- # for n, v, i in fields:
123- # embed.add_field(name=n, value=v, inline=i)
124- # await ctx.send(embed=embed)
125- # found = True
126- # else:
127- # k = stats["Global"]
128- # embed = discord.Embed(
129- # title="Global",
130- # description="COVID-19 Statistics",
131- # colour=0xff0000,
132- # timestamp=datetime.datetime.utcnow()
133- # )
134- # embed.set_thumbnail(
135- # url="https://user-images.githubusercontent.com/63065397/156144079-6f90504d-ad48-4f2e-bec5-bae31cebd858.png"
136- # )
137- # fields = [
138- # ("New Confirmed Cases", k["NewConfirmed"], True),
139- # ("Total Confirmed Cases", k["TotalConfirmed"], True),
140- # ("New Deaths", k["NewDeaths"], True),
141- # ("Total Deaths", k["TotalDeaths"], True),
142- # ]
143- # for n, v, i in fields:
144- # embed.add_field(name=n, value=v, inline=i)
145- # await ctx.send(embed=embed)
146- # found = True
147- # if not found:
148- # embed = discord.Embed(
149- # title="Error",
150- # description="Country Not Found",
151- # colour=0xff0000
152- # )
153- # embed.add_field(name="Given Country Name",
154- # value=original, inline=True)
155- # await ctx.send(embed=embed)
156- # # ----------------------------------------------------------------------------------------------------------------------
157-
158- # async def get_meme(self):
159- # API_URL = "https://meme-api.herokuapp.com/gimme"
160- # async with aiohttp.ClientSession() as session:
161- # async with session.get(API_URL) as resp:
162- # data_json = await resp.json()
163- # return (data_json)
164-
165- # @commands.command(name="meme", aliases=["hehe"], help="sends a random meme")
166- # async def send_meme(self, ctx):
167- # embed = discord.Embed(title="MEME",
168- # colour=0xffee00,
169- # timestamp=datetime.datetime.utcnow())
170- # meme = await self.get_meme()
171- # embed.add_field(name="Post Link", value=meme["postLink"], inline=True)
172- # embed.add_field(name="Author", value=meme["author"], inline=True)
173- # embed.add_field(name="Header", value=meme["title"], inline=False)
174- # embed.set_image(url=meme["url"])
175- # embed.set_thumbnail(
176- # url="https://user-images.githubusercontent.com/63065397/156142184-0675cfee-2863-41d7-bef8-87f600a713b0.png")
177- # await ctx.send(embed=embed)
178- # # ----------------------------------------------------------------------------------------------------------------------
179-
180- # async def get_subreddit(self, subreddit):
181- # API_URL = str("https://www.reddit.com/r/" + subreddit + ".json")
182- # async with aiohttp.ClientSession() as session:
183- # async with session.get(API_URL) as resp:
184- # data_json = await resp.json()
185- # return (data_json)
186-
187- # @commands.command(name="reddit", aliases=["subreddit"], help="shows top headlines of the given subreddit")
188- # async def send_subreddit(self, ctx, subreddit, number: typing.Optional[int]):
189- # data = await self.get_subreddit(subreddit)
190- # if ('message' in data.keys()):
191- # if data['message'] == "Not Found":
192- # embed = discord.Embed(
193- # title="Status",
194- # colour=0xff0000,
195- # timestamp=datetime.datetime.utcnow()
196- # )
197- # embed.add_field(name="Error", value="Not Found", inline=True)
198- # embed.set_footer(text="given subreddit: "+subreddit)
199- # await ctx.send(embed=embed)
200- # return
201- # embed = discord.Embed(
202- # title="Error",
203- # description="API Request Fail",
204- # colour=0xff0000,
205- # timestamp=datetime.datetime.utcnow()
206- # )
207- # for key_i in data.keys():
208- # if key_i != 'message' and key_i != 'error':
209- # new_key = key_i
210- # embed.add_field(name='Error Code', value=str(
211- # data['error']), inline=True)
212- # embed.add_field(name='Error Message', value=str(
213- # data['message']), inline=True)
214- # if new_key is not None:
215- # embed.add_field(name=new_key.title(), value=str(
216- # data[new_key]), inline=True)
217- # embed.set_footer(text="given subreddit: "+subreddit)
218- # await ctx.send(embed=embed)
219- # else:
220- # embed = discord.Embed(title=str("/r/"+subreddit),
221- # colour=0xff5700, timestamp=datetime.datetime.utcnow())
222- # embed.set_thumbnail(
223- # url="https://user-images.githubusercontent.com/63065397/156344382-821872f3-b6e3-46e7-b925-b5f1a0821da8.png")
224- # i = 1
225- # if number is None:
226- # number = 5
227- # for head in (data['data']['children']):
228- # embed.add_field(
229- # name=str(i),
230- # value=head['data']['title'][0:127] + "...",
231- # inline=False
232- # )
233- # i += 1
234- # if i > number:
235- # break
236- # if i <= number:
237- # embed.add_field(
238- # name=str(i),
239- # value="No more data could be received...",
240- # inline=False
241- # )
242- # if number > 0:
243- # await ctx.send(embed=embed)
244- # return
245- # ----------------------------------------------------------------------------------------------------------------------
24670
24771
24872def setup (bot ):
0 commit comments