diff --git a/data/Dailies.py b/data/Dailies.py index a01fa14..cf8f6c8 100644 --- a/data/Dailies.py +++ b/data/Dailies.py @@ -1,5 +1,7 @@ import json -import time +from datetime import datetime, timedelta + +import pytz from db import database @@ -8,27 +10,57 @@ with open("json/economy.json") as file: class Dailies: - def __init__(self, user_id, claimed_at, next_available): + def __init__(self, user_id): self.user_id = user_id self.amount = json_data["daily_reward"] - self.claimed_at = claimed_at - self.next_available = next_available + self.tz = pytz.timezone('US/Eastern') + + data = Dailies.get_data(user_id) + + if data[0] is not None: + self.claimed_at = datetime.fromisoformat(data[0]) + else: + # set date as yesterday to pretend as a valid claimed_at. + self.claimed_at = datetime.now(tz=self.tz) - timedelta(days=1) + + self.streak = int(data[1]) + + def refresh(self): + if self.streak_check(): + self.streak += 1 + else: + self.streak = 1 + + self.claimed_at = datetime.now(tz=self.tz).isoformat() - def push(self): query = """ - INSERT INTO dailies (user_id, amount, claimed_at, next_available) + INSERT INTO dailies (user_id, amount, claimed_at, streak) VALUES (?, ?, ?, ?) """ - - values = (self.user_id, self.amount, self.claimed_at, self.next_available) - + values = (self.user_id, self.amount, self.claimed_at, self.streak) database.execute_query(query, values) + def can_be_claimed(self): + if self.claimed_at is None: + return True + + else: + check_time = datetime.now(tz=self.tz).replace(hour=7, minute=0, second=0, microsecond=0) + + if self.claimed_at < check_time: + return True + + return False + + def streak_check(self): + yesterday = datetime.now(tz=self.tz) - timedelta(days=1) + return self.claimed_at.date() == yesterday.date() + @staticmethod - def cooldown_check(user_id): + def get_data(user_id): query = """ - SELECT next_available - FROM dailies + SELECT claimed_at, streak + FROM dailies WHERE id = ( SELECT MAX(id) FROM dailies @@ -36,11 +68,9 @@ class Dailies: ) """ - values = (user_id,) - result = database.select_query_one(query, values) - current_time = time.time() + try: + (claimed_at, streak) = database.select_query(query, (user_id,))[0] + except (IndexError, TypeError): + (claimed_at, streak) = None, 0 - if result and current_time < result: - return False, result - - return True, result + return claimed_at, streak diff --git a/db/tables.py b/db/tables.py index 3578cda..bbeab86 100644 --- a/db/tables.py +++ b/db/tables.py @@ -23,7 +23,7 @@ CREATE TABLE IF NOT EXISTS dailies ( user_id INTEGER, amount INTEGER, claimed_at REAL, - next_available REAL + streak INTEGER ) """ @@ -69,6 +69,4 @@ def sync_database(): database.execute_query(stats_slots) database.execute_query(stats_duel) - database.execute_query("DROP TABLE IF EXISTS dailies") - print("On startup: database synced.") diff --git a/json/economy.json b/json/economy.json index 7027d86..1355b39 100644 --- a/json/economy.json +++ b/json/economy.json @@ -2,7 +2,6 @@ "emotes_guild_id": 1038051105642401812, "rc_guild_id": 719227135151046699, "daily_reward": 50, - "daily_cooldown": 86400, "blackjack": { "emotes": { "hit_id": 1119262723285467156, diff --git a/json/strings.en-US.json b/json/strings.en-US.json new file mode 100644 index 0000000..781c778 --- /dev/null +++ b/json/strings.en-US.json @@ -0,0 +1,34 @@ +{ + "ping_latency": "Racu latency: {0} ms", + "restarting": "Restarting Racu...", + "restart_error": "Error executing the script: {0}", + "intro_muted": "You're muted in the Rave Cave. You can't perform this command.", + "intro_no_perms": "It seems that you don't have permission to do that!", + "intro_start_descr": "This command will serve as a questionnaire for you entry to {0}. Please keep your answers \"PG-13\"", + "intro_start_short": "Click the blue button to use the short form, this one has 6 questions.", + "intro_start_extended": "The green button will start the extended introduction, this one takes a bit longer but gives a more detailed portrayal of you.", + "intro_start_footer": "Please don't abuse this command.", + "intro_nickname": "How would you like to be identified in the server?", + "intro_age": "How old are you?", + "intro_location": "Where do you live?", + "intro_pronouns": "What are your preferred pronouns?", + "intro_likes": "Likes & interests.", + "intro_dislikes": "Dislikes.", + "intro_languages": "Which languages do you speak?", + "intro_sexuality": "What's your sexuality?", + "intro_rel_status": "What's your relationship status?", + "intro_extras": "EXTRAS: job status, zodiac sign, hobbies, etc. Tell us about yourself!", + "intro_recorded": "Recorded answer: {0}", + "intro_display_content": "Introduction by {0}", + "award_error": "Something went wrong. Check console.", + "give_error": "Something funky happened. Let Tess know.", + "gambling_error": "Something went wrong during the gambling command: {0}", + "duel_yourself": "You cannot duel yourself.", + "duel_bot": "You cannot duel a bit.", + "duel_opponent_no_balance": "Woops, you can't do that because **{}** has no money.", + "duel_all_in": " | opponent's all-in", + "duel_challenge": "**{0}** challenges {1} to a duel ({2}{3}{4})\nUse the buttons to accept/deny (challenge expires after 60s)", + "duel_results": "{1} wins **{2}{3}**\n{4} loses this bet.", + "duel_cancel": "**{0}** canceled the duel.", + "duel_time": "Time ran out." +} \ No newline at end of file diff --git a/modules/basic.py b/modules/basic.py index ac235de..f5ca1b9 100644 --- a/modules/basic.py +++ b/modules/basic.py @@ -104,7 +104,6 @@ class Basic(commands.Cog): if len(nickname) > 100: nickname = nickname[:100] nickname = nickname.replace("\n", " ") - print(f"New form info for {ctx.author.name}: nickname {nickname}") # START AGE await ctx.send(embed=embeds.simple_question_5("How old are you?"), @@ -116,7 +115,6 @@ class Basic(commands.Cog): if len(age) > 5: age = age[:5] age = age.replace("\n", " ") - print(f"New form info for {ctx.author.name}: age {age}") # START LOCATION view = interaction.LocationOptions(ctx) @@ -126,7 +124,6 @@ class Basic(commands.Cog): await view.wait() location = view.location - print(f"New form info for {ctx.author.name}: location {location}") if not view.location: await ctx.send(embed=embeds.no_time()) @@ -143,7 +140,6 @@ class Basic(commands.Cog): if len(pronouns) > 30: pronouns = pronouns[:30] pronouns = pronouns.replace("\n", " ") - print(f"New form info for {ctx.author.name}: pronouns {pronouns}") # START LIKES await ctx.send(embed=embeds.simple_question_300("Likes & interests"), @@ -155,7 +151,6 @@ class Basic(commands.Cog): if len(likes) > 300: likes = likes[:300] likes = likes.replace("\n", " ") - print(f"New form info for {ctx.author.name}: likes {likes}") # START DISLIKES await ctx.send(embed=embeds.simple_question_300("Dislikes"), @@ -167,7 +162,6 @@ class Basic(commands.Cog): if len(dislikes) > 300: dislikes = dislikes[:300] dislikes = dislikes.replace("\n", " ") - print(f"New form info for {ctx.author.name}: dislikes {dislikes}") # POST EXAMPLE EMBED AND FINAL IF APPROVED em = embeds.final_embed_short(ctx, nickname, age, location, pronouns, likes, dislikes) @@ -216,7 +210,6 @@ class Basic(commands.Cog): if len(nickname) > 100: nickname = nickname[:100] nickname = nickname.replace("\n", " ") - print(f"New form info for {ctx.author.name}: nickname {nickname}") # START AGE await ctx.send(embed=embeds.simple_question_5("How old are you?"), @@ -228,7 +221,6 @@ class Basic(commands.Cog): if len(age) > 5: age = age[:5] age = age.replace("\n", " ") - print(f"New form info for {ctx.author.name}: age {age}") # START LOCATION view = interaction.LocationOptions(ctx) @@ -238,7 +230,6 @@ class Basic(commands.Cog): await view.wait() location = view.location - print(f"New form info for {ctx.author.name}: location {location}") if not view.location: await ctx.send(embed=embeds.no_time()) @@ -256,7 +247,6 @@ class Basic(commands.Cog): if len(languages) > 30: languages = languages[:30] languages = languages.replace("\n", " ") - print(f"New form info for {ctx.author.name}: languages {languages}") # START PRONOUNS await ctx.send( @@ -269,7 +259,6 @@ class Basic(commands.Cog): if len(pronouns) > 30: pronouns = pronouns[:30] pronouns = pronouns.replace("\n", " ") - print(f"New form info for {ctx.author.name}: pronouns {pronouns}") # START SEXUALITY await ctx.send( @@ -282,7 +271,6 @@ class Basic(commands.Cog): if len(sexuality) > 30: sexuality = sexuality[:30] sexuality = sexuality.replace("\n", " ") - print(f"New form info for {ctx.author.name}: sexuality {sexuality}") # START RELATIONSHIP_STATUS await ctx.send( @@ -296,8 +284,6 @@ class Basic(commands.Cog): if len(relationship_status) > 30: relationship_status = relationship_status[:30] relationship_status = relationship_status.replace("\n", " ") - print( - f"New form info for {ctx.author.name}: relationship_status {relationship_status}") # START LIKES await ctx.send(embed=embeds.simple_question_300("Likes & interests"), @@ -309,7 +295,6 @@ class Basic(commands.Cog): if len(likes) > 300: likes = likes[:300] likes = likes.replace("\n", " ") - print(f"New form info for {ctx.author.name}: likes {likes}") # START DISLIKES await ctx.send(embed=embeds.simple_question_300("Dislikes"), @@ -322,7 +307,6 @@ class Basic(commands.Cog): if len(dislikes) > 300: dislikes = dislikes[:300] dislikes = dislikes.replace("\n", " ") - print(f"New form info for {ctx.author.name}: dislikes {dislikes}") # START EXTRA await ctx.send(embed=embeds.simple_question_300( @@ -337,7 +321,6 @@ class Basic(commands.Cog): if len(extra) > 300: extra = extra[:300] extra = extra.replace("\n", " ") - print(f"New form info for {ctx.author.name}: extra {extra}") # POST EXAMPLE EMBED AND FINAL IF APPROVED em = embeds.final_embed_extended(ctx, nickname, age, location, diff --git a/modules/economy.py b/modules/economy.py index dfdd6e2..aca6926 100644 --- a/modules/economy.py +++ b/modules/economy.py @@ -1,6 +1,5 @@ import json import os -import time import discord from discord.ext import commands @@ -158,38 +157,14 @@ class Economy(commands.Cog): ) @commands.check(universal.channel_check) async def daily(self, ctx): - (can_claim, next_claim) = Dailies.cooldown_check(ctx.author.id) - amount = json_data["daily_reward"] - current_time = time.time() + ctx_daily = Dailies(ctx.author.id) - # Currency handler - ctx_currency = Currency(ctx.author.id) - - if can_claim: - await ctx.respond(embed=economy_embeds.daily_claim(amount)) - - # give money - ctx_currency.add_cash(amount) - ctx_currency.push() - - # push daily to DB - daily = Dailies( - user_id=ctx.author.id, - claimed_at=current_time, - next_available=current_time + json_data["daily_cooldown"] - ) - daily.push() + if ctx_daily.can_be_claimed(): + ctx_daily.refresh() + await ctx.respond(embed=economy_embeds.daily_claim(ctx_daily.amount, ctx_daily.streak)) else: - cooldown = next_claim - current_time - - hours = int(cooldown // 3600) - minutes = int((cooldown % 3600) // 60) - seconds = int(cooldown % 60) - - cooldown_text = f"{str(hours).zfill(2)}:{str(minutes).zfill(2)}:{str(seconds).zfill(2)}" - - await ctx.respond(embed=economy_embeds.daily_wait(cooldown_text)) + await ctx.respond(embed=economy_embeds.daily_wait()) def setup(sbbot): diff --git a/sb_tools/economy_embeds.py b/sb_tools/economy_embeds.py index 37dd9f5..08222bd 100644 --- a/sb_tools/economy_embeds.py +++ b/sb_tools/economy_embeds.py @@ -329,19 +329,23 @@ def slots_finished(ctx, payout_type, multiplier, bet, results, sbbot): return embed -def daily_claim(amount): +def daily_claim(amount, streak): embed = discord.Embed( color=discord.Color.green(), description=f"You claimed your daily reward of **{cash_balance_name}{amount}**." ) + if streak > 1: + embed.set_footer(text=f"You're on a streak of {streak} days!") + return embed -def daily_wait(time): +def daily_wait(): embed = discord.Embed( color=discord.Color.red(), - description=f"You can't claim that yet! Please wait **{time}**." + description=f"You've already claimed your daily reward." ) + embed.set_footer(text="Reset is at 7 AM Eastern!") return embed