-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoosicCmd.py
221 lines (203 loc) · 7.17 KB
/
moosicCmd.py
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
from moosicUtil import *
from MoosicPlay import *
import discord
from discord.ext import commands
import youtube_dl
import asyncio
# commands and player
class moosicCmd(commands.Cog):
def __init__(self, client):
self.client = client
self.loop = 1
self.queue = []
self.playing = False
# join and add to queue
@commands.command()
async def play(self, ctx, *search):
await msgInfo(ctx)
# adds the "search"
for arg in search:
search1 = " ".join(arg)
# if there is no argument for search
if search1 == "":
await ctx.send("Please enter your search or url")
print("Didn't enter search or url\n")
else:
audioInfo = await ytSearch(ctx, search1)
self.queue.append(audioInfo)
await joinVc(ctx)
if len(self.queue) > 1 or self.playing == True:
await ctx.send("Number {} in queue".format(len(self.queue)))
if len(self.queue) == 1 and self.playing == False:
print("Started player\n")
await asyncio.create_task(player(self, ctx, audioInfo))
# if queue is empty and nothing is playing, dc
if len(self.queue) == 0 and self.playing == False:
try:
await ctx.voice_client.disconnect()
await ctx.send("Disconnected because queue was empty.")
dateTime()
print("Disconnected because queue was empty.\n")
except:
pass
else:
print("Added to queue")
print("Queue length: {}\n".format(len(self.queue)))
@commands.command()
async def p(self, ctx, *search):
await self.play(ctx, search)
# disconnect
@commands.command()
async def disconnect(self, ctx):
await msgInfo(ctx)
await ctx.voice_client.disconnect()
self.playing = False
self.queue.clear()
await ctx.send("Disconnected")
print("Disconnected\n")
@commands.command()
async def dc(self, ctx):
await self.disconnect(ctx)
# pause
@commands.command()
async def pause(self, ctx):
await msgInfo(ctx)
if self.playing == False:
await ctx.send("Nothing is playing right now")
print("Nothing was playing\n")
else:
ctx.voice_client.pause()
await ctx.send("Paused")
print("Paused\n")
@commands.command()
async def pd(self, ctx):
await self.pause(ctx)
# resume
@commands.command()
async def resume(self, ctx):
await msgInfo(ctx)
if self.playing == False:
await ctx.send("Nothing is playing right now")
print("Nothing was playing\n")
else:
ctx.voice_client.resume()
await ctx.send("Resumed")
print("Resumed\n")
@commands.command()
async def r(self, ctx):
await self.resume(ctx)
# stop
@commands.command()
async def stop(self, ctx):
await msgInfo(ctx)
if self.playing == False:
await ctx.send("Nothing is playing right now")
print("Nothing was playing\n")
else:
ctx.voice_client.stop()
self.queue.clear()
self.playing = False
await ctx.send("Stopped queue")
await ctx.send("Please disconnect the bot if your are done using it")
print("Stopped queue\n")
# loop
@commands.command()
async def loop(self, ctx, loopNumber = "infinite"):
await msgInfo(ctx)
if self.playing == False:
await ctx.send("Nothing is playing right now")
print("Nothing was playing\n")
else:
try:
self.loop = loopNumber
# infinite loop
if loopNumber == "infinite":
await ctx.send("Looping")
print("Loop infinitely\n")
# fixed number loop
else:
int(self.loop)
await ctx.send("Looping {}".format(self.loop))
print("Looping {}\n".format(self.loop))
except:
await ctx.send("Please enter a number")
print("Didn't enter a number\n")
@commands.command()
async def l(self, ctx, loopNumber = "infinite"):
await self.loop(ctx, loopNumber)
# skip
@commands.command()
async def skip(self, ctx):
await msgInfo(ctx)
if self.playing == False:
await ctx.send("Nothing is playing right now")
print("Nothing was playing\n")
else:
if len(self.queue) == 0:
await ctx.send("No songs to skip to")
print("No songs to skip to\n")
else:
ctx.voice_client.stop()
self.playing = False
await asyncio.sleep(1)
await ctx.send("Skipped")
print("Skipped\n")
await asyncio.create_task(player(self, ctx, self.queue[0]))
@commands.command()
async def s(self, ctx):
await self.skip(ctx)
# show queue
@commands.command()
async def queue(self, ctx):
await msgInfo(ctx)
if self.playing == False:
await ctx.send("Nothing is playing right now")
print("Nothing was playing\n")
elif len(self.queue) == 0:
await ctx.send("Nothing is in the queue")
print("Nothing was in the queue\n")
else:
x = 0
for i in range(len(self.queue)):
x += 1
await ctx.send("{number}. `{queue}`".format(number = x, queue = self.queue[x - 1]["title"]))
print("Showed queue\n")
# clear queue
@commands.command()
async def clear(self, ctx):
await msgInfo(ctx)
if self.playing == False:
await ctx.send("Nothing is playing right now")
print("Nothing was playing\n")
elif len(self.queue) <= 1:
await ctx.send("Nothing is in the queue")
print("Nothing was in the queue\n")
else:
self.queue.clear()
await ctx.send("Queue cleared")
print("Queue cleared\n")
@commands.command()
async def cq(self, ctx):
await self.clear(ctx)
# help
@commands.command()
async def help(self, ctx):
await msgInfo(ctx)
await ctx.send("""
My prefix is \"-\"
All Commands List:
play \"search\" --- Plays specified search or url(only Youtube for now... and no playlists or streams)
dc --- Disconnects the bot
stop --- Stops all songs in queue
pause --- Pauses the current song
resume --- Resumes the current song
loop \"number of loops\" --- Loops current song infinitely unless specified with number of times
skip --- Skips the current song
clear --- Clears the queue
queue --- Shows all songs currently in queue(Work in progress)
Contact Teriyake4 for bugs, help, and suggestions
Please be nice to the bot, it is very fragile
""")
print("Gave help\n")
def setupCmd(client):
client.add_cog(moosicCmd(client))