-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
77 lines (62 loc) · 2.63 KB
/
bot.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
import discord
import os
from discord.ext import commands
from conf import token
from not_copy import args_to_filters, get_encoding
async def finished_callback(sink, channel, *args):
# Note: sink.audio_data = {user_id: AudioData}
recorded_users = [f" <@{str(user_id)}> ({os.path.split(audio.file)[1]}) " for user_id, audio in
sink.audio_data.items()]
await channel.send(f"Finished! Recorded audio for {', '.join(recorded_users)}.")
class TestBot(commands.Bot):
def __init__(self, *args, **kwargs):
super().__init__(command_prefix=kwargs.pop('commands_prefix', ['-']), *args, **kwargs)
self.connections = {voice.guild.id: voice for voice in self.voice_clients}
self.playlists = {}
async def on_message(self, msg):
if not msg.content:
return
if msg.author.bot:
return
await self.process_commands(msg)
@commands.command(name='start')
async def start_recording(self, ctx, *, args):
filters = args_to_filters(args)
if type(filters) == str:
return await ctx.send(filters)
encoding = get_encoding(args)
if encoding is None:
return await ctx.send("You must provide a valid output encoding.")
vc = await self.get_vc(ctx.message)
vc.start_recording(discord.Sink(encoding=encoding, filters=filters), finished_callback, ctx.channel)
await ctx.send("The recording has started!")
@commands.command(name='stop')
async def stop_recording(self, ctx):
vc = await self.get_vc(ctx.message)
vc.stop_recording()
await ctx.send('stopped recording')
async def on_voice_state_update(self, member, before, after):
if member.id != self.user.id:
return
# Filter out updates other than when we leave a channel we're connected to
if member.guild.id not in self.connections and (not before.channel and after.channel):
return
print("Disconnected")
del self.connections[member.guild.id]
async def get_vc(self, message):
vc = message.author.voice
if not vc:
await message.channel.send("You're not in a vc right now")
return
connection = self.connections.get(message.guild.id)
if connection:
if connection.channel.id == message.author.voice.channel.id:
return connection
await connection.move_to(vc.channel)
return connection
else:
vc = await vc.channel.connect()
self.connections.update({message.guild.id: vc})
return vc
client = TestBot()
client.run(token)