コード例 #1
0
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
コード例 #2
0
ファイル: bot.py プロジェクト: Debent33/DPY-Ticket-Bot
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)
コード例 #3
0
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")
コード例 #4
0
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")
コード例 #5
0
ファイル: bot.py プロジェクト: Debent33/DPY-Ticket-Bot
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):
コード例 #6
0
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"]
コード例 #7
0
def GetTicketCount():
    data = read_json("config")
    return data["ticketCount"]
コード例 #8
0
def RemoveTicket(channelId):
    data = read_json("config")
    data.pop(str(channelId))
    write_json(data, "config")
コード例 #9
0
def GetTicketId(channelId):
    data = read_json("config")
    return data[str(channelId)]["id"]
コード例 #10
0
def IsATicket(channelId):
    data = read_json("config")
    return str(channelId) in data
コード例 #11
0
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")
コード例 #12
0
def GetTicketSetupMessageId():
    data = read_json("config")
    return data["ticketSetupMessageId"]
コード例 #13
0
def IncrementTicketCount():
    data = read_json("config")
    data["ticketCount"] += 1
    write_json(data, "config")