Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions bases/bot_detector/discord_bot/cogs/mod_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
DISCORD_STAFF,
OWNER_ROLE,
VERIFICATION_STAFF,
build_kc_embed,
resolve_primary_rsn,
)
from discord.ext import commands
from discord.ext.commands import Cog, Context
Expand Down Expand Up @@ -79,3 +81,55 @@ async def admin_linked(self, ctx: Context, discord_id: str):
# check if there are any embeds left
if embeds != []:
await ctx.reply(embeds=embeds)

@commands.hybrid_command()
@commands.has_any_role(DISCORD_STAFF, VERIFICATION_STAFF, OWNER_ROLE)
async def admin_kc(self, ctx: Context, discord_id: str):
"""Shows the report (KC) stats of a user's linked accounts.

:param ctx: The context of the command.
:param discord_id: The Discord ID of the user to look up.
"""
debug = {
"author": ctx.author.name,
"author_id": ctx.author.id,
"msg": f"is using admin_kc for {discord_id}",
}
logger.debug(debug)
await ctx.typing()

assert self.deps.legacy_api is not None
linked_accounts = await self.deps.legacy_api.get_discord_links(
discord_id=str(discord_id)
)

if not linked_accounts:
await ctx.reply(
f"No linked OSRS accounts found for Discord ID {discord_id}."
)
return

linked_accounts = [
{"name": acc.get("name"), "primary_rsn": acc.get("primary_rsn")}
for acc in linked_accounts
if acc.get("Verified_status") == 1
]

if not linked_accounts:
await ctx.reply(
f"None of the accounts linked to {discord_id} are verified."
)
return

assert self.deps.public_api is not None
data = await self.deps.public_api.get_report_score(
names=[n["name"] for n in linked_accounts]
)

if not data:
await ctx.reply("No data found.")
return

primary_rsn = resolve_primary_rsn(linked_accounts)
embed = build_kc_embed(primary_rsn=primary_rsn, data=data)
await ctx.reply(embed=embed)
86 changes: 7 additions & 79 deletions bases/bot_detector/discord_bot/cogs/player_stats_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

import discord
from bot_detector.discord_bot.dependencies import BotDependencies
from bot_detector.discord_bot.utils import VERIFIED_PLAYER_ROLE
from bot_detector.discord_bot.utils import (
VERIFIED_PLAYER_ROLE,
build_kc_embed,
resolve_primary_rsn,
)
from discord import Color, Embed
from discord.ext import commands
from discord.ext.commands import Cog, Context
Expand Down Expand Up @@ -280,84 +284,8 @@ async def kc(self, ctx: Context):
await ctx.reply("No data found.")
return

reports_submitted = sum(d.count for d in data if not d.manual_detect)
possible_bans = sum(
d.count
for d in data
if not d.manual_detect and not d.confirmed_ban and d.possible_ban
)
confirmed_bans = sum(
d.count
for d in data
if not d.manual_detect and d.confirmed_ban and d.possible_ban
)

manual_confirmed_ban = sum(
d.count for d in data if d.manual_detect and d.confirmed_ban
)
manual_confirmed_player = sum(
d.count
for d in data
if d.manual_detect and not d.confirmed_ban and d.confirmed_player
)
manual_flags = sum(d.count for d in data if d.manual_detect)
confirmed_manual_flags = manual_confirmed_ban + manual_confirmed_player
manual_flag_accuracy = (
(manual_confirmed_ban / confirmed_manual_flags) * 100
if confirmed_manual_flags
else 0
)
logger.info(
f"{manual_flags=}, {confirmed_manual_flags=}, {manual_confirmed_ban=}, {manual_confirmed_player=}"
)

primary_rsn = None
for account in linked_accounts:
if account.get("primary_rsn") == 1:
primary_rsn = account.get("name")

if not primary_rsn and linked_accounts:
primary_rsn = linked_accounts[0].get("name")

embed = discord.Embed(title=f"{primary_rsn}'s Stats", color=0x00FF00)
embed.add_field(
name="Reports Submitted (Auto):",
value=f"{reports_submitted:,}",
inline=False,
)
embed.add_field(
name="Possible Bans (Auto):",
value=f"{possible_bans:,}",
inline=False,
)
embed.add_field(
name="Confirmed Bans (Auto):",
value=f"{confirmed_bans:,}",
inline=False,
)

if manual_flags:
embed.add_field(
name="Manual Flags:", value=f"{manual_flags:,}", inline=False
)
embed.add_field(
name="Manual Flag Accuracy:",
value=f"{manual_flag_accuracy:.2f}%",
inline=False,
)

embed.set_thumbnail(
url="https://user-images.githubusercontent.com/5789682/117364618-212a3200-ae8c-11eb-8b42-9ef5e225930d.gif"
)

if reports_submitted == 0:
embed.set_footer(
text=(
"If you have the plugin installed but are not seeing your KC increase, "
"you may have to disable Anonymous Mode in your plugin settings."
),
icon_url="https://raw.githubusercontent.com/Bot-detector/bot-detector/master/src/main/resources/warning.png",
)
primary_rsn = resolve_primary_rsn(linked_accounts)
embed = build_kc_embed(primary_rsn=primary_rsn, data=data)
await ctx.reply(embed=embed)

@commands.hybrid_command()
Expand Down
3 changes: 3 additions & 0 deletions bases/bot_detector/discord_bot/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
is_allowed_channel,
is_supporter,
)
from bot_detector.discord_bot.utils.kc_embed import build_kc_embed, resolve_primary_rsn
from bot_detector.discord_bot.utils.string_processing import (
get_random_id,
is_valid_rsn,
Expand Down Expand Up @@ -52,4 +53,6 @@
"is_supporter",
"BOOSTER_ROLE",
"SUPPORTER_ROLE",
"build_kc_embed",
"resolve_primary_rsn",
]
82 changes: 82 additions & 0 deletions bases/bot_detector/discord_bot/utils/kc_embed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import discord
from bot_detector.public_api import ReportScoreResponse


def resolve_primary_rsn(accounts: list[dict]) -> str | None:
for account in accounts:
if account.get("primary_rsn") == 1:
return account.get("name")
if accounts:
return accounts[0].get("name")
return None


def build_kc_embed(
primary_rsn: str | None, data: list[ReportScoreResponse]
) -> discord.Embed:
reports_submitted = sum(d.count for d in data if not d.manual_detect)
possible_bans = sum(
d.count
for d in data
if not d.manual_detect and not d.confirmed_ban and d.possible_ban
)
confirmed_bans = sum(
d.count
for d in data
if not d.manual_detect and d.confirmed_ban and d.possible_ban
)

manual_confirmed_ban = sum(
d.count for d in data if d.manual_detect and d.confirmed_ban
)
manual_confirmed_player = sum(
d.count
for d in data
if d.manual_detect and not d.confirmed_ban and d.confirmed_player
)
manual_flags = sum(d.count for d in data if d.manual_detect)
confirmed_manual_flags = manual_confirmed_ban + manual_confirmed_player
manual_flag_accuracy = (
(manual_confirmed_ban / confirmed_manual_flags) * 100
if confirmed_manual_flags
else 0
)

embed = discord.Embed(title=f"{primary_rsn}'s Stats", color=0x00FF00)
embed.add_field(
name="Reports Submitted (Auto):",
value=f"{reports_submitted:,}",
inline=False,
)
embed.add_field(
name="Possible Bans (Auto):",
value=f"{possible_bans:,}",
inline=False,
)
embed.add_field(
name="Confirmed Bans (Auto):",
value=f"{confirmed_bans:,}",
inline=False,
)

if manual_flags:
embed.add_field(name="Manual Flags:", value=f"{manual_flags:,}", inline=False)
embed.add_field(
name="Manual Flag Accuracy:",
value=f"{manual_flag_accuracy:.2f}%",
inline=False,
)

embed.set_thumbnail(
url="https://user-images.githubusercontent.com/5789682/117364618-212a3200-ae8c-11eb-8b42-9ef5e225930d.gif"
)

if reports_submitted == 0:
embed.set_footer(
text=(
"If you have the plugin installed but are not seeing your KC increase, "
"you may have to disable Anonymous Mode in your plugin settings."
),
icon_url="https://raw.githubusercontent.com/Bot-detector/bot-detector/master/src/main/resources/warning.png",
)
return embed
Loading