SHARE
TWEET

Untitled

a guest Jun 18th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. From 4b412a75b1ab7ce7080bc7c539dd189904e9c1a1 Mon Sep 17 00:00:00 2001
  2. From: popcornmix <popcornmix@gmail.com>
  3. Date: Tue, 18 Jun 2019 20:37:48 +0100
  4. Subject: [PATCH] Gymhunter: Add support for forms and sex or raid bosses
  5.  
  6. ---
  7.  GymHunter.py  | 25 ++++++++++++++++---------
  8.  MonsterMap.py |  8 +++++++-
  9.  utility.py    | 30 ++++++++++++++++++------------
  10.  3 files changed, 41 insertions(+), 22 deletions(-)
  11.  
  12. diff --git a/GymHunter.py b/GymHunter.py
  13. index b263835..fcfaa94 100755
  14. --- a/GymHunter.py
  15. +++ b/GymHunter.py
  16. @@ -180,19 +180,25 @@ def get_gym_name(self, id, kind):
  17.      i = None
  18.    return utility.portalnames(kind)[i] if i is not None else None
  19.  
  20. -async def raid_message(channel, end_time, until, title, lat, lon, content=None, mon=None, egg=None, move1=None, move2=None):
  21. +async def raid_message(channel, end_time, until, title, lat, lon, content=None, mon=None, egg=None, props=None):
  22.    if mon is None:
  23.      description="Hatching at {} ({}m {}s)".format(end_time.strftime("%H:%M:%S"), *divmod(until.seconds, 60))
  24.      thumb = "eggs/{}.png".format(egg)
  25.      name = "Level {} egg!".format(egg)
  26.    else:
  27. +    move1, move2, form, sex = utility.extract_props(props)
  28.      if move1 and move2:
  29.        description = "Prepare for {}/{}\n".format(move1, move2)
  30.      else:
  31.        description = ""
  32.      description += "Until {} ({}m {}s)".format(end_time.strftime("%H:%M:%S"), *divmod(until.seconds, 60))
  33.      thumb = "monsters/{:03}_000.png".format(mon)
  34. -    name = "{} Raid!".format(utility.get_mon_name(mon))
  35. +    name = utility.get_mon_name(mon)
  36. +    if sex:
  37. +     name += " " + sex
  38. +    if form:
  39. +     name += " ({})".format(form)
  40. +    name += " Raid!"
  41.  
  42.    thumbnail = "https://monsterimages.tk/v1.5/regular/{}".format(thumb)
  43.    await utility.post_map_internal(channel, None, lat, lon, None, want_image=True, title=title, description=description, thumbnail=thumbnail, name=name, content=content)
  44. @@ -854,7 +860,7 @@ class GymHunter:
  45.          await channel.send("No nests with {} types found".format(args[0].lower()))
  46.        return
  47.      now = datetime.datetime.now()
  48. -    egg, mon, end_time, until, move1, move2, args = utility.parse_egg_mon_time(inarg, now)
  49. +    egg, mon, end_time, until, props, args = utility.parse_egg_mon_time(inarg, now)
  50.      if len(args) > 0:
  51.        gym, error = utility.get_gym(" ".join(args), utility.portalnames('nest'), kind = "nest")
  52.        if error is not None:
  53. @@ -952,8 +958,9 @@ class GymHunter:
  54.        gyms.append(gym)
  55.      await channel.send("The current exgyms are {}".format(", ".join(gyms)))
  56.  
  57. -  async def raid_message_check(self, now, gym, egg, mon, end_time, until, move1, move2):
  58. -    print("raid_message_check: gym:{} mon:{} egg:{} move:{}/{} now:{} end:{} until:{}".format(gym, mon, egg, move1, move2, now, end_time, until))
  59. +  async def raid_message_check(self, now, gym, egg, mon, end_time, until, props):
  60. +    move1, move2, form, sex = utility.extract_props(props)
  61. +    print("raid_message_check: gym:{} mon:{} egg:{} props:{} now:{} end:{} until:{}".format(gym, mon, egg, props, now, end_time, until))
  62.      error = None
  63.      response = []
  64.      recents = await self.get_recent_raids(utility.channel(self.bot, 'raidsgymhunter'), utility.egg_time() + utility.boss_time() + utility.slop_time(), gym)
  65. @@ -1032,7 +1039,7 @@ class GymHunter:
  66.          content = utility.role(self.bot, 'exraidspawner') if spawner else None
  67.          title="{}. {} ({} {})".format(gym, address, utility.get_dist_as_str(distance), utility.get_cardinal_dir((lat, lon), self.cambridge))
  68.          print("{} ({}) [{}]".format(title, spawner, content))
  69. -        await raid_message(raid_channel, end_time, until, title, lat, lon, content, mon=mon, egg=egg, move1=move1, move2=move2)
  70. +        await raid_message(raid_channel, end_time, until, title, lat, lon, content, mon=mon, egg=egg, props=props)
  71.      return error, None if len(response) == 0 else "\n".join(response)
  72.  
  73.  
  74. @@ -1048,7 +1055,7 @@ class GymHunter:
  75.        return
  76.  
  77.      now = datetime.datetime.now()
  78. -    egg, mon, end_time, until, move1, move2, args = utility.parse_egg_mon_time(inarg, now)
  79. +    egg, mon, end_time, until, props, args = utility.parse_egg_mon_time(inarg, now)
  80.  
  81.      gym = error = response = None
  82.      if len(inarg) == 0:
  83. @@ -1059,7 +1066,7 @@ class GymHunter:
  84.        gym, error = utility.get_gym(" ".join(args), utility.portalnames('gym'))
  85.  
  86.      if gym:
  87. -      error, response =  await self.raid_message_check(now, gym.split(" (")[0], egg, mon, end_time, until, move1, move2)
  88. +      error, response =  await self.raid_message_check(now, gym.split(" (")[0], egg, mon, end_time, until, props)
  89.      if error is not None:
  90.        await channel.send(error)
  91.        return
  92. @@ -1092,7 +1099,7 @@ class GymHunter:
  93.        return
  94.      now = datetime.datetime.now()
  95.      now = now.replace(hour=8, minute=0, second=0)
  96. -    egg, mon, end_time, until, move1, move2, args = utility.parse_egg_mon_time(inarg, now)
  97. +    egg, mon, end_time, until, props, args = utility.parse_egg_mon_time(inarg, now)
  98.      if end_time is None:
  99.        await ctx.message.channel.send("I need a date and time for the ex raid")
  100.        return
  101. diff --git a/MonsterMap.py b/MonsterMap.py
  102. index 030e11a..b643117 100644
  103. --- a/MonsterMap.py
  104. +++ b/MonsterMap.py
  105. @@ -89,7 +89,13 @@ class MonsterMap:
  106.        if boss:
  107.          post = "!raid {} {} {}".format(boss, gym, raid_time.strftime('%H:%M'))
  108.          if move1 and move2:
  109. -          post += " {}/{}".format(move1.replace(" ", "_"), move2.replace(" ", "_"))
  110. +          post += " ‹{}/{}›".format(move1.replace(" ", "_"), move2.replace(" ", "_"))
  111. +        if r.get('pokemon_form_name') and len(r.get('pokemon_form_name')) > 0:
  112. +          post += " ‹{}›".format(r.get('pokemon_form_name'))
  113. +        if r.get('gender') and r.get('gender').lower() in ["♀", "female"]:
  114. +          post += " ‹♀›"
  115. +        if r.get('gender') and r.get('gender').lower() in ["♂","male"]:
  116. +          post += " ‹♂›"
  117.          print("{} ({})".format(post, len(current_raids)))
  118.          def pred(m):
  119.            return m.channel == channel
  120. diff --git a/utility.py b/utility.py
  121. index 5935e12..2f87a62 100644
  122. --- a/utility.py
  123. +++ b/utility.py
  124. @@ -94,6 +94,7 @@ re_replace = [
  125.        (re.compile(r'<:dra:417236951515529227>', flags=re.IGNORECASE),                r' dragonite '   ),
  126.        (re.compile(r'<:shuckle:451463019218599964>', flags=re.IGNORECASE),            r' shuckle '     ),
  127.        (re.compile(r'<:Slowpoke:497650972093448202>', flags=re.IGNORECASE),           r' slowpoke '    ),
  128. +      (re.compile(r'‹(.*?)›', flags=re.IGNORECASE),                                  r''    ),
  129.  ]
  130.  
  131.  def replace(inarg):
  132. @@ -113,7 +114,23 @@ def mangle_portal(gym):
  133.      gym = "SPM"
  134.    return gym
  135.  
  136. +def extract_props(props):
  137. +  move1 = move2 = form = sex = None
  138. +  for s in props:
  139. +    if s.count('/') == 1:
  140. +      move1 = s.split('/')[0]
  141. +      move2 = s.split('/')[1]
  142. +      move1=move1.replace("_", " ").title()
  143. +      move2=move2.replace("_", " ").title()
  144. +    elif s == "♀" or s == "♂":
  145. +      sex = s
  146. +    else:
  147. +      form = s
  148. +  return move1, move2, form, sex
  149. +
  150.  def parse_egg_mon_time(inarg, now):
  151. +  # grab any quoted props and remove them
  152. +  props = re.findall(r"‹(.*?)›", inarg, re.DOTALL)
  153.    inarg = replace(inarg)
  154.    args = list(filter(None, inarg.split(" ")))
  155.    mon = None
  156. @@ -121,8 +138,6 @@ def parse_egg_mon_time(inarg, now):
  157.    until = None
  158.    end_time = None
  159.    date = None
  160. -  move1= None
  161. -  move2 = None
  162.    pops = []
  163.    for i in range(len(args)-1, -1, -1):
  164.      eggnames = {'level1':1, 'level2':2, 'level3':3, 'level4':4, 'level5':5 }
  165. @@ -151,15 +166,6 @@ def parse_egg_mon_time(inarg, now):
  166.          pops.append(i)
  167.          continue
  168.  
  169. -    if args[i].count('/') == 1:
  170. -      m1 = args[i].split('/')[0]
  171. -      m2 = args[i].split('/')[1]
  172. -      if len(m1) >= 3 and len(m2) >= 3 and not is_int(m1) and not is_int(m2):
  173. -        move1=m1.replace("_", " ").title()
  174. -        move2=m2.replace("_", " ").title()
  175. -        pops.append(i)
  176. -        continue
  177. -
  178.    if end_time:
  179.      until = end_time - now
  180.  
  181. @@ -175,7 +181,7 @@ def parse_egg_mon_time(inarg, now):
  182.      egg = int(args[-1])
  183.      args.pop(-1)
  184.  
  185. -  return egg, mon, end_time, until, move1, move2, args
  186. +  return egg, mon, end_time, until, props, args
  187.  
  188.  def egg_time():
  189.    return 60 * 60
  190. --
  191. 2.11.0
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top