Skip to content

Commit fd10c83

Browse files
committed
Pet command, to lazy to make tests now.
1 parent 1ca8f96 commit fd10c83

File tree

27 files changed

+2784
-128
lines changed

27 files changed

+2784
-128
lines changed

bot/cogs/cookies/command/cookies.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from bot.apis import Emotes
1010
from bot.ext import Context, Response, commands
1111
from bot.models import Cookies, User
12-
from bot.utils import Check, SessionsCaches, StringTools
12+
from bot.utils import Check, RandomUtils, SessionsCaches, StringTools
1313

1414
from .translations import Translations
1515

@@ -23,6 +23,7 @@ def __init__(self, bot: Gorenmu) -> None:
2323
self.multiplicador = 1
2424
self.translations: Translations = Translations(bot, self)
2525
self.StringTools: StringTools = StringTools()
26+
self.RandomUtils: RandomUtils = RandomUtils()
2627
self.SessionsCaches: SessionsCaches = SessionsCaches(bot)
2728
self.emotes: Emotes = Emotes(bot, self.SessionsCaches.Emotes.session)
2829

@@ -234,12 +235,12 @@ async def slotmachine(self, ctx: Context, amount: str = "1"):
234235
stock_method = cookie.stock_all if is_all_mode else cookie.stock
235236

236237
if total_reward:
237-
emote = (await self.emotes.get_pog(ctx=ctx))[0]
238+
emote = await self.RandomUtils.pick_dynamic(self.emotes.get_pat(ctx, 10), "PogChamp", self.bot)
238239
total = total_reward * self.multiplicador
239240
await stock_method(amount_available) # NOQA
240241
suffix = translations.cookie_win_suffix(total, time_suffix)
241242
else:
242-
emote = (await self.emotes.get_sad(ctx=ctx))[0]
243+
emote = await self.RandomUtils.pick_dynamic(self.emotes.get_pat(ctx, 10), "peepoSad", self.bot)
243244
await stock_method(0) # NOQA
244245
suffix = translations.cookie_loss_suffix(time_suffix)
245246

bot/cogs/interactive/command/interactive.py

Lines changed: 39 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
from __future__ import annotations
22

3-
import datetime
4-
import hashlib
53
from typing import TYPE_CHECKING
64

75
from bot.apis import Emotes
86
from bot.ext import ChatMessage, Context, Response, commands
9-
from bot.utils import SessionsCaches, StringTools
7+
from bot.utils import RandomUtils, SessionsCaches, StringTools
108

119
from .translations import Translations
1210

1311
if TYPE_CHECKING:
1412
from bot.bot import Gorenmu
1513

1614

15+
# TODO: Change to random utils
16+
17+
1718
class InteractiveCmd(commands.CustomComponent):
1819
def __init__(self, bot: Gorenmu) -> None:
1920
self.bot = bot
2021
self.translations: Translations = Translations(bot, self)
2122
self.StringTools: StringTools = StringTools()
23+
self.RandomUtils: RandomUtils = RandomUtils()
2224
self.SessionsCaches: SessionsCaches = SessionsCaches(bot)
2325
self.Emotes: Emotes = Emotes(bot, self.SessionsCaches.Emotes.session)
2426

@@ -82,18 +84,14 @@ async def hug(self, ctx: Context, arg: str) -> Response:
8284
name = await self.generic_prepare(ctx, arg, "hug", translations)
8385
if isinstance(name, Response):
8486
return name
85-
emote = None
86-
if not self.bot.mock:
87-
emote = (await self.Emotes.get_hug(ctx, 1))[0]
88-
if not emote:
89-
emote = "🤗"
87+
emote = await self.RandomUtils.pick_dynamic(self.Emotes.get_hug(ctx, 1), "🤗", self.bot)
9088
return translations.options(user=name, emote=emote)
9189

9290
@commands.command(name="kiss", aliases=[])
9391
async def kiss(self, ctx: Context, arg: str) -> Response:
9492
translations = self.translations.Kiss
9593
name = await self.generic_prepare(ctx, arg, "kiss", translations)
96-
emote = (None if self.bot.mock else (await self.Emotes.get_kiss(ctx, 1))[0]) or "🤗"
94+
emote = await self.RandomUtils.pick_dynamic(self.Emotes.get_kiss(ctx, 1), "😘", self.bot)
9795
return name if isinstance(name, Response) else translations.options(user=name, emote=emote)
9896

9997
@commands.command(name="ship", aliases=["love"])
@@ -105,19 +103,13 @@ async def ship(self, ctx: Context, *, arg: str) -> Response:
105103
if name1 == name2:
106104
return translations.yourself()
107105

108-
seed_string = f"{name1.lower()}{name1.lower()}{datetime.datetime.now().strftime('%Y-%U')}"
109-
hash_digest = hashlib.sha256(seed_string.encode()).hexdigest()
110-
percentage = int(hash_digest, 16) % 101
111-
ship = name1[: len(name1) // 2 + 1] + name2[len(name2) // 2 + 1 :]
112-
emojis = ["😭", "😥", "💔", "😢", "😐", "😊", "❤", "💕", "💘", "😍", "PogChamp ❤"]
113-
emoji = emojis[round(percentage / 10)]
114-
return await translations.options(
115-
user1=name1,
116-
user2=name2,
117-
ship=ship,
118-
percentage=percentage,
119-
emoji=emoji,
106+
percentage = self.RandomUtils.get_seeded_percentage(
107+
name1.lower(), name2.lower(), time_basis=self.RandomUtils.TimeBasis.WEEKLY
120108
)
109+
emojis = ["😭", "😥", "💔", "😢", "😐", "😊", "❤", "💕", "💘", "😍", "PogChamp ❤"]
110+
emoji = self.RandomUtils.pick_by_percentage(emojis, percentage)
111+
ship_name = name1[: len(name1) // 2 + 1] + name2[len(name2) // 2 + 1 :]
112+
return await translations.options(user1=name1, user2=name2, ship=ship_name, percentage=percentage, emoji=emoji)
121113

122114
@commands.command(name="pat", aliases=[])
123115
async def pat(self, ctx: Context, *, arg: str) -> Response:
@@ -127,7 +119,7 @@ async def pat(self, ctx: Context, *, arg: str) -> Response:
127119
return name
128120
if name == ctx.author.name:
129121
return translations.yourself()
130-
emote = (None if self.bot.mock else (await self.Emotes.get_pat(ctx, 1))[0]) or "😚"
122+
emote = await self.RandomUtils.pick_dynamic(self.Emotes.get_pat(ctx, 1), "😚", self.bot)
131123
return await translations.options(name, emote)
132124

133125
@commands.command(name="penis", aliases=[])
@@ -138,9 +130,8 @@ async def penis(self, ctx: Context, *, arg: str | None = None) -> Response:
138130
name = await self.generic_prepare(ctx, arg, "penis", translations)
139131
if isinstance(name, Response):
140132
return name
141-
seed = f"{name.lower()}{datetime.datetime.now().strftime('%j')}"
142-
hash_val = int(hashlib.sha256(seed.encode()).hexdigest(), 16)
143-
length = (hash_val % 28) + 5
133+
percentage = self.RandomUtils.get_seeded_percentage(name.lower(), time_basis=self.RandomUtils.TimeBasis.DAILY)
134+
length = self.RandomUtils.map_percentage_to_range(percentage, min_value=5, max_value=32)
144135
emoji = "🤏" if length <= 13 else "🍌" if length <= 19 else "🍆"
145136
return await translations.options(name, length, emoji)
146137

@@ -152,39 +143,32 @@ async def slap(self, ctx: Context, *, arg: str) -> Response:
152143
return name
153144
if name == ctx.author.name:
154145
return translations.yourself()
155-
now = datetime.datetime.now()
156-
seed_string = f"{name.lower()}{now.strftime('%Y-%m-%d-%H-%M')}-{now.second // 30}"
157-
hash_digest = hashlib.sha256(seed_string.encode()).hexdigest()
158-
percentage = int(hash_digest, 16) % 101
159-
emoji = "👋"
160-
if not self.bot.mock:
161-
emojis = await self.Emotes.get_hit(ctx, amount=10)
162-
if len(emojis) > 2:
163-
emoji = emojis[round(percentage / 10)]
164-
return await translations.options(name, percentage, emoji)
146+
percentage = self.RandomUtils.get_seeded_percentage(
147+
name.lower(), time_basis=self.RandomUtils.TimeBasis.SECOND_30
148+
)
149+
emote = await self.RandomUtils.pick_dynamic_by_percentage(
150+
self.Emotes.get_hit(ctx, 1), "👋", percentage, self.bot
151+
)
152+
return await translations.options(name, percentage, emote)
165153

166154
@commands.command(name="tuck", aliases=[])
167155
async def tuck(self, ctx: Context, *, arg: str) -> Response:
168156
translations = self.translations.Tuck
169157
name = await self.generic_prepare(ctx, arg, "tuck", translations)
170158
if isinstance(name, Response):
171159
return name
172-
now = datetime.datetime.now()
173-
seed_string = f"{name.lower()}{now.strftime('%Y-%m-%d-%H-%M-%S')}-{now.second // 30}"
174-
hash_digest = hashlib.sha256(seed_string.encode()).hexdigest()
175-
emoji1 = "🙂"
176-
emoji2 = "🛏"
177-
if not self.bot.mock:
178-
base_value = int(hash_digest, 16) % 101
179-
emojis1 = await self.Emotes.get_okay(ctx, amount=10)
180-
if emojis1:
181-
index1 = (base_value * len(emojis1)) // 101
182-
emoji1 = emojis1[min(index1, len(emojis1) - 1)]
183-
184-
emojis2 = await self.Emotes.get_bed(ctx, amount=10)
185-
if emojis2:
186-
index2 = (base_value * len(emojis2)) // 101
187-
emoji2 = emojis2[min(index2, len(emojis2) - 1)]
160+
percentage = self.RandomUtils.get_seeded_percentage(
161+
name.lower(), time_basis=self.RandomUtils.TimeBasis.SECOND_30
162+
)
163+
emoji1 = await self.RandomUtils.pick_dynamic_by_percentage(
164+
self.Emotes.get_okay(ctx, 1), "🙂", percentage, self.bot
165+
)
166+
percentage = self.RandomUtils.get_seeded_percentage(
167+
name.lower(), time_basis=self.RandomUtils.TimeBasis.SECOND_30
168+
)
169+
emoji2 = await self.RandomUtils.pick_dynamic_by_percentage(
170+
self.Emotes.get_bed(ctx, 1), "🛏", percentage, self.bot
171+
)
188172
if name == ctx.author.name:
189173
return translations.yourself(emoji2)
190174
return await translations.options(name, emoji1, emoji2)
@@ -211,13 +195,13 @@ async def generic_prepare(self, ctx: Context, arg: str, action: str, translation
211195
return self.translations.GenericWait.already_in_action(action, name, ctx.author.name), None
212196
return name
213197

214-
async def generic_prepare_2_names(self, ctx: Context, arg: str, translation):
198+
async def generic_prepare_2_names(
199+
self, ctx: Context, arg: str, translation
200+
) -> tuple[str | None, None] | tuple[str | None, str | None]:
215201
name1, name2, _ = self.StringTools.safe_split(arg, 3)
216202
name1 = self.StringTools.str2name_or(name1)
217203
name2 = self.StringTools.str2name_or(name2)
218-
quick_responses = {
219-
ctx.bot.bot_user.name.lower(): translation.bot_nick(),
220-
}
204+
quick_responses = {ctx.bot.bot_user.name.lower(): translation.bot_nick()}
221205
if name1 in quick_responses:
222206
return quick_responses.get(name1), None
223207
elif name2 in quick_responses:

bot/cogs/pet/__init__.py

Whitespace-only changes.

bot/cogs/pet/command/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)