2626import hastebin
2727from operator import itemgetter
2828from errors import custom_error_handling
29+ import dateparser
2930
3031tessdata_dir_config = "--tessdata-dir 'C:\\ Program Files (x86)\\ Tesseract-OCR\\ tessdata' "
3132xtraconfig = "-l eng -c tessedit_char_blacklist=&|=+%#^*[]{};<> -psm 6"
@@ -1789,22 +1790,25 @@ async def timerset(ctx,timer):
17891790 now = datetime .datetime .utcnow () + datetime .timedelta (hours = server_dict [channel .server .id ]['offset' ])
17901791 timer_split = message .clean_content .lower ().split ()
17911792 del timer_split [0 ]
1792- if "am" in " " .join (timer_split ).lower () or "pm" in " " .join (timer_split ).lower ():
1793- try :
1794- start = datetime .datetime .strptime (" " .join (timer_split )+ " " + str (now .year ), '%m/%d %I:%M %p %Y' )
1795- if start .month < now .month :
1796- start = start .replace (year = now .year + 1 )
1797- except ValueError :
1798- await Meowth .send_message (channel , _ ("Meowth! Your timer wasn't formatted correctly. Change your **!timerset** to match this format: **MM/DD HH:MM AM/PM** (You can also omit AM/PM and use 24-hour time!)" ))
1799- return
1800- else :
1801- try :
1802- start = datetime .datetime .strptime (" " .join (timer_split )+ " " + str (now .year ), '%m/%d %H:%M %Y' )
1803- if start .month < now .month :
1804- start = start .replace (year = now .year + 1 )
1805- except ValueError :
1806- await Meowth .send_message (channel , _ ("Meowth! Your timer wasn't formatted correctly. Change your **!timerset** to match this format: **MM/DD HH:MM AM/PM** (You can also omit AM/PM and use 24-hour time!)" ))
1807- return
1793+ try :
1794+ start = dateparser .parse (" " .join (timer_split ).lower ())
1795+ except :
1796+ if "am" in " " .join (timer_split ).lower () or "pm" in " " .join (timer_split ).lower ():
1797+ try :
1798+ start = datetime .datetime .strptime (" " .join (timer_split )+ " " + str (now .year ), '%m/%d %I:%M %p %Y' )
1799+ if start .month < now .month :
1800+ start = start .replace (year = now .year + 1 )
1801+ except ValueError :
1802+ await Meowth .send_message (channel , _ ("Meowth! Your timer wasn't formatted correctly. Change your **!timerset** to match this format: **MM/DD HH:MM AM/PM** (You can also omit AM/PM and use 24-hour time!)" ))
1803+ return
1804+ else :
1805+ try :
1806+ start = datetime .datetime .strptime (" " .join (timer_split )+ " " + str (now .year ), '%m/%d %H:%M %Y' )
1807+ if start .month < now .month :
1808+ start = start .replace (year = now .year + 1 )
1809+ except ValueError :
1810+ await Meowth .send_message (channel , _ ("Meowth! Your timer wasn't formatted correctly. Change your **!timerset** to match this format: **MM/DD HH:MM AM/PM** (You can also omit AM/PM and use 24-hour time!)" ))
1811+ return
18081812 diff = start - now
18091813 total = (diff .total_seconds () / 60 )
18101814 if now <= start :
@@ -2028,7 +2032,8 @@ async def on_message(message):
20282032 firstsplit = re .split ("\n |\r " , messagelist .pop (0 ))
20292033 command = firstsplit .pop (0 ).lower ()
20302034 message .content = command + "\n " + "\n " .join (firstsplit ) + " " + " " .join (messagelist )
2031- await Meowth .process_commands (message )
2035+ if not message .author .bot :
2036+ await Meowth .process_commands (message )
20322037
20332038@Meowth .command (pass_context = True )
20342039@checks .cityexraidchannel ()
@@ -3355,7 +3360,7 @@ def check(msg):
33553360 if msg .channel == ctx .message .channel and ctx .message .author .id == msg .author .id :
33563361 if msg .attachments :
33573362 return True
3358- invitemsg = await Meowth .wait_for_message (author = ctx .message .author , check = check , timeout = 30 )
3363+ invitemsg = await Meowth .wait_for_message (author = ctx .message .author , check = check , timeout = 60 )
33593364 if invitemsg is not None :
33603365 ctx .message = invitemsg
33613366 await _invite (ctx )
@@ -3430,6 +3435,7 @@ async def recover(ctx):
34303435 name = channel .name
34313436 topic = channel .topic
34323437 egg = re .match ('level-[1-5]-egg' , name )
3438+ now = datetime .datetime .utcnow () + datetime .timedelta (hours = server_dict [server .id ]['offset' ])
34333439 if egg :
34343440 raidtype = 'egg'
34353441 chsplit = egg .string .split ('-' )
@@ -3446,11 +3452,11 @@ async def recover(ctx):
34463452 topicsplit = topic .split ('|' )
34473453 localhatch = datetime .datetime .strptime (topicsplit [0 ][:- 9 ], "Hatches on %B %d at %I:%M %p" )
34483454 utchatch = localhatch - datetime .timedelta (hours = server_dict [server .id ]['offset' ])
3449- exp = utchatch .replace (tzinfo = datetime .timezone .utc ).timestamp ()
3455+ exp = utchatch .replace (year = now . year , tzinfo = datetime .timezone .utc ).timestamp ()
34503456 manual_timer = True
34513457 pokemon = ''
34523458 if len (raid_info ['raid_eggs' ][egglevel ]['pokemon' ]) == 1 :
3453- pokemon = raid_info ['raid_eggs' ][egglevel ]['pokemon' ][0 ]
3459+ pokemon = get_name ( raid_info ['raid_eggs' ][egglevel ]['pokemon' ][0 ])
34543460 elif name .split ('-' )[0 ] in get_raidlist ():
34553461 raidtype = 'raid'
34563462 egglevel = 0
@@ -3465,7 +3471,7 @@ async def recover(ctx):
34653471 else :
34663472 localend = datetime .datetime .strptime (topic [:- 8 ], "Ends on %B %d at %I:%M %p" )
34673473 utcend = localend - datetime .timedelta (hours = server_dict [server .id ]['offset' ])
3468- exp = utcend .replace (tzinfo = datetime .timezone .utc ).timestamp ()
3474+ exp = utcend .replace (year = now . year , tzinfo = datetime .timezone .utc ).timestamp ()
34693475 manual_timer = True
34703476 elif name .split ('-' )[0 ] == 'ex' :
34713477 raidtype = 'egg'
@@ -3483,32 +3489,52 @@ async def recover(ctx):
34833489 topicsplit = topic .split ('|' )
34843490 localhatch = datetime .datetime .strptime (topicsplit [0 ][:- 9 ], "Hatches on %B %d at %I:%M %p" )
34853491 utchatch = localhatch - datetime .timedelta (hours = server_dict [server .id ]['offset' ])
3486- exp = utchatch .replace (tzinfo = datetime .timezone .utc ).timestamp ()
3492+ exp = utchatch .replace (year = now . year , tzinfo = datetime .timezone .utc ).timestamp ()
34873493 manual_timer = True
34883494 pokemon = ''
34893495 if len (raid_info ['raid_eggs' ]['EX' ]['pokemon' ]) == 1 :
3490- pokemon = raid_info ['raid_eggs' ]['EX' ]['pokemon' ][0 ]
3496+ pokemon = get_name ( raid_info ['raid_eggs' ]['EX' ]['pokemon' ][0 ])
34913497 else :
34923498 await Meowth .send_message (channel , "Meowth! I couldn't recognize this as a raid channel!" )
34933499 return
34943500 reportchannel = None
34953501 raidmessage = None
3496- rsvpidlist = []
3497- rsvpmentions = []
3498- async for message in Meowth .logs_from (channel , limit = 500 ):
3502+ trainer_dict = {}
3503+ async for message in Meowth .logs_from (channel , limit = 5 , reverse = True ):
34993504 if message .author .id == server .me .id :
35003505 if "Coordinate here" in message .content :
35013506 reportchannel = message .raw_channel_mentions [0 ]
35023507 raidmessage = message .id
3508+ async for message in Meowth .logs_from (channel , limit = 500 ):
3509+ if message .author .id == server .me .id :
35033510 if "is interested" in message .content or "on the way" in message .content or "at the raid" in message .content :
3504- if message .raw_mentions [0 ] not in rsvpidlist :
3505- rsvpidlist .append (message .raw_mentions [0 ])
3506- for trainer in rsvpidlist :
3507- user = ctx .message .server .get_member (trainer )
3508- rsvpmentions .append (user .mention )
3511+ if message .raw_mentions :
3512+ if message .raw_mentions [0 ] not in trainer_dict :
3513+ trainerid = message .raw_mentions [0 ]
3514+ if "is interested" in message .content :
3515+ status = "maybe"
3516+ if "on the way" in message .content :
3517+ status = "omw"
3518+ if "at the raid" in message .content :
3519+ status = "waiting"
3520+ if "trainers" in message .content :
3521+ messagesplit = message .content .split ()
3522+ if messagesplit [- 2 ].isdigit ():
3523+ count = int (messagesplit [- 2 ])
3524+ else :
3525+ count = 1
3526+ else :
3527+ count = 1
3528+
3529+ trainer_dict [trainerid ] = {'status' : status , 'count' : count }
3530+ else :
3531+ continue
3532+ else :
3533+ continue
3534+
35093535 server_dict [channel .server .id ]['raidchannel_dict' ][channel .id ] = {
35103536 'reportcity' : reportchannel ,
3511- 'trainer_dict' : {} ,
3537+ 'trainer_dict' : trainer_dict ,
35123538 'exp' : exp ,
35133539 'manual_timer' : manual_timer ,
35143540 'active' : True ,
@@ -3519,13 +3545,19 @@ async def recover(ctx):
35193545 'pokemon' : pokemon ,
35203546 'egglevel' : egglevel
35213547 }
3522- recovermsg = _ ("Meowth! This channel has been recovered! However, I can't remember if anyone RSVPed to this raid. Trainers {} could you help me remember your status? " ).format (", " .join (rsvpmentions ))
3548+ recovermsg = _ ("Meowth! This channel has been recovered! However, there may be some inaccuracies in what I remembered! Here's what I have:" )
3549+ bulletpoint = parse_emoji (ctx .message .server , ":small_blue_diamond:" )
3550+ recovermsg += "\n " + bulletpoint + await _interest (ctx )
3551+ recovermsg += "\n " + bulletpoint + await _otw (ctx )
3552+ recovermsg += "\n " + bulletpoint + await _waiting (ctx )
35233553 if not manual_timer :
35243554 if raidtype == "egg" :
35253555 action = "hatch"
35263556 elif raidtype == "raid" :
35273557 action = "end"
3528- recovermsg += "I'm also not sure when this {raidtype} will {action}, so please use **!timerset** if you can!" .format (raidtype = raidtype , action = action )
3558+ recovermsg += "\n " "I'm not sure when this {raidtype} will {action}, so please use **!timerset** if you can!" .format (raidtype = raidtype , action = action )
3559+ else :
3560+ recovermsg += "\n " + bulletpoint + await print_raid_timer (channel )
35293561 await Meowth .send_message (channel , recovermsg )
35303562 event_loop .create_task (expiry_check (channel ))
35313563
0 commit comments