Skip to content

Commit

Permalink
fixed revolt sending mechanism, added revolt beta invite again
Browse files Browse the repository at this point in the history
  • Loading branch information
Deutscher775 committed Nov 18, 2024
1 parent 9c6e9eb commit 14ceca6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 38 deletions.
2 changes: 2 additions & 0 deletions src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ def invite(platform: str, token: Annotated[str, fastapi.Query(max_length=85)] =
return fastapi.responses.RedirectResponse(status_code=301, url="https://discord.com/oauth2/authorize?client_id=1230579871059804280&permissions=138046467089&scope=applications.commands+bot")
elif platform == "guilded-beta" and token in beta_users.TOKENS:
return fastapi.responses.RedirectResponse(status_code=301, url="https://www.guilded.gg/b/3f887186-82d5-4fe1-abbd-045748b125b3")
elif platform == "revolt-beta" and token in beta_users.TOKENS:
return fastapi.responses.RedirectResponse(status_code=301, url="https://app.revolt.chat/bot/01HZH72H3PZKTEG1ADQ5P2XBF5")
else:
return fastapi.responses.JSONResponse(status_code=400, content={"message": "Invalid platform."})

Expand Down
70 changes: 32 additions & 38 deletions src/astroidapi/sending_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ async def distribute(cls, endpoint, updated_json):
@classmethod
async def send_from_discord(cls, updated_json, endpoint, attachments: list = None):
try:
asyncio.create_task(cls.send_to_revolt(updated_json, endpoint, attachments))
asyncio.create_task(cls.send_to_guilded(updated_json, endpoint, attachments))
asyncio.create_task(cls.send_to_nerimity(updated_json, endpoint, attachments))
if updated_json["config"]["isbeta"] is True:
asyncio.create_task(cls.send_to_revolt(updated_json, endpoint, attachments))
except Exception as e:
raise errors.SendingError.SendFromDiscordError(e)

Expand Down Expand Up @@ -257,41 +258,34 @@ async def send_to_nerimity(cls, updated_json, endpoint, attachments: list = None

@classmethod
async def send_to_revolt(cls, updated_json, endpoint, attachments: list = None):
return True
#if updated_json["meta"]["read"]["revolt"] is False:
# if updated_json["meta"]["sender-channel"] in updated_json["config"]["channels"]["discord"]:
# channel_id = updated_json["config"]["channels"]["revolt"][updated_json["config"]["channels"]["discord"].index(updated_json["meta"]["sender-channel"])]
# elif updated_json["meta"]["sender-channel"] in updated_json["config"]["channels"]["guilded"]:
# channel_id = updated_json["config"]["channels"]["revolt"][updated_json["config"]["channels"]["guilded"].index(updated_json["meta"]["sender-channel"])]
# elif updated_json["meta"]["sender-channel"] in updated_json["config"]["channels"]["nerimity"]:
# channel_id = updated_json["config"]["channels"]["revolt"][updated_json["config"]["channels"]["nerimity"].index(updated_json["meta"]["sender-channel"])]
# else:
# raise errors.SendingError.ChannelNotFound(f"The channel {updated_json["meta"]["sender-channel"]} ({updated_json["meta"]["sender"]}) does not seem to be a registered channel on other platforms.")
#
# headers = {
# "Authorization" : f"Bot {config.REVOLT_TOKEN}"
# }
# url = f"https://api.revolt.chat/channels/{channel_id}/messages"
# payload = {
# "attachments": [None],
# "masquerade": {
# "avatar": updated_json["meta"]["message"]["author"]["avatar"],
# "name": updated_json["meta"]["message"]["author"]["name"]
#
# },
# "replies": [
# {
# "id": "",
# "mention": True
# }
# ],
# "embeds": [{}]
# }
# async with aiohttp.ClientSession() as session:
# async with session.post(url, headers=headers, json=payload) as r:
# await session.post(f"https://astroid.deutscher775.de/read/{endpoint}?token={config.MASTER_TOKEN}&read_revolt=true")
# await session.close()
# return True
#else:
# return False
if updated_json["meta"]["read"]["revolt"] is False:
if updated_json["meta"]["sender-channel"] in updated_json["config"]["channels"]["discord"]:
channel_id = updated_json["config"]["channels"]["revolt"][updated_json["config"]["channels"]["discord"].index(updated_json["meta"]["sender-channel"])]
elif updated_json["meta"]["sender-channel"] in updated_json["config"]["channels"]["guilded"]:
channel_id = updated_json["config"]["channels"]["revolt"][updated_json["config"]["channels"]["guilded"].index(updated_json["meta"]["sender-channel"])]
elif updated_json["meta"]["sender-channel"] in updated_json["config"]["channels"]["nerimity"]:
channel_id = updated_json["config"]["channels"]["revolt"][updated_json["config"]["channels"]["nerimity"].index(updated_json["meta"]["sender-channel"])]
else:
raise errors.SendingError.ChannelNotFound(f"The channel {updated_json["meta"]["sender-channel"]} ({updated_json["meta"]["sender"]}) does not seem to be a registered channel on other platforms.")

headers = {
"X-Bot-Token": f"{config.REVOLT_TOKEN}"
}
url = f"https://api.revolt.chat/channels/{channel_id}/messages"
payload = {
"masquerade": {
"avatar": updated_json["meta"]["message"]["author"]["avatar"],
"name": updated_json["meta"]["message"]["author"]["name"]
},
"content": updated_json["meta"]["message"]["content"]
}

async with aiohttp.ClientSession() as session:
async with session.post(url, headers=headers, json=payload) as r:
print(f"Sent to revolt. Response: {r.status}, {r.reason} {await r.text()}")
asyncio.create_task(read_handler.ReadHandler.mark_read(endpoint, "revolt"))
await session.close()
return True
else:
return False

0 comments on commit 14ceca6

Please sign in to comment.