General Development
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
# git related things
|
||||
.git
|
||||
.gitignore
|
||||
|
||||
# build environment not needed for deployment
|
||||
.vscode/
|
||||
|
||||
# other
|
||||
README.md
|
||||
|
||||
8
.gitignore
vendored
8
.gitignore
vendored
@@ -1,4 +1,10 @@
|
||||
__pycache__/
|
||||
# own config file
|
||||
config/config.py
|
||||
|
||||
# caches and build environment
|
||||
__pycache__/
|
||||
.vscode/
|
||||
|
||||
# generated data from logging
|
||||
logs/
|
||||
*.log
|
||||
|
||||
17
aquabot.py
17
aquabot.py
@@ -9,7 +9,9 @@ https://discordpy.readthedocs.io/en/latest/intro.html
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import logging
|
||||
from datetime import datetime
|
||||
import platform
|
||||
import random
|
||||
|
||||
# IMPORTS - internal
|
||||
import loadconfig
|
||||
@@ -19,7 +21,7 @@ logger = logging.getLogger("discord")
|
||||
# https://docs.python.org/3/library/logging.html#levels
|
||||
logger.setLevel(logging.INFO)
|
||||
handler = logging.FileHandler(
|
||||
filename="discord.log",
|
||||
filename="logs/discord-{%Y-%m-%d_%H-%M}.log".format(datetime.now()),
|
||||
encoding="utf-8",
|
||||
mode="w"
|
||||
)
|
||||
@@ -43,6 +45,15 @@ for cog in loadconfig.__cogs__:
|
||||
else:
|
||||
print(f"SUCCESS: Loaded {cog}")
|
||||
|
||||
# ACTIVITY
|
||||
async def activity():
|
||||
while True: # Infinite Loop
|
||||
new_activity = random.choice(loadconfig.__activity__)
|
||||
status = f"{new_activity[1]} | {loadconfig.__prefix__}aquabot"
|
||||
activity = discord.Activity(name=status, type=new_activity[0])
|
||||
await bot.change_presence(activity=activity)
|
||||
await asyncio.sleep(15) # Time in minutes
|
||||
|
||||
# BOT STARTING EVENT
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
@@ -64,9 +75,7 @@ async def on_ready():
|
||||
"""
|
||||
print(startup)
|
||||
|
||||
status = f"Hentai | {loadconfig.__prefix__}aquabot"
|
||||
activity = discord.Activity(name=status, type=discord.ActivityType.watching)
|
||||
await bot.change_presence(activity=activity)
|
||||
activity_loop = asyncio.ensure_future(activity())
|
||||
|
||||
print(f"AquaBot is ready!\n")
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ class General(commands.Cog):
|
||||
"""
|
||||
embed = discord.Embed(colour=discord.Colour.blue())
|
||||
embed.set_thumbnail(url=ctx.me.avatar_url)
|
||||
embed.set_image(url=ctx.me.avatar_url)
|
||||
|
||||
embed.add_field(name="Owner", value=self.bot.AppInfo.owner, inline=True)
|
||||
embed.add_field(name="Command Prefix", value=loadconfig.__prefix__, inline=True)
|
||||
@@ -44,4 +45,4 @@ class General(commands.Cog):
|
||||
|
||||
# COG ENDING
|
||||
def setup(bot):
|
||||
bot.add_cog(General(bot))
|
||||
bot.add_cog(General(bot))
|
||||
|
||||
10
cogs/help.py
10
cogs/help.py
@@ -20,11 +20,11 @@ class Help(commands.Cog):
|
||||
"""
|
||||
Sends a short help for new users
|
||||
"""
|
||||
response = """
|
||||
I'm the usele... divine AquaBot!\n
|
||||
If you need help, try using the `help` command!
|
||||
"""
|
||||
await ctx.send(response)
|
||||
response = (
|
||||
"I'm the usele... divine AquaBot!\n"
|
||||
"If you need help. try using the `help` command!"
|
||||
)
|
||||
await ctx.send(response)
|
||||
|
||||
|
||||
# COG ENDING
|
||||
|
||||
@@ -5,12 +5,16 @@ Make Aqua be able to join voice channel and play audio:
|
||||
- play
|
||||
|
||||
https://discordpy.readthedocs.io/en/latest/ext/commands/cogs.html
|
||||
https://stackoverflow.com/questions/56031159/discord-py-rewrite-what-is-the-source-for-youtubedl-to-play-music
|
||||
"""
|
||||
|
||||
# IMPORTS
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from discord.utils import get
|
||||
from discord import FFmpegPCMAudio
|
||||
import os
|
||||
import youtube_dl
|
||||
|
||||
# COG INIT
|
||||
class Voice(commands.Cog):
|
||||
@@ -26,14 +30,14 @@ class Voice(commands.Cog):
|
||||
"""
|
||||
channel = ctx.message.author.voice.channel
|
||||
if not channel:
|
||||
ctx.send:("You're not connected to a voice channel!")
|
||||
ctx.send("You're not connected to a voice channel!")
|
||||
return
|
||||
|
||||
voice = get(self.bot.voice_clients, guild=ctx.guild)
|
||||
|
||||
if voice and voice.is_connected():
|
||||
await voice.move_to(channel)
|
||||
await ctx.send(f"`Move to {channel}!`")
|
||||
await ctx.send(f"`Moved to {channel}!`")
|
||||
else:
|
||||
voice = await channel.connect()
|
||||
await ctx.send(f"`Joined {channel}!`")
|
||||
@@ -62,7 +66,31 @@ class Voice(commands.Cog):
|
||||
Plays music from YT link specifies
|
||||
"""
|
||||
# TODO
|
||||
ctx.send("This module is not working yet!")
|
||||
try:
|
||||
if os.path.isfile("song.mp3"):
|
||||
os.remove("song.mp3")
|
||||
except PermissionError:
|
||||
await ctx.send("Wait for the current song to end or use the `stop`command")
|
||||
return
|
||||
|
||||
voice = get(bot.voice_clients, guild=ctx.guild)
|
||||
youtube_dl_opts = {
|
||||
'format': 'bestaudio/best',
|
||||
'postprocessors': [{
|
||||
'key': 'FFmpegExtractAudio',
|
||||
'preferredcodec': 'mp3',
|
||||
'preferredquality': '192',
|
||||
}],
|
||||
}
|
||||
with youtube_dl.YouTubeDL(youtube_dl_opts) as ydl:
|
||||
ydl.download([url])
|
||||
for file in os.listdir("./"):
|
||||
if file.endswith(".mp3"):
|
||||
os.rename(file, "song.mp3")
|
||||
|
||||
voice.play(discord.FFmpegPCMAudio("song.mp3"))
|
||||
voice.volume=25
|
||||
voice.is_playing()
|
||||
|
||||
|
||||
# COG ENDING
|
||||
|
||||
15
config/status.py
Normal file
15
config/status.py
Normal file
@@ -0,0 +1,15 @@
|
||||
"""
|
||||
The bot's online status rotates through this list
|
||||
"""
|
||||
|
||||
__activity__ = [
|
||||
(discord.ActivityType.watching, "Hentai"),
|
||||
(discord.ActivityType.watching, "Konosuba"),
|
||||
(discord.ActivityType.watching, "beach episodes")
|
||||
(discord.ActivityType.playing, "with water")
|
||||
(discord.ActivityType.playing, "with Megumin"),
|
||||
(discord.ActivityType.playing, "with Sake"),
|
||||
(discord.ActivityType.streaming, "Hentai")
|
||||
(discord.ActivityType.custom, "mizu")
|
||||
]
|
||||
}
|
||||
@@ -8,7 +8,9 @@ __avatar__ = "https://i.imgur.com/mskM9dH.png"
|
||||
|
||||
from config.cogs import __cogs__
|
||||
|
||||
from config.status import __activity__
|
||||
|
||||
try:
|
||||
from config.config import __token__, __prefix__
|
||||
except ImportError as e:
|
||||
print(f"Error while importing: {e}")
|
||||
print(f"Error while importing: {e}")
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
discord.py[voice]=1.2.5
|
||||
youtube-dl
|
||||
|
||||
Reference in New Issue
Block a user