import re from discord.ext import commands from myBot import MyBot from .api import Api class ParseForIssues(commands.Cog): def __init__(self, bot: MyBot): self.bot = bot self.shortProjectNames = None self.api = Api(bot.config.YOUTRACK) @commands.Cog.listener() async def on_message(self, message): if message.author.id == self.bot.user.id: return content = message.content.lower() if self.shortProjectNames is None: projects = self.api.get_projects() self.shortProjectNames = [] for project in projects: self.shortProjectNames.append(project["shortName"].lower()) matches = re.findall(rf"(?:{'|'.join(map(re.escape, self.shortProjectNames))})-[0-9]+", content) for match in matches: await message.channel.send(self.api.URL + "/issue/" + match) async def setup(bot: MyBot): await bot.add_cog(ParseForIssues(bot))