Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #49 from is-a-dev/developments
Browse files Browse the repository at this point in the history
Developments
  • Loading branch information
MaskDuck authored May 18, 2024
2 parents a9f7023 + 9a385b2 commit b284655
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 2 deletions.
2 changes: 1 addition & 1 deletion _orangcbot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async def on_command_error(
bot.load_extension("extensions.delete_response")
bot.load_extension("extensions.nixwiki")
bot.load_extension("extensions.archwiki")

bot.load_extension("extensions.github")
if os.getenv("HASDB"):
bot.load_extension("extensions.tags_reworked")
# bot.load_extension("extensions.forum")
Expand Down
17 changes: 16 additions & 1 deletion _orangcbot/extensions/dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import TYPE_CHECKING

import nextcord
import whois
from dns import resolver as _dnsresolver
from nextcord.ext import commands

Expand Down Expand Up @@ -49,6 +50,8 @@ def __init__(self, url: str):
DigSelectOption("AAAA"),
DigSelectOption("MX"),
DigSelectOption("TXT"),
DigSelectOption("SRV"),
DigSelectOption("PTR"),
]
self._url: str = url
super().__init__(options=options, placeholder="What records do you want?")
Expand Down Expand Up @@ -99,7 +102,7 @@ class DNS(commands.Cog):
def __init__(self, bot: commands.Bot) -> None:
self._bot: commands.Bot = bot

@commands.command()
@commands.command(aliases=["dns"])
async def dig(self, ctx: commands.Context, url: str):
"""Dig an URL for its DNS records. Default to CNAME, if you want other then select in the dropdown."""
try:
Expand All @@ -114,6 +117,18 @@ async def dig(self, ctx: commands.Context, url: str):
msg = await ctx.send(embed=construct_embed(url, answer, "CNAME"), view=k)
k.update_msg(msg)

@commands.command()
async def urlwhois(self, ctx: commands.Context, url: str) -> None:
"""Dig an URL for WHOIS info."""
r = whois.whois(url)
await ctx.send(
embed=nextcord.Embed(
title=f"WHOIS info for {url}",
description=r.text,
color=nextcord.Color.random(),
)
)


def setup(bot: commands.Bot) -> None:
bot.add_cog(DNS(bot))
99 changes: 99 additions & 0 deletions _orangcbot/extensions/github.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
from __future__ import annotations

import re
from typing import List

import aiohttp
import nextcord
from nextcord.ext import commands


async def request(*args, **kwargs):
async with aiohttp.ClientSession() as session:
async with session.request(*args, **kwargs) as ans:
return await ans.json()


# so my LSP know it

request.__doc__ = aiohttp.ClientSession.request.__doc__


FULL_MATCH_ANY_REPO = r"(https:\/\/github.com\/)?([A-Za-z1-9-]+)\/([A-Za-z1-9-]+)(\/pull)?(#|\/)(?P<pr_id>\d+)"


MATCH_IS_A_DEV_ONLY = r"register#(\d+)"
PR_CHANNEL_ID = 1130858271620726784
STAFF_ROLE_ID = 1197475623745110109


class _PRRawObject(object):
def __init__(self, *, repo_owner: str, repo_name: str, pr_id: str) -> None:
self.repo_owner = repo_owner
self.repo_name = repo_name
self.pr_id = pr_id


class GitHub(commands.Cog):
@commands.Cog.listener()
async def on_message(self, message: nextcord.Message):
# if message.channel.id != PR_CHANNEL_ID: return
if message.author.bot:
return
full_matches: List[re.Match] = re.findall(FULL_MATCH_ANY_REPO, message.content)
print(full_matches)
is_a_dev_matches: List[re.Match] = re.findall(
MATCH_IS_A_DEV_ONLY, message.content
)
pr_list: List[_PRRawObject] = []
if len(full_matches) > 0:
for x in full_matches:
print(x)
repo_owner = x[1]
repo_name = x[2]
pr_id = x[5]
pr_list.append(
_PRRawObject(
repo_owner=repo_owner, repo_name=repo_name, pr_id=pr_id
)
)
# TODO: Fix is-a-dev-only regex

# elif len(is_a_dev_matches) > 0:
# for x in is_a_dev_matches:
# repo_owner = "is-a-dev"
# repo_name = "register"
# pr_id = x[0]
# pr_list.append(
# _PRRawObject(
# repo_owner=repo_owner, repo_name=repo_name, pr_id=pr_id
# )
# )

else:
if message.channel.id == PR_CHANNEL_ID:
if message.author.get_role(STAFF_ROLE_ID) is None:
await message.delete()

return
if message.channel.id == PR_CHANNEL_ID:
await message.edit(suppress=True)
embed_description = """"""
for pr in pr_list:
i = await request(
"GET",
f"https://api.github.com/repos/{pr.repo_owner}/{pr.repo_name}/issues/{pr.pr_id}",
)
embed_description += f"[(#{pr.pr_id}) {i['title']}]({i[
'html_url']})\n"
await message.channel.send(
embed=nextcord.Embed(
title="PR/Issue",
description=embed_description,
color=nextcord.Color.from_rgb(136, 225, 180),
)
)


def setup(bot: commands.Bot) -> None:
bot.add_cog(GitHub())
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ aiohttp
psycopg2-binary
nextcord-ext-help-commands
nextcord-ext-menus
python-whois

0 comments on commit b284655

Please sign in to comment.