General Development

This commit is contained in:
CramMK
2020-01-24 15:41:14 +00:00
parent e4fe8a7d60
commit 4581f24da9
9 changed files with 83 additions and 15 deletions

View File

@@ -1,3 +1,9 @@
# git related things
.git .git
.gitignore .gitignore
# build environment not needed for deployment
.vscode/
# other
README.md README.md

8
.gitignore vendored
View File

@@ -1,4 +1,10 @@
__pycache__/ # own config file
config/config.py config/config.py
# caches and build environment
__pycache__/
.vscode/ .vscode/
# generated data from logging
logs/
*.log *.log

View File

@@ -9,7 +9,9 @@ https://discordpy.readthedocs.io/en/latest/intro.html
import discord import discord
from discord.ext import commands from discord.ext import commands
import logging import logging
from datetime import datetime
import platform import platform
import random
# IMPORTS - internal # IMPORTS - internal
import loadconfig import loadconfig
@@ -19,7 +21,7 @@ logger = logging.getLogger("discord")
# https://docs.python.org/3/library/logging.html#levels # https://docs.python.org/3/library/logging.html#levels
logger.setLevel(logging.INFO) logger.setLevel(logging.INFO)
handler = logging.FileHandler( handler = logging.FileHandler(
filename="discord.log", filename="logs/discord-{%Y-%m-%d_%H-%M}.log".format(datetime.now()),
encoding="utf-8", encoding="utf-8",
mode="w" mode="w"
) )
@@ -43,6 +45,15 @@ for cog in loadconfig.__cogs__:
else: else:
print(f"SUCCESS: Loaded {cog}") 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 STARTING EVENT
@bot.event @bot.event
async def on_ready(): async def on_ready():
@@ -64,9 +75,7 @@ async def on_ready():
""" """
print(startup) print(startup)
status = f"Hentai | {loadconfig.__prefix__}aquabot" activity_loop = asyncio.ensure_future(activity())
activity = discord.Activity(name=status, type=discord.ActivityType.watching)
await bot.change_presence(activity=activity)
print(f"AquaBot is ready!\n") print(f"AquaBot is ready!\n")

View File

@@ -26,6 +26,7 @@ class General(commands.Cog):
""" """
embed = discord.Embed(colour=discord.Colour.blue()) embed = discord.Embed(colour=discord.Colour.blue())
embed.set_thumbnail(url=ctx.me.avatar_url) 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="Owner", value=self.bot.AppInfo.owner, inline=True)
embed.add_field(name="Command Prefix", value=loadconfig.__prefix__, inline=True) embed.add_field(name="Command Prefix", value=loadconfig.__prefix__, inline=True)
@@ -44,4 +45,4 @@ class General(commands.Cog):
# COG ENDING # COG ENDING
def setup(bot): def setup(bot):
bot.add_cog(General(bot)) bot.add_cog(General(bot))

View File

@@ -20,11 +20,11 @@ class Help(commands.Cog):
""" """
Sends a short help for new users Sends a short help for new users
""" """
response = """ response = (
I'm the usele... divine AquaBot!\n "I'm the usele... divine AquaBot!\n"
If you need help, try using the `help` command! "If you need help. try using the `help` command!"
""" )
await ctx.send(response) await ctx.send(response)
# COG ENDING # COG ENDING

View File

@@ -5,12 +5,16 @@ Make Aqua be able to join voice channel and play audio:
- play - play
https://discordpy.readthedocs.io/en/latest/ext/commands/cogs.html 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 # IMPORTS
import discord import discord
from discord.ext import commands from discord.ext import commands
from discord.utils import get from discord.utils import get
from discord import FFmpegPCMAudio
import os
import youtube_dl
# COG INIT # COG INIT
class Voice(commands.Cog): class Voice(commands.Cog):
@@ -26,14 +30,14 @@ class Voice(commands.Cog):
""" """
channel = ctx.message.author.voice.channel channel = ctx.message.author.voice.channel
if not 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 return
voice = get(self.bot.voice_clients, guild=ctx.guild) voice = get(self.bot.voice_clients, guild=ctx.guild)
if voice and voice.is_connected(): if voice and voice.is_connected():
await voice.move_to(channel) await voice.move_to(channel)
await ctx.send(f"`Move to {channel}!`") await ctx.send(f"`Moved to {channel}!`")
else: else:
voice = await channel.connect() voice = await channel.connect()
await ctx.send(f"`Joined {channel}!`") await ctx.send(f"`Joined {channel}!`")
@@ -62,7 +66,31 @@ class Voice(commands.Cog):
Plays music from YT link specifies Plays music from YT link specifies
""" """
# TODO # 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 # COG ENDING

15
config/status.py Normal file
View 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")
]
}

View File

@@ -8,7 +8,9 @@ __avatar__ = "https://i.imgur.com/mskM9dH.png"
from config.cogs import __cogs__ from config.cogs import __cogs__
from config.status import __activity__
try: try:
from config.config import __token__, __prefix__ from config.config import __token__, __prefix__
except ImportError as e: except ImportError as e:
print(f"Error while importing: {e}") print(f"Error while importing: {e}")

View File

@@ -1 +1,2 @@
discord.py[voice]=1.2.5 discord.py[voice]=1.2.5
youtube-dl