-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
181 lines (144 loc) · 5.4 KB
/
main.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
import os
import discord
import time
from discord.ext import commands
import logging
import Response
import Values
import player
from jokeapi import Jokes
import queue
import asyncio
import random
from keep_alive import keep_alive
my_secret = os.environ['DiscordToken']
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix='$',
intents=intents,
activity=discord.Game(name=Values.Activity),
status=discord.Status.online,
description="Listening to $help command")
handler = logging.FileHandler(filename=f'LOGS/{time.ctime()}.log',
encoding='utf-8',
mode='w')
last_run = time.ctime()
print(last_run)
q = queue.Queue()
songs_q = []
#@bot.command(help=Values.test_help)
#async def test2(ctx, *arg):
# file = open("queue_persistent.txt","r")
# for i in file:
# await play(ctx, i)
@bot.command(help=Values.test_help)
async def test(ctx, *arg):
passed_text = " ".join(arg)
await ctx.send(embed=Response.CreatEmbed(passed_text))
@bot.command(help=Values.joke_help)
async def joke(ctx):
j = await Jokes()
joke = await j.get_joke(blacklist=Values.joke_blacklist)
await ctx.send(embed=Response.JokeSetup(setup=joke.get('setup')))
time.sleep(3)
await ctx.send(embed=Response.JokeDelivery(delivery=joke.get('delivery')))
@bot.command(help=Values.play_help)
async def play(ctx, *args):
song_requested = " ".join(args).strip()
if song_requested == "" and ctx.voice_client is not None:
if ctx.voice_client.is_playing() is False:
await resume(ctx)
else:
ctx.voice_client.play(q.get())
temp=songs_q.pop(0)
return 0
elif song_requested == "" and ctx.voice_client is None:
await skip(ctx)
await bot.change_presence(
activity=discord.Game(random.choice(Values.playingList)))
await join(ctx)
if ctx.voice_client.is_playing() != True:
result_dict = player.Search(song_requested).result()['result'][0]
#print(result_dict)
#print(result_dict['duration'][:-3])
#print("\n" + result_dict['id'])
if int(result_dict['duration'][:-3]) < Values.songAllowedLength:
link = result_dict['link']
id = result_dict['id']
async with ctx.typing():
player.download_func(link, id)
await asyncio.sleep(Values.TypingSleepTimer)
await ctx.send(embed=Response.SongResponse(result_dict))
await join(ctx)
source = await discord.FFmpegOpusAudio.from_probe(f'./Storage/{id}.mp3')
ctx.voice_client.play(source, after=lambda t: asyncio.run_coroutine_threadsafe(ctx.voice_client.play(q.get(0), bot.loop)))
print(f"[Debug] Playing {id}")
else:
await ctx.send(embed=Response.Songlenthexceeded())
else:
result_dict = player.Search(song_requested).result()['result'][0]
if int(result_dict['duration'][:-3]) < Values.songAllowedLength:
result_dict = player.Search(song_requested).result()['result'][0]
link = result_dict['link']
id = result_dict['id']
async with ctx.typing():
player.download_func(link, id)
await asyncio.sleep(Values.TypingSleepTimer)
await ctx.send(embed=Response.SongResponse(result_dict))
source = await discord.FFmpegOpusAudio.from_probe(f'./Storage/{id}.mp3')
q.put(source)
songs_q.append(result_dict['title'])
else:
await ctx.send(embed=Response.Songlenthexceeded())
print(
f"[Debug] added to queue. Total songs in queue: {q.unfinished_tasks}\n\n({songs_q})\n\n"
)
@bot.command(help=Values.help_join)
async def join(ctx):
if ctx.message.author.voice is None:
await ctx.send(embed=Response.Auth_non_connected())
elif ctx.voice_client is None:
await ctx.message.author.voice.channel.connect(reconnect=True,
self_deaf=True)
elif ctx.voice_client.channel == ctx.message.author.voice.channel:
pass
else:
await ctx.voice_client.disconnect()
await ctx.message.author.voice.channel.connect(reconnect=True,
self_deaf=True)
@bot.command(help=Values.help_leave)
async def leave(ctx):
await ctx.voice_client.disconnect()
@bot.command(help=Values.help_skip)
async def skip(ctx):
ctx.voice_client.stop()
await ctx.send(embed=Response.ShortResponse(f"Now playing {songs_q.pop(0)}"))
ctx.voice_client.play(q.get(0))
print("[debug] bot skipped song")
@bot.command(help=Values.help_stop)
async def pause(ctx):
ctx.voice_client.pause()
print("[debug] bot paused")
@bot.command(help=Values.help_stop)
async def resume(ctx):
ctx.voice_client.resume()
print("[debug] bot resumed")
@bot.command(help=Values.help_halt)
async def stop(ctx):
ctx.voice_client.stop()
@bot.command(help=Values.help_queue)
async def queue(ctx):
await ctx.send(embed=Response.ShowQueue(songs_q))
@bot.command(help=Values.help_ClearQueue)
async def clear(ctx):
q.queue.clear()
songs_q.clear()
await ctx.send(embed=Response.ShortResponse("Your Queue has been cleared"))
@bot.command(help=Values.help_fix)
async def fix(ctx):
q.queue.clear()
songs_q.clear()
await leave(ctx)
print(Values.fix)
keep_alive()
bot.run(my_secret, log_handler=handler, log_level=logging.INFO)