forked from ybrenning/poopy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoo.py
137 lines (100 loc) · 3.4 KB
/
poo.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
#!/usr/bin/env python3
import os
import asyncio
import discord
from discord.ext import commands
import youtube_dl
from dotenv import load_dotenv
from mcstatus import JavaServer
from mcpi.minecraft import Minecraft
mc = Minecraft.create("85.14.195.116", 4711)
load_dotenv()
MC_SERVER_IP = os.getenv("MC_SERVER_IP")
TOKEN = os.getenv("DISCORD_TOKEN")
bot = commands.Bot(command_prefix="$")
mcserver = JavaServer.lookup(MC_SERVER_IP)
@bot.event
async def on_ready():
print(f"We have logged in as {bot.user.name}.")
@bot.command(
brief="Pings the user",
help="This thing is self-explanatory, why would you even ask for extra help?",
)
async def ping(ctx):
await ctx.send("pong")
@bot.command(
brief="Play a song from YouTube",
help="Takes a YouTube URL as an argument and joins your current vc to play the audio",
)
async def play(ctx, url):
voice_clients = {}
yt_dl_opts = {"format": "bestaudio/best"}
ytdl = youtube_dl.YoutubeDL(yt_dl_opts)
ffmpeg_options = {"options": "-vn"}
msg = ctx.message
if ctx.author.voice:
voice_client = await msg.author.voice.channel.connect()
voice_clients[voice_client.guild.id] = voice_client
else:
await ctx.send("You are not connected to a voice channel :poop:")
try:
loop = asyncio.get_event_loop()
data = await loop.run_in_executor(
None, lambda: ytdl.extract_info(url, download=False)
)
song = data["url"]
player = discord.FFmpegPCMAudio(song, **ffmpeg_options)
voice_clients[msg.guild.id].play(player)
except Exception as err:
print(err)
@bot.command(
brief="Leaves current voice channel",
help="Read the name of the command jesus fucking christ",
)
async def leave(ctx):
if ctx.author.voice:
await ctx.guild.voice_client.disconnect()
else:
await ctx.send("I am not currently in a voice channel :poop:")
@bot.command(brief="Pauses current audio", help="Just read the name holy")
async def pause(ctx):
if ctx.author.voice:
await ctx.guild.voice_client.pause()
else:
await ctx.send("I am not currently in a voice channel :poop:")
@bot.command(
brief="Resume the current audio",
help="Stop reading the help section and touch some grass",
)
async def resume(ctx):
if ctx.author.voice:
await ctx.guild.voice_client.resume()
else:
await ctx.send("I am not currently in a voice channel :poop:")
@bot.command(
brief="Displays status of Minecraft server",
help="Show the amount of players currently online as well as the ping",
)
async def status(ctx):
status = mcserver.status()
await ctx.send(
f":poop: The MC-server has {status.players.online} player(s) online and replied in {status.latency} ms :poop:"
)
@bot.command(
brief="Displays players on Minecraft server",
help="Show names of all players currently on the Minecraft server",
)
async def players(ctx):
mc.postToChat("§8[§bPoopy§8]§a: I have fetched server data. beep boop.")
query = mcserver.query()
await ctx.send(
f":poop: The MC-server has the following players online: {', '.join(query.players.names)} :poop:"
)
@bot.command(
brief="Show source code of this bot",
help="Links to the GitHub repository of this bot",
)
async def code(ctx):
await ctx.send("https://github.com/ybrenning/poopy")
if __name__ == "__main__":
bot.run(TOKEN)