Ejemplo n.º 1
0
 async def tunnel_close(self, ctx: commands.Context, tunnel_id):
     tunnels_data = json.load(open(self.bot.tunnels_json))
     transcripts = None
     for tunnel in tunnels_data['tunnels']:
         if tunnel_id == int(tunnel['tunnelID']):
             tunnel_owner = ctx.guild.get_member(
                 int(tunnel['tunnelAuthor'].split(' ')[-1].strip('( )')))
             if ctx.channel.name == f"{str(ctx.author.name).lower()}-{ctx.author.discriminator}" or discord.utils.get(
                     ctx.guild.roles, name="Support"
             ) in ctx.author.roles or ctx.author.id == ctx.guild.owner_id:
                 try:
                     transcripts = reversed(
                         list(await ctx.channel.history().flatten()))
                 except discord.errors.NotFound:
                     pass
                 transcript_temp = f"Transcript for {tunnel_owner.name}#{tunnel_owner.discriminator} ({tunnel_owner.id}) \n"
                 file1 = BytesIO(
                     initial_bytes=bytes(transcript_temp + "\n".join(
                         f"{transcript.author.name}#{transcript.author.discriminator} ({transcript.author.id}): {transcript.content}"
                         for transcript in transcripts),
                                         encoding="utf-8"))
                 await tunnel_owner.send(file=discord.File(
                     file1,
                     filename=
                     f"{tunnel_owner.name}_{tunnel_owner.discriminator}_{ctx.channel.id}.txt"
                 ))
                 file1.close()
                 await ctx.channel.delete()
                 tunnel['tunnelStatus'] = 'closed'
                 tunnel['tunnelClosedTime'] = indian_standard_time_now()[1]
     json.dump(tunnels_data, open(self.bot.tunnels_json, 'w'), indent='\t')
Ejemplo n.º 2
0
    async def report(self,
                     ctx: commands.Context,
                     user: discord.Member,
                     *,
                     reason="No reason given!"):
        counts = json.load(open(self.bot.counts_json))
        if "id" not in counts.keys():
            counts["id"] = {}
        if str(ctx.guild.id) not in counts.keys():
            counts[str(ctx.guild.id)] = {}
        if "report_id" not in counts["id"].keys():
            counts["id"]["report_id"] = self.bot.start_number
        if "report_number" not in counts[str(ctx.guild.id)].keys():
            counts[str(ctx.guild.id)]["report_number"] = 1
        title = f"""Report #{counts[str(ctx.guild.id)]["report_number"]}"""
        embed = discord.Embed(
            title=title,
            description=(f"**Reported User**: {user.mention}\n"
                         f"**Reported Reason**: {reason}\n"
                         f"**Reported by**: {ctx.author.mention}"),
            color=discord.Colour.blurple())
        embed.set_footer(
            text=
            f"""ReportID: {counts["id"]["report_id"]} | {indian_standard_time_now()[1]}"""
        )
        embed.set_author(name=f"{ctx.author.name}",
                         icon_url=f"{ctx.author.avatar_url}")
        message_sent = await ctx.send(embed=embed)
        await message_sent.add_reaction(f":_tick:705003237174018179")
        await message_sent.add_reaction(f":_neutral:705003236687609936")
        await message_sent.add_reaction(f":_cross:705003237174018158")
        reports = json.load(open(self.bot.reports_json))
        if "reports" not in reports.keys():
            reports["reports"] = []
        report_1 = {
            "reportID": counts['id']["report_id"],
            "reportMessageID": message_sent.id,
            "reportTitle": title,
            "reportReason": reason,
            "reportAuthor":
            f"{ctx.author.name}#{ctx.author.discriminator} ({ctx.author.id})",
            "reportTime": indian_standard_time_now()[1],
            "reportStatus": "waiting",
            "reportUser": f"{user.name}#{user.discriminator} ({user.id})"
        }
        reports["reports"].append(report_1)
        counts['id']["report_id"] += 1
        counts[str(ctx.guild.id)]["report_number"] += 1

        json.dump(reports, open(self.bot.reports_json, "w"), indent='\t')
        json.dump(counts, open(self.bot.counts_json, "w"), indent='\t')

        await ctx.author.send(
            "Your report successfully sent!, this is how it would look like",
            embed=embed)
Ejemplo n.º 3
0
 async def suggest(self, ctx: commands.Context, type1, *, suggestion):
     counts = json.load(open(self.bot.counts_json))
     if "id" not in counts.keys():
         counts["id"] = {}
     if str(ctx.guild.id) not in counts.keys():
         counts[str(ctx.guild.id)] = {}
     if "suggestion_id" not in counts["id"].keys():
         counts["id"]["suggestion_id"] = self.bot.start_number
     if "suggestion_number" not in counts[str(ctx.guild.id)].keys():
         counts[str(ctx.guild.id)]["suggestion_number"] = 1
     title = f"Suggestion #{counts[str(ctx.guild.id)]['suggestion_number']}"
     embed = discord.Embed(
         title=title,
         description=(
             f"**Suggestion**: {suggestion}\n"
             f"**Suggestion by**: {ctx.author.mention}"
         ),
         color=discord.Colour.green()
     ).set_footer(text=f"SuggestionID: {counts['id']['suggestion_id']} | {indian_standard_time_now()[1]}")
     embed.set_author(name=f"{ctx.author.name}", icon_url=f"{ctx.author.avatar_url}")
     message_sent = await ctx.send(embed=embed)
     await message_sent.add_reaction(f":_tick:705003237174018179")
     await message_sent.add_reaction(f":_neutral:705003236687609936")
     await message_sent.add_reaction(f":_cross:705003237174018158")
     await message_sent.add_reaction(f":_already_there:705003236897194004")
     suggestions = json.load(open(self.bot.suggestions_json))
     if "suggestions" not in suggestions.keys():
         suggestions["suggestions"] = []
     suggestion_1 = {
         "suggestionID": counts['id']["suggestion_id"],
         "suggestionMessageID": message_sent.id,
         "suggestionTitle": title,
         "suggestionContent": suggestion,
         "suggestionAuthor": f"{ctx.author.name}#{ctx.author.discriminator} ({ctx.author.id})",
         "suggestionTime": indian_standard_time_now()[1],
         "suggestionChannelID": message_sent.channel.id,
         "suggestionGuildID": message_sent.guild.id,
         "suggestionType": f"{type1}",
         "suggestionStatus": "waiting"
     }
     counts['id']["suggestion_id"] += 1
     counts[str(ctx.guild.id)]["suggestion_number"] += 1
     json.dump(counts, open(self.bot.counts_json, "w+"), indent='\t')
     suggestions["suggestions"].append(suggestion_1)
     json.dump(suggestions, open(self.bot.suggestions_json, "w+"), indent='\t')
     await ctx.author.send("Your suggestion is sent!, This is how your suggestion look like!", embed=embed)
Ejemplo n.º 4
0
    async def tunnel_new(self, ctx: commands.Context, user: discord.Member,
                         reason: str):
        counts = json.load(open(self.bot.counts_json))
        if "id" not in counts.keys():
            counts["id"] = {}
        if str(ctx.guild.id) not in counts.keys():
            counts[str(ctx.guild.id)] = {}
        if "tunnel_id" not in counts["id"].keys():
            counts["id"]["tunnel_id"] = self.bot.start_number
        if "tunnel_number" not in counts[str(ctx.guild.id)].keys():
            counts[str(ctx.guild.id)]["tunnel_number"] = 1
        overwrites = {
            ctx.guild.default_role:
            discord.PermissionOverwrite(read_messages=False),
            ctx.author:
            discord.PermissionOverwrite(read_messages=True,
                                        send_messages=True,
                                        read_message_history=True),
            user:
            discord.PermissionOverwrite(read_messages=True,
                                        send_messages=True,
                                        read_message_history=True)
        }
        embed = discord.Embed(
            title=
            f"Thank you for creating a tunnel! {ctx.author.name} This is Tunnel #{counts[str(ctx.guild.id)]['tunnel_number']}",
            description=
            f"Thank you for creating a tunnel! {ctx.author.mention}\nWe'll get back to you as soon as possible.",
        )
        embed.set_footer(
            text=
            f"TunnelID: {counts['id']['tunnel_id']} | {indian_standard_time_now()[1]}"
        )
        if discord.utils.get(ctx.guild.categories,
                             name="Tunnels") not in ctx.guild.categories:
            await ctx.guild.create_category(name="Tunnels")
        channel = await ctx.guild.create_text_channel(
            name=
            f'{ctx.author.name}-{ctx.author.discriminator}-----{user.name}-{user.discriminator}',
            category=discord.utils.get(ctx.guild.categories, name="Tunnels"),
            overwrites=overwrites)
        await channel.edit(
            topic=
            f"Opened by {ctx.author.name} - All messages sent to this channel are being recorded."
        )
        await channel.send(embed=embed)

        tunnels_data = json.load(open(self.bot.tunnels_json))
        if "tunnels" not in tunnels_data.keys():
            tunnels_data["tunnels"] = []

        tunnel_1 = {
            "tunnelID": counts['id']["tunnel_id"],
            "tunnelAuthor":
            f"{str(ctx.author.name).replace(' ', '-')}#{ctx.author.discriminator} ({ctx.author.id})",
            "tunnelOpenedTime": indian_standard_time_now()[1],
            "tunnelClosedTime": "Not closed till now!",
            "tunnelGuildID": f"{ctx.guild.id}",
            "tunnelReason": f"{reason}",
            "tunnelUser":
            f"{str(user.name).replace(' ', '-')}#{user.discriminator} ({user.id})",
            "tunnelStatus": "opened"
        }
        tunnels_data["tunnels"].append(tunnel_1)
        counts[str(ctx.guild.id)]["tunnel_number"] += 1
        counts["id"]["tunnel_id"] += 1
        json.dump(counts, open(self.bot.counts_json, "w"), indent='\t')
        json.dump(tunnels_data, open(self.bot.tunnels_json, 'w'), indent='\t')
Ejemplo n.º 5
0
    async def ticket_new(self, ctx: commands.Context, *,
                         reason: Optional[str]):
        counts = json.load(open(self.bot.counts_json))
        if "id" not in counts.keys():
            counts["id"] = {}
        if str(ctx.guild.id) not in counts.keys():
            counts[str(ctx.guild.id)] = {}
        if "ticket_id" not in counts["id"].keys():
            counts["id"]["ticket_id"] = self.bot.start_number
        if "ticket_number" not in counts[str(ctx.guild.id)].keys():
            counts[str(ctx.guild.id)]["ticket_number"] = 1
        support_role = discord.utils.find(lambda r: r.name == "Support",
                                          ctx.guild.roles)
        if support_role is None:
            await ctx.guild.create_role(name="Support")
        overwrites = {
            ctx.guild.default_role:
            discord.PermissionOverwrite(read_messages=False),
            ctx.author:
            discord.PermissionOverwrite(read_messages=True,
                                        send_messages=True,
                                        read_message_history=True),
            support_role:
            discord.PermissionOverwrite(read_messages=True,
                                        send_messages=True,
                                        read_message_history=True)
        }
        embed = discord.Embed(
            title=
            f"Thank you for creating a ticket! {ctx.author.name} This is Ticket #{counts[str(ctx.guild.id)]['ticket_number']}",
            description=
            f"Thank you for creating a ticket! {ctx.author.mention}\nWe'll get back to you as soon as possible.",
        )
        embed.set_footer(
            text=
            f"TicketID: {counts['id']['ticket_id']} | {indian_standard_time_now()[1]}"
        )
        if discord.utils.get(ctx.guild.categories,
                             name="Support") not in ctx.guild.categories:
            await ctx.guild.create_category(name="Support")
        channel = await ctx.guild.create_text_channel(
            name=f'{ctx.author.name}-{ctx.author.discriminator}',
            category=discord.utils.get(ctx.guild.categories, name="Support"),
            overwrites=overwrites)
        await channel.edit(
            topic=
            f"Opened by {ctx.author.name} - All messages sent to this channel are being recorded."
        )
        await channel.send(embed=embed)
        tickets_data = json.load(open(self.bot.tickets_json))
        if "tickets" not in tickets_data.keys():
            tickets_data["tickets"] = []

        ticket_1 = {
            "ticketID": counts['id']["ticket_id"],
            "ticketAuthor":
            f"{ctx.author.name}#{ctx.author.discriminator} ({ctx.author.id})",
            "ticketOpenedTime": indian_standard_time_now()[1],
            "ticketClosedTime": "Not closed till now!",
            "ticketGuildID": f"{ctx.guild.id}",
            "ticketReason": f"{reason}",
            "ticketStatus": "opened"
        }
        tickets_data["tickets"].append(ticket_1)
        counts[str(ctx.guild.id)]["ticket_number"] += 1
        counts["id"]["ticket_id"] += 1
        json.dump(counts, open(self.bot.counts_json, "w"), indent='\t')
        json.dump(tickets_data, open(self.bot.tickets_json, 'w'), indent='\t')
Ejemplo n.º 6
0
    async def on_raw_reaction_add(self, payload):
        guild: discord.Guild = self.bot.get_guild(payload.guild_id)
        guild_data = json.load(open(self.bot.guilds_json))
        enabled = guild_data[str(guild.id)]["enabled"]
        if f"Bot.cogs.{self.qualified_name}" in enabled:
            counts = json.load(open(self.bot.counts_json))
            if "id" not in counts.keys():
                counts["id"] = {}
            if str(guild.id) not in counts.keys():
                counts[str(guild.id)] = {}
            if "ticket_id" not in counts["id"].keys():
                counts["id"]["ticket_id"] = self.bot.start_number
            if "ticket_number" not in counts[str(guild.id)].keys():
                counts[str(guild.id)]["ticket_number"] = 1
            tickets_data = json.load(open(self.bot.tickets_json))
            if str(guild.id) not in tickets_data:
                tickets_data[str(guild.id)] = {}
                tickets_data[str(guild.id)]['ticket_emoji'] = []
            emoji = payload.emoji
            support_role = discord.utils.find(lambda r: r.name == "Support",
                                              guild.roles)
            if support_role is None:
                await guild.create_role(name="Support")
            overwrites = {
                guild.default_role:
                discord.PermissionOverwrite(read_messages=False),
                guild.get_member(payload.user_id):
                discord.PermissionOverwrite(read_messages=True,
                                            send_messages=True,
                                            read_message_history=True),
                support_role:
                discord.PermissionOverwrite(read_messages=True,
                                            send_messages=True,
                                            read_message_history=True)
            }
            user: discord.Member = guild.get_member(payload.user_id)
            embed = discord.Embed(
                title=
                f"Thank you for creating a ticket! {user.name} This is Ticket #{counts[str(guild.id)]['ticket_number']}",
                description=
                f"Thank you for creating a ticket! {user.mention}\nWe'll get back to you as soon as possible.",
            )
            embed.set_footer(
                text=
                f"TicketID: {counts['id']['ticket_id']} | {indian_standard_time_now()[1]}"
            )
            for emoji_2 in tickets_data[str(guild.id)]['ticket_emoji']:
                if str(emoji) == str(emoji_2):
                    if discord.utils.get(
                            guild.categories,
                            name="Support") not in guild.categories:
                        await guild.create_category(name="Support")
                    channel = await guild.create_text_channel(
                        name=f'{user.name}-{user.discriminator}',
                        category=discord.utils.get(user.guild.categories,
                                                   name="Support"),
                        overwrites=overwrites)
                    await channel.edit(
                        topic=
                        f"Opened by {user.name} - All messages sent to this channel are being recorded."
                    )
                    await channel.send(embed=embed)
                tickets_data = json.load(open(self.bot.tickets_json))
                if "tickets" not in tickets_data.keys():
                    tickets_data["tickets"] = []

                ticket_1 = {
                    "ticketID": counts['id']["ticket_id"],
                    "ticketAuthor":
                    f"{user.name}#{user.discriminator} ({user.id})",
                    "ticketOpenedTime": indian_standard_time_now()[1],
                    "ticketClosedTime": "Not closed till now!",
                    "ticketGuildID": f"{guild.id}",
                    "ticketReason":
                    "No Reason given (Ticket opened using emoji)",
                    "ticketStatus": "opened"
                }
                tickets_data["tickets"].append(ticket_1)
                counts[str(guild.id)]["ticket_number"] += 1
                counts["id"]["ticket_id"] += 1
                json.dump(counts, open(self.bot.counts_json, "w"), indent='\t')
                json.dump(tickets_data,
                          open(self.bot.tickets_json, 'w'),
                          indent='\t')