Untitled
unknown
plain_text
2 years ago
9.5 kB
24
Indexable
import nextcord
import datetime
from datetime import datetime
import time
import re
import times
import json
import os
import traceback
TOKEN = "MTE2OTkzNjk2NTMyMDMzMTM0NQ.GLLK92.96jOucMvZHPixGUtNUD5SEAc6WMWiUmgOZ6ZW0"
activity = nextcord.Activity(type=nextcord.ActivityType.watching, name="Awaiting A Name")
intents=nextcord.Intents().all()
bot = nextcord.Client(intents=intents, activity=activity)
colors = {
"main" : 0xFEC23E,
"log" : 0xFEC23E,
"error" : 0xFF0000
}
testingGuildIDs = [
1112755563978293268,
1040903592707625020
]
fruitStockChannel = 1112755563978293271
fruitToEmoji = {'Rocket': '<:Rocket:1171910339928014868>',
'Spin': '<:Spin:1171910373742485564>',
'Chop': '<:Chop:1171910424019607573>',
'Spring': '<:Spring:1171910569733914654>',
'Bomb': '<:Bomb:1171910612461297736>',
'Smoke': '<:Smoke:1171910630769426474>',
'Spike': '<:Spike:1171910763414306826>',
'Flame': '<:Flame:1171910791168020480>',
'Falcon': '<:Falcon:1171910816719700140>',
'Ice': '<:Ice:1171910845899493467>',
'Sand': '<:Sand:1171910876069118074>',
'Dark': '<:Dark:1171910916690948158>',
'Diamond': '<:Diamond:1171911022907494501>',
'Light': '<:Light:1171911052213092382>',
'Rubber': '<:Rubber:1171911069892087960>',
'Barrier': '<:Barrier:1171911101697507341>',
'Ghost': '<:Ghost:1171911129350541433>',
'Magma': '<:Magma:1171911213672824934>',
'Quake': '<:Quake:1171911239438438521>',
'Buddha': '<:Buddha:1171911260334460989>',
'Love': '<:Love:1171911293888897074>',
'String': '<:String:1171911319860035736>',
'Spider': '<:String:1171911319860035736>',
'Sound': '<:Sound:1171911446335082578>',
'Phoenix': '<:Phoenix:1171911516480622622>',
'Portal': '<:Portal:1171911941028061254>',
'Rumble': '<:Rumble:1171912038226870383>',
'Pain': '<:Pain:1171912058619572244>',
'Blizzard': '<:Blizzard:1171912148981645312>',
'Gravity': '<:Gravity:1171912175619678280>',
'Mammoth': '<:Mammoth:1171912198436700263>',
'Dough': '<:Dough:1171912339231092737>',
'Shadow': '<:Shadow:1171912363956523059>',
'Venom': '<:Venom:1171912405341712407>',
'Control': '<:Control:1171912492201545818>',
'Spirit': '<:Spirit:1171912527601475675>',
'Dragon': '<:Dragon:1171912567858417724>',
'Leopard': '<:Leopard:1171912593691136030>'}
GuildID = 1112755563978293268
class stockPingButtons(nextcord.ui.View):
def __init__(self):
super().__init__(timeout=None)
self.add_item(nextcord.ui.Button(
style=nextcord.ButtonStyle.link, url="https://discord.com/api/oauth2/authorize?client_id=1112751645735010334&permissions=8&scope=bot", label="Invite Me", disabled=False))
self.add_item(nextcord.ui.Button(
style=nextcord.ButtonStyle.link, url="https://discord.gg/bloxzy", label="Main Server", disabled=False))
currentStockLeft = ""
def getFileInfo(fileName):
data = {}
current_directory = os.path.dirname(os.path.abspath(__file__))
# Path to the JSON file
json_file_path = os.path.join(current_directory, fileName)
with open(json_file_path, 'r') as json_file:
try:
data = json.load(json_file)
except:
print("File is empty")
return data
async def stockAlertServer(stockType):
currentStock = getFileInfo(stockType)
importantServers = getFileInfo("important.json")
for server in importantServers:
server = importantServers[server]
print(server)
print(type(server))
channel = await bot.fetch_channel(server['channel'])
embed = nextcord.Embed(title=currentStock['title'], description=currentStock['description'])
view = stockPingButtons()
if "role" in server:
await channel.send(content=f"<@&{server['role']}>", embed=embed, view=view)
else:
await channel.send(embed=embed, view=view)
def writeToJson(fileName, role, interaction):
data = {}
current_directory = os.path.dirname(os.path.abspath(__file__))
# Path to the JSON file
json_file_path = os.path.join(current_directory, fileName)
with open(json_file_path, 'r') as json_file:
try:
data = json.load(json_file)
except:
print("File is empty")
if role:
newData = {
interaction.guild_id: {
"channel" : interaction.channel_id,
"role" : role.id,
"added" : interaction.user.id
}
}
else:
newData = {
interaction.guild_id: {
"channel" : interaction.channel_id,
"added" : interaction.user.id
}
}
if str(interaction.guild_id) in data:
data.pop(str(interaction.guild_id))
data.update(newData)
with open(json_file_path, 'w') as json_file:
formattedData = json.dumps(data, indent=4)
json_file.write(formattedData)
print("Added")
@bot.event
async def on_message(message):
print(message.content)
try:
if not message.author.id == bot.user.id:
if message.channel.id == fruitStockChannel:
currentStockLeft = f"<t:{times.timeToUnix(times.hour_rounder())}:R>"
channel = await bot.fetch_channel(1112755563978293271)
content = str(message.content)
beliDescription = content.replace("$", "<:beli:1120686451156320307>")
finalDescription = ""
stringLists = beliDescription.splitlines() # Get each fruit line
stockType = "Stock Update"
for item in stringLists:
if "mirage" in item.lower():
stockType = "Mirage Stock"
elif "normal" in item.lower():
stockType = "Normal Stock"
else:
fruitsFindAll = re.findall(r'@([^\s]+)(?<!\bbeli\b)|<:([^\s:]+)(?<!\bbeli\b):', item) # Get each individual fruit
fruits = list(set([x for group in fruitsFindAll for x in group if x]))
print(f"FRUITS: {fruits}")
for fruit in fruits:
print(f"FRUIT: {fruit}")
beliString = re.findall(r'<:beli:\d+>(\d+,\d+)', item)
newString = fruitToEmoji[fruit] + f" {fruit}" + " - " + "<:beli:1120686451156320307>"
print("new String" + newString)
for item in beliString:
newString += item
finalDescription += newString + "\n"
finalDescription += "\n" + "Expires: " + str(currentStockLeft)
embed = nextcord.Embed(title=stockType, description=finalDescription)
await channel.send(embed=embed)
current_directory = os.path.dirname(os.path.abspath(__file__))
if stockType == "Mirage Stock":
# Path to the JSON file
json_file_path = os.path.join(current_directory, "miragestock.json")
data = {
"title" : stockType,
"description" : finalDescription,
}
with open(json_file_path, 'w') as json_file:
formattedData = json.dumps(data, indent=4)
json_file.write(formattedData)
await stockAlertServer("miragestock.json")
elif stockType == "Normal Stock":
json_file_path = os.path.join(current_directory, "normalstock.json")
data = {
"title" : stockType,
"description" : finalDescription,
}
with open(json_file_path, 'w') as json_file:
formattedData = json.dumps(data, indent=4)
json_file.write(formattedData)
await stockAlertServer("normalstock.json")
except Exception as e:
print(traceback.print_exc())
print(f"Message Error {e}")
@bot.event
async def on_ready():
print(f"{bot.user} is now online!")
@bot.slash_command(guild_ids=testingGuildIDs, description="Stick the stock to the current channel")
async def stockalert(interaction: nextcord.Interaction, role: nextcord.Role = None):
writeToJson("important.json", role, interaction)
embed = nextcord.Embed(title="Server Added", description="Your server has been added to the stock alert list.")
await interaction.response.send_message(embed=embed)
bot.run(TOKEN)Editor is loading...