@@ -278,12 +278,36 @@ async def elapsed(ctx, *, arg=""):
278278 await ctx .send (elapsedError ())
279279
280280
281- @bot .command ()
282- async def productivity (ctx , * , arg = "" ):
283- arg = arg .split ()
284- await ctx .send (str (getProductivity (ctx .author .id , arg [0 ]+ " " + arg [1 ], arg [2 ]+ " " + arg [3 ])))
281+ def prodError ():
282+ s = """Malformed argument! Use one of the following:
283+ p.productivity YYYY-MM-DD YYYY-MM-DD
284+ p.productivity YYYY-MM-DD HH:mm:SS HH:mm:SS
285+ p.productivity YYYY-MM-DD HH:mm:SS YYYY-MM-DD HH:mm:SS
286+ p.dayproductivity YYYY-MM-DD
287+ """
288+ return s
289+
290+ # Accurate to 3 decimal places because...
285291
286292
287293@bot .command ()
288- async def dayproductivity (ctx , * , arg = "" ):
289- await ctx .send (str (getDayProductivity (ctx .author .id , arg )))
294+ async def productivity (ctx , * , arg = "" ):
295+ arg = arg .split ()
296+ if (not (1 <= len (arg ) <= 4 )):
297+ await ctx .send (prodError ())
298+ else :
299+ if (len (arg ) == 1 ):
300+ arg = [arg [0 ], "00:00:00" , arg [0 ], "11:59:59" ]
301+ elif (len (arg ) == 2 ):
302+ arg = [arg [0 ], "00:00:00" , arg [1 ], "11:59:59" ]
303+ elif (len (arg ) == 3 ):
304+ arg = [arg [0 ], arg [1 ], arg [0 ], arg [2 ]]
305+ else : # len(arg)==4
306+ pass
307+ try :
308+ prod = float (getProductivity (
309+ ctx .author .id , arg [0 ]+ " " + arg [1 ], arg [2 ]+ " " + arg [3 ]))
310+ prod = round (1000 * prod )/ 10
311+ await ctx .send (f"Productivity for { arg [0 ]} { arg [1 ]} to { arg [2 ]} { arg [3 ]} was **{ prod } %**" )
312+ except (IndexError , ValueError ):
313+ await ctx .send (prodError ())
0 commit comments