Compare commits

...

3 Commits

Author SHA1 Message Date
fd4ac1d544
leaguefacts 2023-04-08 16:53:23 +10:00
73a31d7b99
add games 5.1 and 5.2 2023-04-08 16:53:08 +10:00
a8730ed579
leaguefacts 2023-04-08 09:50:32 +10:00
3 changed files with 80 additions and 6 deletions

61
bot.py
View File

@ -1,15 +1,18 @@
#!/usr/bin/env python3
from discord.utils import setup_logging
from typing import Optional
import argparse
import discord
import logging
import os.path
import random
import re
import shutil
import subprocess as sp
discord.utils.setup_logging()
_log = logging.getLogger("statbot")
_log = logging.getLogger(__name__)
_GAMES = "games.txt"
_DB = "holy-heck2.db"
@ -39,16 +42,50 @@ def _update_db():
class BotClient(discord.Client):
def __init__(
self,
intents: discord.Intents,
leaguefacts: Optional[list[str]] = None,
):
super().__init__(intents=intents)
self._leaguefacts = leaguefacts or []
async def on_ready(self):
_log.info(f"ready as {self.user}")
async def on_message(self, message: discord.Message):
content = message.content
if re.match("https://replay.pokemonshowdown.com/dl-.*", content):
_log.info(f"Recognised {content} as a League game")
_write_game(content)
if self.is_replay(message):
await self.on_replay(message)
elif self.is_leaguefact(message):
await self.on_leaguefact(message)
def is_replay(self, message: discord.Message) -> bool:
if re.match("https://replay.pokemonshowdown.com/dl-.*", message.content):
return True
return False
async def on_replay(self, message: discord.Message):
_log.info(f"Recognised {message.content} as a League game")
_write_game(message.content)
_update_db()
def is_leaguefact(self, message: discord.Message) -> bool:
return message.content.lower() == "notleaguefact"
async def on_leaguefact(self, message: discord.Message):
fact = self._select_leaguefact()
if fact:
await message.channel.send(f"Did you know? {fact}")
else:
await message.channel.send("There are no league facts.")
def _select_leaguefact(self) -> Optional[str]:
if not self._leaguefacts:
return None
random.seed()
return random.choice(self._leaguefacts)
def main():
parser = argparse.ArgumentParser()
@ -59,12 +96,26 @@ def main():
default="token",
help="file containing Discord API token",
)
parser.add_argument(
"-f",
"--facts",
metavar="FILE",
default="facts.txt",
help="file containing leagefacts",
)
args = parser.parse_args()
facts = []
if os.path.exists(args.facts):
with open(args.facts) as f:
for line in f:
facts.append(line)
intents = discord.Intents.default()
intents.message_content = True
client = BotClient(intents=intents)
client = BotClient(leaguefacts=facts, intents=intents)
with open(args.token_file) as f:
token = f.read().strip()
client.run(token, log_handler=None)

21
facts.txt Normal file
View File

@ -0,0 +1,21 @@
The Canberra Mamoswines have fielded the most unique Pokémon, with 13.
The Raleigh County Revavrooms have drafted the most unique Pokémon, with 18.
Barrow's Biggest Birds have made the most free agency exchanges so far, with 2 exchanges totalling 6 members.
Despite their name, Barrow's Biggest Birds do not currently possess any of largest birds in the league, and have only had at most three birds on their roster. They briefly had the tallest drafted bird, Quaquaval, but exchanged them in week 3.
The Raleigh County Revavrooms conducted the single largest free agency exchange in week 3, replacing eight members of their roster.
The Canberra Mamoswines are the slowest team, with an average of 64.5 Speed across their roster. The Raleigh County Revavrooms are the fastest, with an average of 83.3 Speed.
The Nimbasa City Ninjasks have the greatest Speed differential between their fastest and slowest members, of 112 points. Emily's Eevees and the Raleigh County Revavrooms are tied for the lowest differential, of 72 points.
The Buenos Aires Aggrons have largest roster, with 14 heads across their 10 members. However, the Raleigh County Revavrooms have the most bodies, with up to 13.
Emily's Eevees have the fewest limbs in the league, with only 24. Only two of their members are in the Amporphous egg group.
The Nimbasa City Ninjasks and the Canberra Mamoswines are tied for the most toxic rosters, with 2 Pokémon each capable of learning the move.
Cerluedge has more kills than all other Fire-type Pokémon combined that aren't some kind of Volcarona, as befitting of its ability, Flash Fire.
Landorus is the only Force of Nature that has not been drafted in season 3.
Emily's Eevees is the only roster to not have a Pokémon with more than 100 Speed.
Most teams have an average member cost of 12 points. Emily's Eevees and the Nimbasa City Ninjasks are tied for the most unevenly weighted teams, with a standard distribution of 6.87 points. The Raleigh County Revavrooms are the most evenly weighted, with a standard distribution of 5.29 points.
Only one team does not have a regional or alternate variant of a Pokémon on their roster: the Nimbasa City Ninjasks.
The East Midland Milotics have the fattest roster, claiming both Dondozo and Bellibolt.
Three teams have more than one 2-cost Pokémon in their rosters: Barrow's Biggest Birds, Mew York, and the Nimbasa City Ninjasks, each with 2 members. Five teams have no 2-cost Pokémon at all.
The San Francisco 549ers have the smallest Paldean representation in the league, with only one team member.
Moltres is the only legendary bird that has not been drafted in season 3.
Tyranitar, Metagross, and Kommo-o are the only pseudo-legendary Pokémon to not be drafted (either directly or as a variant) in season 3. Of these, only Metagross and Kommo-o are not available to be drafted.
Frosmoth is the biggest underdog in season 3 so far, having 4 knockouts to its name while only being a 2-point Pokémon.

View File

@ -18,3 +18,5 @@ https://replay.pokemonshowdown.com/dl-gen9paldeadexposthomedraft-33751
https://replay.pokemonshowdown.com/dl-gen9paldeadexposthomedraft-33998
https://replay.pokemonshowdown.com/dl-gen9paldeadexposthomedraft-34087
https://replay.pokemonshowdown.com/dl-gen9paldeadexposthomedraft-34672
https://replay.pokemonshowdown.com/dl-gen9paldeadexposthomedraft-36025
https://replay.pokemonshowdown.com/dl-gen9paldeadexposthomedraft-36096