summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Liu <joshua.liu@sourceobby.com>2025-11-22 13:09:03 -0500
committerJoshua Liu <joshua.liu@sourceobby.com>2025-11-22 13:09:03 -0500
commita8341cc036256b9e7708302b9a0947c45191c4fc (patch)
tree27dc2b8cf677d3733458dedd50138619924c6444
parent8718db0da478bf1db1edd4a5ca5e310c9f4a9a39 (diff)
feat: created RobloxAPI for making calls to the roblox marketplace API, and refactored bigresult.py to make use of itfeature/RobloxAPI
-rw-r--r--RobloxAPI/main.py31
-rw-r--r--bigresult.py48
2 files changed, 75 insertions, 4 deletions
diff --git a/RobloxAPI/main.py b/RobloxAPI/main.py
new file mode 100644
index 0000000..6c817c5
--- /dev/null
+++ b/RobloxAPI/main.py
@@ -0,0 +1,31 @@
+import json
+import urllib.request
+
+class RobloxMarketPlaceAPI:
+ def __init__(self):
+ self.response = None
+ self.request = ""
+ self.API_BASE = "https://catalog.roblox.com/v1/search/items/details?"
+ self.item = 0
+
+ def send_request(self) -> bool:
+ request = self.API_BASE + self.request
+ try:
+ self.response = json.loads(urllib.request.urlopen(request, timeout=30).read())
+ return True
+ except:
+ return False
+
+ def read_response(self) -> dict:
+ res = None
+ for key in self.response["data"]:
+ if self.response["data"][key]["id"] == self.item:
+ res = self.response["data"][key]
+ break
+ return res
+
+ def configure_request(self, category, argument):
+ if self.category == "TARGET":
+ self.item = argument
+ argument = argument.replace(" ", "%20")
+ self.request = self.request + f"&{category}={argument}" \ No newline at end of file
diff --git a/bigresult.py b/bigresult.py
index 8016d76..adab920 100644
--- a/bigresult.py
+++ b/bigresult.py
@@ -1,10 +1,17 @@
+from time import sleep
import discord
import dotenv
from discord.ext import commands
import random
import threading
-import time
+import datetime
from functools import partial, wraps
+import json
+import urllib.request
+from RobloxAPI.main import RobloxMarketPlaceAPI
+import math
+
+
# from commands.funny import BigCommands
class BigResultPlus(commands.Bot):
@@ -20,6 +27,10 @@ class BigResultPlus(commands.Bot):
"teachmethebigresult": BigResultPlus.teachbigresult,
"ivotedfor": BigResultPlus.voot,
}
+ self.daily_pi_update_msg = "rise and shine bastards, server time is ;;date;; and the Pumpkin Pi is ;;robux;; and Avi has ;;profit?;; ;;amount;; robux"
+ self.roblox_api_url = "https://catalog.roblox.com/v1/search/items/details?"
+ self.pumpkin_pi_buy = 800
+ self.robloxAPI = RobloxMarketPlaceAPI()
# intents = discord.Intents.all()
# self.client = commands.Bot(intents=intents, command_prefix="!") # This represents our connection with Discord
@@ -27,6 +38,32 @@ class BigResultPlus(commands.Bot):
for key in self.COMMANDS:
super().command(name=key)(wraps(self.COMMANDS[key])(partial(self.COMMANDS[key], self)))
+ def riseandshine(self):
+ next_day = datetime.datetime.now()
+ next_day = next_day.replace(day=next_day.day + 1)
+ self.robloxAPI.configure_request("CreatorName", "Roblox")
+ self.robloxAPI.configure_request("Keyword", "Pumpkin Pi")
+ self.robloxAPI.configure_request("Limit", "10")
+ self.robloxAPI.configure_request("TARGET", 16986805)
+
+ while True:
+ today = datetime.datetime.now()
+ if (today < next_day):
+ sleep(60*60)
+ next_day = today.replace(day=today.day + 1)
+
+ if not self.robloxAPI.send_request():
+ return
+
+ pumpkinpi = self.robloxAPI.read_response()
+ update_msg = self.daily_pi_update_msg.replace(";;date;;", today.isoformat())
+ update_msg = update_msg.replace(";;robux;;", f"{pumpkinpi["lowestPrice"]}")
+ if self.pumpkin_pi_buy - pumpkinpi["lowestPrice"] < 0:
+ update_msg = update_msg.replace(";;profit?;;", "gained")
+ else:
+ update_msg = update_msg.replace(";;profit?;;", "lost (LOL)")
+ update_msg = update_msg.replace(";;amount;;", f"{abs(self.pumpkin_pi_buy - pumpkinpi["lowestPrice"])}")
+ self.send_msg(update_msg, 0)
# @client.command(name="snipe")
@@ -78,7 +115,7 @@ class BigResultPlus(commands.Bot):
saved = message.content
await channel_sent.send("BOOM :sunglasses: :fire:")
await message.delete()
- time.sleep(2)
+ sleep(2)
await channel_sent.send(saved)
self.snipe_active = False
@@ -140,14 +177,17 @@ class BigResultPlus(commands.Bot):
elif ("?" in fuckyou and random.randint(1, 2000) == 1984):
await message.reply("did you attend?")
+ sleep(1)
await message.reply("were you there?")
+ sleep(1)
await message.reply("were you listening?")
+ sleep(1)
await message.reply("why do you ask?")
return
await super().process_commands(message)
return
- async def send_msg(self, msg):
- channel = super().get_channel(427176475406630914)
+ async def send_msg(self, msg, channel):
+ channel = super().get_channel(channel)
await channel.send(msg)