Skip to content

Commit

Permalink
Patch 20200811
Browse files Browse the repository at this point in the history
Update liquipedia.py
  + Add live event
Update main.py
  + Split liquipedia command
  + Add discord invite link
Update README.md
  • Loading branch information
penut85420 committed Aug 11, 2020
1 parent 943f58c commit b19ecae
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
+ `!Nice` 可以召喚 Nice 的封號
+ `!Has` 可以召喚 Has 的粉絲團
+ `!Hui` 可以召喚輝哥的粉絲團
+ `!Nice比賽` 可以查詢 Nice 接下來的比賽
+ `!Has比賽` 可以查詢 Has 接下來的比賽
+ `!Rex比賽` 可以查詢 Rex 接下來的比賽
+ `!SoBad` 可以召喚師哥的粉絲團
+ `!阿吉` 恭迎吉孤觀音!
+ `!堅持` 你在堅持啥啊
Expand Down
20 changes: 16 additions & 4 deletions algs_fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,7 @@ async def cmd_summon(self, ctx, *arg):
return

result = search_next(player)
if result is not None:
await ctx.send(result)
else:
await ctx.send(f'沒有找到 {player} 最近的比賽 QQ')
await ctx.send(result)

@commands.command(name='nice')
async def nice(self, ctx):
Expand All @@ -123,6 +120,21 @@ async def nice(self, ctx):
]
await ctx.send(' GivePLZ '.join(nice_name) + ' GivePLZ ')

@commands.command(name='nice比賽')
async def cmd_nice_match(self, ctx):
msg = search_next('Nice')
await ctx.send(msg)

@commands.command(name='has比賽')
async def cmd_has_match(self, ctx):
msg = search_next('Has')
await ctx.send(msg)

@commands.command(name='rex比賽')
async def cmd_rex_match(self, ctx):
msg = search_next('Rex')
await ctx.send(msg)

@commands.command(name='has')
async def cmd_has(self, ctx):
await ctx.send('Has 臉書粉絲團 https://www.facebook.com/SC2Has-273980189818092/')
Expand Down
33 changes: 19 additions & 14 deletions liquipedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,28 @@ def search_match_list(player):
left_name, right_name = right_name, left_name
timestamp = table.find('span', attrs={'class': 'match-countdown'}).text.strip()
timestamp = pd.to_datetime(timestamp).to_pydatetime().replace(tzinfo=None)
if timestamp < dt.datetime.utcnow():
continue
tournament = table.find_all('div')[-1].text.strip()
return left_name, right_name, timestamp, tournament
is_live = True if timestamp < dt.datetime.utcnow() else False

return left_name, right_name, timestamp, tournament, is_live

return None

def search_next(player):
result = search_match_list(player)
if result is not None:
left, right, ts, tour = result
delta = ts - dt.datetime.utcnow()
seconds = delta.total_seconds()
minutes = int(seconds // 60 % 60)
hours = int(seconds // 60 // 60 % 24)
s = f'{hours} 小時 {minutes} 分鐘'
if delta.days:
s = f'{delta.days}{s}'

return f'距離 {left} 的下一場比賽「{tour}」對上 {right} 就在「{s}」之後'
return None
left, right, ts, tour, is_live = result
if not is_live:
delta = ts - dt.datetime.utcnow()
seconds = delta.total_seconds()
minutes = int(seconds // 60 % 60)
hours = int(seconds // 60 // 60 % 24)
s = f'{hours} 小時 {minutes} 分鐘'
if delta.days:
s = f'{delta.days}{s}'

return f'距離 {left} 的下一場比賽「{tour}」對上 {right} 就在「{s}」之後'

return f'{left} 正在「{tour}」與 {right} 進行對戰!'

return f'沒有找到 {player} 最近的比賽 QQ'

0 comments on commit b19ecae

Please sign in to comment.