Skip to content

Commit 59fc8fb

Browse files
AmbratolmAmbratolm
authored andcommitted
Improved board cog display
1 parent f2d59bc commit 59fc8fb

File tree

7 files changed

+70
-48
lines changed

7 files changed

+70
-48
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77

88
jobs:
99
deploy:
10+
if: github.repository == 'simple-works/ACT'
1011
runs-on: ubuntu-latest
1112

1213
steps:
Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
from discord import Color, Embed, Interaction, Member, User, app_commands
44
from discord.ext.commands import Cog
5-
from humanize import intcomma, naturaltime
5+
from humanize import intcomma, intword, metric, naturalsize, naturaltime, ordinal
66
from odmantic import query
7+
from tabulate import tabulate
78

89
from bot.main import ActBot
910
from db.actor import Actor
10-
from humanize import intword, metric, ordinal
1111

1212

1313
class Board(Cog, description="Allows players to view their data."):
@@ -49,11 +49,11 @@ async def profile(
4949
)
5050
embed.add_field(
5151
name="Experience",
52-
value=f"⏫ **{actor.xp}** / {actor.next_level_xp}\n{actor.xp_bar}",
52+
value=f"⏫ **{intcomma(actor.xp)}** / {actor.next_level_xp}\n{actor.xp_bar}",
5353
)
5454
embed.add_field(name="", value="", inline=False)
55-
embed.add_field(name="Gold", value=f"💰 **{actor.gold}**")
56-
embed.add_field(name="Items", value=f"🎒 **{len(actor.items)}**")
55+
embed.add_field(name="Gold", value=f"💰 **{intcomma(actor.gold)}**")
56+
embed.add_field(name="Items", value=f"🎒 **{intcomma(len(actor.items))}**")
5757
if isinstance(member, Member):
5858
embed.add_field(
5959
name="Joined",
@@ -105,22 +105,24 @@ async def leaderboard(self, interaction: Interaction):
105105
for i, actor in enumerate(actors):
106106
if i == 0:
107107
top_actor = actor
108-
name = f"{actor.display_name} ({actor.name})"
108+
name = f"{actor.display_name} @{actor.name}"
109109
rank = actor.rank_name
110110
level = str(actor.level)
111-
xp = intcomma(actor.xp)
112-
gold = intcomma(actor.gold)
113-
leaderboard_text += (
114-
f"# {(i+1):<2} {name}\n\t 🏆{rank:<2} 🏅{level}{xp} 💰{gold}\n\n"
115-
)
111+
xp = naturalsize(actor.xp, binary=False, gnu=True).replace("B", "")
112+
gold = naturalsize(actor.gold, binary=False, gnu=True).replace("B", "")
113+
leaderboard_text += f"#{(i+1):<2} {name}\n\t 🏆{rank:<2} 🏅{level:<2}{xp:<8} 💰{gold}\n\n"
116114
leaderboard_text += "```"
117115

118116
# Create embed
119117
embed = Embed(title="🏆 Leaderboard", color=Color.blue())
120-
top_member = guild.get_member(top_actor.id) or await guild.fetch_member(
121-
top_actor.id
122-
)
123-
if top_member:
124-
embed.set_thumbnail(url=top_member.display_avatar)
118+
try:
119+
top_member = guild.get_member(top_actor.id) or await guild.fetch_member(
120+
top_actor.id
121+
)
122+
if top_member:
123+
embed.set_thumbnail(url=top_member.display_avatar)
124+
except:
125+
pass
125126
embed.add_field(name="", value=leaderboard_text, inline=False)
126127
await interaction.followup.send(embed=embed)
128+
await interaction.followup.send(embed=embed)
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,9 @@ async def on_message(self, message: Message):
9393
@staticmethod
9494
def calculate_xp_reward(message: Message):
9595
word_count = 0
96-
message_content = message.content
9796

9897
# Exclude URLs
99-
message_content = re.sub(r"https?://\S+", "", message_content) # Remove URLs
100-
word_count += len(message_content.split())
98+
word_count += len(re.sub(r"https?://\S+", "", message.content).split())
10199

102100
# Handle embeds
103101
if message.embeds:

bot/cogs/filter_cog.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# * Filter Cog
1717
# ----------------------------------------------------------------------------------------------------
1818
class Filter(Cog, description="Filters blacklisted message content."):
19+
TOLERANCE = 0.99 # Between 0 and 1
1920
MAX_OFFENSES = 5
2021
GOLD_PENALTY = 500
2122

@@ -96,12 +97,12 @@ async def on_message(self, message: Message):
9697
embed.set_thumbnail(url=member.display_avatar.url)
9798
await censored_message.reply(embed=embed)
9899

99-
@staticmethod
100-
def get_profane_words(words: list[str]) -> list[str]:
100+
@classmethod
101+
def get_profane_words(cls, words: list[str]) -> list[str]:
101102
"""Get list of profane words from given list. If non found, get empty list."""
102103
predictions = predict_prob(words)
103104
profane_words = []
104105
for i, word in enumerate(words):
105-
if predictions[i] >= 0.8: # 1 means profane, 0 means clean
106+
if predictions[i] >= cls.TOLERANCE: # 1 means profane, 0 means clean
106107
profane_words.append(word)
107108
return profane_words

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ dependencies = [
1515
"odmantic>=1.0.2",
1616
"pydantic>=2.10.6",
1717
"python-dotenv>=1.0.1",
18+
"tabulate>=0.9.0",
1819
]
1920
#----------------------------------------------------------------------------------------------------
2021
[dependency-groups]

uv.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

z_test/_utils.ipynb

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,35 +63,43 @@
6363
"output_type": "stream",
6464
"text": [
6565
"Bad words:\n",
66-
"#0 Shoot: 75% (0.7548510274136075)\n",
67-
"#1 Ohh: 54% (0.5386781922217238)\n",
68-
"#2 We: 4% (0.03686327802381447)\n",
69-
"#3 will: 4% (0.03686327802381447)\n",
70-
"#4 test: 1% (0.008391262960679548)\n",
71-
"#5 CuNt: 100% (0.9999905004769302)\n",
72-
"#6 and: 4% (0.03686327802381447)\n",
73-
"#7 FuCk.: 100% (0.9999999999972535)\n",
74-
"#8 Maybe,: 3% (0.0326957016621721)\n",
75-
"#9 Yeah: 7% (0.07411545808528545)\n",
76-
"#10 bItch,: 100% (0.9999999999500696)\n",
77-
"#11 What?: 4% (0.03686327802381447)\n",
78-
"#12 This: 4% (0.03686327802381447)\n",
79-
"#13 Is: 4% (0.03686327802381447)\n",
80-
"#14 cring: 4% (0.03686327802381447)\n",
81-
"#15 DuMbAsS: 100% (0.9989037354074615)\n",
82-
"#16 Please: 4% (0.03686327802381447)\n",
83-
"#17 no: 4% (0.03686327802381447)\n",
84-
"#18 bad: 12% (0.1226694265167477)\n",
85-
"#19 words: 4% (0.03613674029367816)\n"
66+
"Shoot:\t 75 %\n",
67+
"shit:\t 100 %\n",
68+
"hate:\t 90 %\n",
69+
"ugly:\t 89 %\n",
70+
"sh:\t 85 %\n",
71+
"shut:\t 98 %\n",
72+
"up:\t 4 %\n",
73+
"Ohh:\t 54 %\n",
74+
"We:\t 4 %\n",
75+
"will:\t 4 %\n",
76+
"test:\t 1 %\n",
77+
"CuNt:\t 100 %\n",
78+
"and:\t 4 %\n",
79+
"FuCk.:\t 100 %\n",
80+
"Maybe,:\t 3 %\n",
81+
"Yeah:\t 7 %\n",
82+
"bItch,:\t 100 %\n",
83+
"What?:\t 4 %\n",
84+
"This:\t 4 %\n",
85+
"Is:\t 4 %\n",
86+
"cring:\t 4 %\n",
87+
"DuMbAsS:\t 100 %\n",
88+
"Please:\t 4 %\n",
89+
"no:\t 4 %\n",
90+
"bad:\t 12 %\n",
91+
"words:\t 4 %\n"
8692
]
8793
},
8894
{
8995
"data": {
9096
"text/plain": [
91-
"array([0.75485103, 0.53867819, 0.03686328, 0.03686328, 0.00839126,\n",
92-
" 0.9999905 , 0.03686328, 1. , 0.0326957 , 0.07411546,\n",
93-
" 1. , 0.03686328, 0.03686328, 0.03686328, 0.03686328,\n",
94-
" 0.99890374, 0.03686328, 0.03686328, 0.12266943, 0.03613674])"
97+
"array([0.75485103, 0.99999978, 0.90172162, 0.89174782, 0.84905614,\n",
98+
" 0.98060388, 0.03686328, 0.53867819, 0.03686328, 0.03686328,\n",
99+
" 0.00839126, 0.9999905 , 0.03686328, 1. , 0.0326957 ,\n",
100+
" 0.07411546, 1. , 0.03686328, 0.03686328, 0.03686328,\n",
101+
" 0.03686328, 0.99890374, 0.03686328, 0.03686328, 0.12266943,\n",
102+
" 0.03613674])"
95103
]
96104
},
97105
"execution_count": 12,
@@ -102,12 +110,12 @@
102110
"source": [
103111
"from profanity_check import predict, predict_prob\n",
104112
"\n",
105-
"content = \"Shoot Ohh We will test CuNt and FuCk. Maybe, Yeah bItch, What? This Is cring DuMbAsS Please no bad words \".split()\n",
113+
"content = \"Shoot shit hate ugly sh shut up Ohh We will test CuNt and FuCk. Maybe, Yeah bItch, What? This Is cring DuMbAsS Please no bad words \".split()\n",
106114
"predictions = predict_prob(content)\n",
107115
"\n",
108116
"print(\"Bad words:\")\n",
109117
"for i, prefiction in enumerate(predictions):\n",
110-
" print(f\"#{i}\", f\"{content[i]}:\", f\"{round(100 * prefiction)}%\", f\"({prefiction})\")\n",
118+
" print(f\"{content[i]}:\\t\", f\"{round(100 * prefiction)} %\")\n",
111119
"\n",
112120
"predictions"
113121
]

0 commit comments

Comments
 (0)