Skip to content

Commit

Permalink
Migrate HepBoat integrations to Zeppelin
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanC committed Oct 25, 2023
1 parent a92dd5e commit 53bbe11
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
26 changes: 12 additions & 14 deletions components/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ async def EventMirror(
client: Client = tanjun.inject(type=Client),
config: Dict[str, Any] = tanjun.inject(type=Dict[str, Any]),
) -> None:
"""Handler for automatically mirroring HepBoat log archives."""
"""Handler for automatically mirroring Zeppelin log archives."""

if not ctx.author.is_bot:
return
elif int(ctx.author.id) != config["users"]["hepboat"]:
elif int(ctx.author.id) != config["users"]["zeppelin"]:
return
elif not hasattr(ctx.message, "content"):
return
Expand All @@ -257,36 +257,34 @@ async def EventMirror(
content: str = ctx.message.content.lower()
url: Optional[str] = None

if "prime-dash.hepbo.at/api/archive/" not in content:
if "zeppelin.gg/api/archives/" not in content:
return

try:
url = content.split("(<")[1].split(">)")[0]

if not url.startswith("https://"):
raise Exception(f"expected startswith https://, got {url}")
elif not url.endswith(".html"):
raise Exception(f"expected endswith .html, got {url}")
except Exception as e:
logger.opt(exception=e).debug("Failed to validate HepBoat log archive URL")
logger.opt(exception=e).debug("Failed to validate Zeppelin log archive URL")

return

data: Optional[str] = await Utility.GET(url.replace(".html", ".txt"))
data: Optional[str] = await Utility.GET(url)

if data is None:
return

result: str = Responses.Log("mirror", f"Mirror of HepBoat log archive <{url}>")
result: str = Responses.Log("mirror", f"Mirror of Zeppelin log archive <{url}>")
filename: Optional[str] = None
channelId: Optional[int] = None
users: List[str] = []

try:
filename = url.split("/")[-1].split(".")[0]
filename = url.split("/")[-1] + ".txt"
except Exception as e:
logger.opt(exception=e).debug(
f"Failed to determine HepBoat log archive filename"
f"Failed to determine Zeppelin log archive filename"
)

return
Expand All @@ -302,7 +300,7 @@ async def EventMirror(
users.append(user)
except Exception as e:
logger.opt(exception=e).debug(
f"Failed to determine relevant user and channel in HepBoat log archive"
f"Failed to determine relevant user and channel in Zeppelin log archive"
)

if channelId is not None:
Expand All @@ -319,7 +317,7 @@ async def EventMirror(
attachment=Bytes(data, f"{filename}.txt"),
)

logger.success(f"Mirrored HepBoat log archive {url}")
logger.success(f"Mirrored Zeppelin log archive {url}")


@component.with_listener(GuildMessageCreateEvent)
Expand All @@ -338,7 +336,7 @@ async def EventStoreThreadMessage(
if not channel:
return

# Disregard message deletions in regular channels. HepBoat is only
# Disregard message deletions in regular channels. Zeppelin is only
# missing thread message deletions.
if (channel.type != ChannelType.GUILD_PUBLIC_THREAD) and (
channel.type != ChannelType.GUILD_PRIVATE_THREAD
Expand Down Expand Up @@ -416,7 +414,7 @@ async def EventThreadDelete(
if not channel:
return

# Disregard message deletions in regular channels. HepBoat is only
# Disregard message deletions in regular channels. Zeppelin is only
# missing thread message deletions.
if (channel.type != ChannelType.GUILD_PUBLIC_THREAD) and (
channel.type != ChannelType.GUILD_PRIVATE_THREAD
Expand Down
2 changes: 1 addition & 1 deletion config_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"users": {
"owner": 1234567890,
"bot": 1234567890,
"hepboat": 1234567890
"zeppelin": 1234567890
},
"roles": {
"limit": true,
Expand Down

0 comments on commit 53bbe11

Please sign in to comment.