Skip to content

Commit

Permalink
Merge pull request #229 from Bot-detector/develop
Browse files Browse the repository at this point in the history
release
  • Loading branch information
extreme4all authored Aug 10, 2024
2 parents 55946f6 + 2929b24 commit 47d598f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/cogs/rsn_linking_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ async def link(self, ctx: Context, *, name: str):

# register verification
await config.api.post_discord_code(
discord_id=ctx.author.id, player_name=player.get("name"), code=code
discord_id=ctx.author.id, name=player.get("name"), code=code
)

# send user via pm the random code
Expand Down
21 changes: 13 additions & 8 deletions src/utils/bot_detector_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import aiohttp
from src import config
from src.utils.string_processing import to_jagex_name

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -198,6 +199,7 @@ async def create_player(self, name: str, debug: bool = False) -> None:
None
"""
url = self.url + "/v1/player"
name = to_jagex_name(name=name)
data = await self._webrequest(
url,
type="post",
Expand All @@ -223,7 +225,7 @@ async def get_player(self, name: str, debug: bool = False) -> dict:
"""
url = self.url + "/v1/player"
params = {
"player_name": name,
"player_name": to_jagex_name(name=name),
"token": self.token,
"row_count": 1,
"page": 1,
Expand All @@ -234,7 +236,7 @@ async def get_player(self, name: str, debug: bool = False) -> dict:
return data

# TODO: API design
async def get_discord_player(self, runescape_name: str) -> List[dict]:
async def get_discord_player(self, name: str) -> List[dict]:
"""
Get a player's Discord account by their RuneScape name.
Expand All @@ -243,22 +245,23 @@ async def get_discord_player(self, runescape_name: str) -> List[dict]:
player's Discord account information.
Args:
runescape_name (str): The RuneScape name of the player to get.
name (str): The RuneScape name of the player to get.
Returns:
List[dict]: A list of dictionaries containing the player's Discord
account information, or an empty list if the player was not found.
"""
name = to_jagex_name(name=name)
url = (
self.url
+ f"/discord/verify/player_rsn_discord_account_status/{self.token}/{runescape_name}"
+ f"/discord/verify/player_rsn_discord_account_status/{self.token}/{name}"
)
data = await self._webrequest(url, type="get")
return data

# TODO: API design
async def post_discord_code(
self, discord_id: str, player_name: int, code: str
self, discord_id: str, name: int, code: str
) -> List[dict]:
"""
Post a Discord verification code for a player.
Expand All @@ -274,8 +277,9 @@ async def post_discord_code(
Returns:
None
"""
name = to_jagex_name(name=name)
url = self.url + f"/discord/verify/insert_player_dpc/{self.token}"
data = {"discord_id": discord_id, "player_name": player_name, "code": code}
data = {"discord_id": discord_id, "player_name": name, "code": code}
await self._webrequest(url, type="post", json=data)

# TODO: API design
Expand Down Expand Up @@ -374,6 +378,7 @@ async def get_prediction(self, player_name: str, breakdown: bool = True) -> dict
player was not found.
"""
url = self.url + "/v1/prediction"
player_name = to_jagex_name(name=player_name)
params = {"name": player_name, "breakdown": int(breakdown)}
data = await self._webrequest(url, type="get", params=params)
return data
Expand Down Expand Up @@ -429,7 +434,7 @@ async def get_latest_sighting(self, name: str):
if the player was not found.
"""
url = self.url + f"/discord/get_latest_sighting/{self.token}"
params = {"player_name": name}
params = {"player_name": to_jagex_name(name=name)}
data = await self._webrequest(url, type="post", json=params)
return data

Expand All @@ -448,6 +453,6 @@ async def get_xp_gainz(self, name: str):
if the player was not found.
"""
url = self.url + f"/discord/get_xp_gains/{self.token}"
params = {"player_name": name}
params = {"player_name": to_jagex_name(name=name)}
data = await self._webrequest(url, type="post", json=params)
return data
3 changes: 3 additions & 0 deletions src/utils/string_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ def plus_minus(var, compare):
diff_control = "+"

return diff_control

def to_jagex_name(name: str) -> str:
return name.lower().replace("_", " ").replace("-", " ").strip()

0 comments on commit 47d598f

Please sign in to comment.