aboutsummaryrefslogtreecommitdiff
path: root/code/cogs/repeat.py
blob: b7b43ea5cf2bd2cdfc3e1bcf54776925e829ebcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import discord
import datetime
from discord import app_commands
from discord.ext import commands
from cogs.music import Music

from utils.config import BOT_COLOR


class Repeat(commands.GroupCog, name="repeat"):
    def __init__(self, bot):
        self.bot = bot

    @app_commands.command(name="off")
    @app_commands.check(Music.create_player)
    async def repeat_off(self, interaction: discord.Interaction):
        "Turn song/queue repetition off"
        player = self.bot.lavalink.player_manager.get(interaction.guild.id)

        if player.loop == 0:
            embed = discord.Embed(
                title=f"Repeating Already Off",
                description=f"Music repetition is already turned off.",
                color=BOT_COLOR,
            )
            embed.set_footer(
                text=datetime.datetime.now(datetime.timezone.utc).strftime(
                    "%Y-%m-%d %H:%M:%S"
                )
                + " UTC"
            )
            return await interaction.response.send_message(embed=embed, ephemeral=True)

        player.loop = 0

        embed = discord.Embed(
            title=f"Repeating Off",
            description=f"Music will no longer be repeated.",
            color=BOT_COLOR,
        )
        embed.set_footer(
            text=datetime.datetime.now(datetime.timezone.utc).strftime(
                "%Y-%m-%d %H:%M:%S"
            )
            + " UTC"
        )
        await interaction.response.send_message(embed=embed)

    @app_commands.command(name="song")
    @app_commands.check(Music.create_player)
    async def repeat_song(self, interaction: discord.Interaction):
        "Forever repeat that song that is currently playing"
        player = self.bot.lavalink.player_manager.get(interaction.guild.id)

        if player.loop == 1:
            embed = discord.Embed(
                title=f"Repeating Already On",
                description=f"The current song is already being repeated.",
                color=BOT_COLOR,
            )
            embed.set_footer(
                text=datetime.datetime.now(datetime.timezone.utc).strftime(
                    "%Y-%m-%d %H:%M:%S"
                )
                + " UTC"
            )
            return await interaction.response.send_message(embed=embed, ephemeral=True)

        player.loop = 1

        embed = discord.Embed(
            title=f"Repeating Current Song 🔁",
            description=f"The song that is currently playing will be repeated until the </repeat off:1224840891395608737> command is run",
            color=BOT_COLOR,
        )
        embed.set_footer(
            text=datetime.datetime.now(datetime.timezone.utc).strftime(
                "%Y-%m-%d %H:%M:%S"
            )
            + " UTC"
        )
        await interaction.response.send_message(embed=embed)

    @app_commands.command(name="queue")
    @app_commands.check(Music.create_player)
    async def repeat_queue(self, interaction: discord.Interaction):
        "Continuously repeat the queue once it reaches the end"
        player = self.bot.lavalink.player_manager.get(interaction.guild.id)

        if player.loop == 2:
            embed = discord.Embed(
                title=f"Repeating Already On",
                description=f"The queue is already being repeated.",
                color=BOT_COLOR,
            )
            embed.set_footer(
                text=datetime.datetime.now(datetime.timezone.utc).strftime(
                    "%Y-%m-%d %H:%M:%S"
                )
                + " UTC"
            )
            return await interaction.response.send_message(embed=embed, ephemeral=True)

        player.loop = 2

        embed = discord.Embed(
            title=f"Repeating Current Song 🔂",
            description=f"All songs in the queue will continue to repeat until the </repeat off:1224840891395608737> command is run.",
            color=BOT_COLOR,
        )
        embed.set_footer(
            text=datetime.datetime.now(datetime.timezone.utc).strftime(
                "%Y-%m-%d %H:%M:%S"
            )
            + " UTC"
        )
        await interaction.response.send_message(embed=embed)


async def setup(bot):
    await bot.add_cog(Repeat(bot))