From d30bcb85ab254c616d2d3e072f28820f94a83a02 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Thu, 17 Oct 2024 15:03:14 -0700 Subject: [PATCH] Adding trader reset command to the bot --- app/cogs/cheeky_functions.py | 1 - app/cogs/tarkov.py | 45 ++++++++++++++++++++++++++++++++++++ app/cogs/warframe.py | 7 +----- app/warframe.py | 2 -- 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/app/cogs/cheeky_functions.py b/app/cogs/cheeky_functions.py index d6085b20..2fdf2e87 100755 --- a/app/cogs/cheeky_functions.py +++ b/app/cogs/cheeky_functions.py @@ -1,4 +1,3 @@ -from bs4 import BeautifulSoup from discord import option from discord.ext import commands import discord diff --git a/app/cogs/tarkov.py b/app/cogs/tarkov.py index fc74f439..c8323de7 100755 --- a/app/cogs/tarkov.py +++ b/app/cogs/tarkov.py @@ -18,6 +18,51 @@ class Tarkov(commands.Cog): tarkov = discord.SlashCommandGroup("tarkov", "Tarkov related commands") + @tarkov.command( + guild_ids=core_utils.my_guilds, + name="traders", + description="Time until trader resets", + ) + async def trader_resets(self, ctx: commands.Context): + import requests + from datetime import datetime + + from datetime import timezone + + await ctx.defer() + # Define the target date and time + embed = discord.Embed( + description="-------", color=discord.Color.blue(), type="rich" + ) + + embed.set_author(name="Trader Reset Times") + embed.set_thumbnail(url="https://i.ytimg.com/vi/8He5q7qOzNw/maxresdefault.jpg") + + times = requests.get( + "https://tarkovbot.eu/tools/pve/trader-resets/gettimes" + ).json() + + for time in times: + target_time = datetime.fromisoformat( + time["resetTime"].replace("000Z", "+00:00") + ) + + # Get the current time in UTC + current_time = datetime.now(timezone.utc) + + # Calculate the difference + time_difference = target_time - current_time + + # Convert the difference to minutes + minutes_until = time_difference.total_seconds() / 60 + + embed.add_field( + name=time["name"], + value=f"{minutes_until:.2f} minutes", + inline=True, + ) + await ctx.send_followup(embed=embed) + @tarkov.command( guild_ids=core_utils.my_guilds, name="lottery", diff --git a/app/cogs/warframe.py b/app/cogs/warframe.py index b49f7eae..d90bb6fb 100755 --- a/app/cogs/warframe.py +++ b/app/cogs/warframe.py @@ -1,11 +1,6 @@ -from bs4 import BeautifulSoup -from discord import option -from discord.ext import commands, tasks +from discord.ext import commands import discord -import json -import os import queue -import requests import threading import core_utils diff --git a/app/warframe.py b/app/warframe.py index b9a19c43..4815eccc 100755 --- a/app/warframe.py +++ b/app/warframe.py @@ -1,8 +1,6 @@ from bs4 import BeautifulSoup -import json import queue import requests -import threading def query_wiki(letter, q: queue.Queue):