Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions arsene_wenger/cogs/facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
A cog to spit back random lines from files
"""

import asyncio
import random
from pathlib import Path

import discord
from discord import app_commands
Expand All @@ -21,9 +23,12 @@ def __init__(self, bot):

@commands.command(name="wengersucks")
async def wengerSucks(self, ctx):
with open("wengerSucks.txt", "r", encoding="utf-8") as f:
content = f.read()
def _read():
path = Path(__file__).parent.parent / "wengerSucks.txt"
with open(path, "r", encoding="utf-8") as f:
return f.read()

content = await asyncio.to_thread(_read)
for message in content.split("\n\n"):
return await ctx.send(message)

Expand All @@ -33,32 +38,32 @@ async def wengerSucks(self, ctx):
)
async def wengerFact(self, interaction: discord.Interaction):
await interaction.response.send_message(
embed=await self.getManagerFact("wenger")
embed=self.getManagerFact("wenger")
)

@app_commands.command(
name="unaifact",
description="Get a random fact about our former manager Unai Emery.",
)
async def unaiFact(self, interaction: discord.Interaction):
await interaction.response.send_message(embed=await self.getManagerFact("unai"))
await interaction.response.send_message(embed=self.getManagerFact("unai"))

@app_commands.command(
name="artetafact",
description="Get a random fact about our current manager Mikel Arteta",
)
async def artetaFact(self, interaction: discord.Interaction):
await interaction.response.send_message(
embed=await self.getManagerFact("arteta")
embed=self.getManagerFact("arteta")
)

async def getManagerFact(self, manager):
def getManagerFact(self, manager):
"""
Get a random fact and return it as a nice embed
:param manager:
:return:
"""
facts = f"facts/{manager}Facts.txt"
facts = Path(__file__).parent.parent / "facts" / f"{manager}Facts.txt"
try:
with open(facts, "r", encoding="utf-8") as f:
content = f.readlines()
Expand All @@ -73,6 +78,7 @@ async def getManagerFact(self, manager):
return embed
except FileNotFoundError:
print(f"{getTimestamp()}\nError reading file {facts}")
return None


async def setup(bot):
Expand All @@ -82,4 +88,4 @@ async def setup(bot):
This function is necessary for every cog file, multiple classes in the
same file all need adding and each file must have their own setup function.
"""
await bot.add_cog(FactsCog(bot))
await bot.add_cog(FactsCog(bot))
1 change: 1 addition & 0 deletions arsene_wenger/cogs/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Fixture(BaseModel):
competition: str
scoreline: str = ""
result: Literal["W", "L", "D"] | None = None

@computed_field
@property
def location_tag(self) -> str:
Expand Down
30 changes: 27 additions & 3 deletions arsene_wenger/cogs/link_fixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ def find_urls(self, message, domain):
pattern = re.compile(rf"https?://(?:www\.)?(?:{domain})/\S+")
return re.findall(pattern, message)

def twitter_web_viewer_url(self, url):
"""Extra url for twitter and x links that takes the original URL's number and converts it to
a twitter web viewer url.
example: if new_url is "https://www.fxtwitter.com/samimokbel_bbc/status/2092649709462564884?s=46"
the function should return "https://twitterwebviewer.com/?tweet=2092649709462564884"
"""
match = re.search(r"status/(\d+)", url)
if match:
tweet_id = match.group(1)
return f"https://twitterwebviewer.com/?tweet={tweet_id}"
return None

@commands.Cog.listener()
async def on_message(self, message):
if message.author.bot:
Expand All @@ -44,9 +56,21 @@ async def on_message(self, message):
url = original_urls[0]
new_url = self.rewrite_media_url(url, domain)
await message.edit(suppress=True)
await message.reply(
f"Fx'ed that for you! {new_url}", mention_author=False
)
if "fxtwitter.com" in new_url:
twitter_web_viewer = self.twitter_web_viewer_url(new_url)
if twitter_web_viewer:
await message.reply(
f"Fx'ed that for you! {new_url}\nTwitter Web Viewer version: <{twitter_web_viewer}>",
mention_author=False,
)
else:
await message.reply(
f"Fx'ed that for you! {new_url}", mention_author=False
)
else:
await message.reply(
f"Fx'ed that for you! {new_url}", mention_author=False
)


async def setup(bot):
Expand Down