def CheckIfValidReactionMessage(msgId): data = read_json("config") if data["ticketSetupMessageId"] == msgId: return True data.pop("ticketSetupMessageId") data.pop("ticketCount") for value in data.values(): if value["reactionMsgId"] == msgId: return True return False
async def on_raw_reaction_add(payload): # Check if its the bot adding the reaction if payload.user_id == bot.user.id: return # Check if its a valid reaction reaction = str(payload.emoji) if reaction not in ["🔒", "✅"]: return # Check its a valid reaction channel if not payload.channel_id == bot.new_ticket_channel_id and not IsATicket( str(payload.channel_id)): return # Check its a valid message if not CheckIfValidReactionMessage(payload.message_id): return # Soooo, its valid message and reaction so go do logic bois data = read_json("config") if payload.message_id == data["ticketSetupMessageId"] and reaction == "✅": # We want a new ticket... await ReactionCreateNewTicket(bot, payload) # once the ticket is created remove the users reaction guild = bot.get_guild(payload.guild_id) member = await guild.fetch_member(payload.user_id) channel = bot.get_channel(payload.channel_id) message = await channel.fetch_message(payload.message_id) await message.remove_reaction("✅", member) return elif reaction == "🔒": # Simply add a tick to the message channel = bot.get_channel(payload.channel_id) message = await channel.fetch_message(payload.message_id) await message.add_reaction("✅") elif reaction == "✅": # Time to delete the ticket! guild = bot.get_guild(payload.guild_id) member = await guild.fetch_member(payload.user_id) channel = bot.get_channel(payload.channel_id) await CloseTicket(bot, channel, member)
async def SetupNewTicketMessage(bot): data = read_json("config") channel = bot.get_channel(bot.new_ticket_channel_id) embed = discord.Embed( title="Our Services", description= "To purchase a service or enquire about one you must react with a tick", color=0xB4DA55, ) m = await channel.send(embed=embed) await m.add_reaction("✅") data["ticketSetupMessageId"] = m.id write_json(data, "config")
async def NewTicketEmbedSender(bot, author, channel): content = f""" **Hello {author.display_name}** This is your ticket, how can we help you? `Our team will be with you shortly.` """ embed = discord.Embed(description=content, color=0x808080) m = await channel.send(f"{author.mention} | <@&{bot.staff_role_id}>", embed=embed) await m.add_reaction("🔒") data = read_json("config") data[str(channel.id)]["reactionMsgId"] = m.id write_json(data, "config")
from discord.ext import commands from utils.jsonLoader import read_json from utils.util import ( CreateNewTicket, CloseTicket, IsATicket, ReactionCreateNewTicket, SetupNewTicketMessage, CheckIfValidReactionMessage, ) bot = commands.Bot(command_prefix="..", case_insensitive=True, owner_id=271612318947868673) secret_file = read_json("secrets") bot.new_ticket_channel_id = None bot.log_channel_id = None bot.category_id = None bot.staff_role_id = None @bot.event async def on_ready(): print("Lesh go!") await bot.change_presence(activity=discord.Game(name=".new for a ticket")) @bot.event async def on_raw_reaction_add(payload):
import os from pathlib import Path import discord from discord.ext import commands from utils.jsonLoader import read_json cwd = Path(__file__).parents[0] cwd = str(cwd) secret_file = read_json("token") config_file = read_json("config") def get_prefix(bot, message): return commands.when_mentioned_or(bot.PREFIX)(bot, message) bot = commands.Bot( command_prefix=get_prefix, case_insensitive=True, help_command=None, intents=discord.Intents.all(), ) bot.config_token = secret_file["token"] bot.PREFIX = "--" bot.player = None bot.server = config_file["server"]
def GetTicketCount(): data = read_json("config") return data["ticketCount"]
def RemoveTicket(channelId): data = read_json("config") data.pop(str(channelId)) write_json(data, "config")
def GetTicketId(channelId): data = read_json("config") return data[str(channelId)]["id"]
def IsATicket(channelId): data = read_json("config") return str(channelId) in data
def LogNewTicketChannel(channelId, ticketId): data = read_json("config") data[str(channelId)] = {} data[str(channelId)]["id"] = ticketId data[str(channelId)]["reactionMsgId"] = None write_json(data, "config")
def GetTicketSetupMessageId(): data = read_json("config") return data["ticketSetupMessageId"]
def IncrementTicketCount(): data = read_json("config") data["ticketCount"] += 1 write_json(data, "config")