Merge pull request #18 from rzmk/main
Stable bot build with Inventory Cog & Music Cog Fixes
This commit is contained in:
commit
1d96f83124
10 changed files with 176 additions and 44 deletions
26
bot.py
26
bot.py
|
|
@ -13,22 +13,26 @@ async def on_ready():
|
|||
print(f'{client.user.name} is ready.')
|
||||
await client.change_presence(activity=discord.Streaming(name="duck pictures.", url="https://www.youtube.com/watch?v=dQw4w9WgXcQ"))
|
||||
|
||||
@commands.is_owner()
|
||||
@client.command()
|
||||
async def load(ctx, extension):
|
||||
"""Loads a cog"""
|
||||
client.load_extension(f'cogs.{extension}')
|
||||
|
||||
|
||||
@commands.is_owner()
|
||||
@client.command()
|
||||
async def unload(ctx, extension):
|
||||
"""Unloads a cog"""
|
||||
client.unload_extension(f'cogs.{extension}')
|
||||
|
||||
# Subfolders
|
||||
for filename in os.listdir('./cogs/fun'):
|
||||
if filename.endswith('.py'):
|
||||
client.load_extension(f'cogs.fun.{filename[:-3]}')
|
||||
# for filename in os.listdir('./cogs/fun'):
|
||||
# if filename.endswith('.py'):
|
||||
# client.load_extension(f'cogs.fun.{filename[:-3]}')
|
||||
|
||||
for filename in os.listdir('./cogs/general'):
|
||||
if filename.endswith('.py'):
|
||||
client.load_extension(f'cogs.general.{filename[:-3]}')
|
||||
# for filename in os.listdir('./cogs/general'):
|
||||
# if filename.endswith('.py'):
|
||||
# client.load_extension(f'cogs.general.{filename[:-3]}')
|
||||
|
||||
for filename in os.listdir('./cogs/info'):
|
||||
if filename.endswith('.py'):
|
||||
|
|
@ -42,8 +46,12 @@ for filename in os.listdir('./cogs/music'):
|
|||
if filename.endswith('.py'):
|
||||
client.load_extension(f'cogs.music.{filename[:-3]}')
|
||||
|
||||
for filename in os.listdir('./cogs/owner'):
|
||||
# for filename in os.listdir('./cogs/owner'):
|
||||
# if filename.endswith('.py'):
|
||||
# client.load_extension(f'cogs.owner.{filename[:-3]}')
|
||||
|
||||
for filename in os.listdir('./cogs/inventory'):
|
||||
if filename.endswith('.py'):
|
||||
client.load_extension(f'cogs.owner.{filename[:-3]}')
|
||||
client.load_extension(f'cogs.inventory.{filename[:-3]}')
|
||||
|
||||
client.run(TOKEN)
|
||||
|
|
@ -9,6 +9,7 @@ class PingCog(commands.Cog):
|
|||
# Commands
|
||||
@commands.command(aliases=['latency'])
|
||||
async def ping(self, ctx):
|
||||
"""Returns the bot client latency"""
|
||||
await ctx.send(f'Pong! {round(self.client.latency * 1000)}ms')
|
||||
|
||||
def setup(client):
|
||||
|
|
|
|||
61
cogs/inventory/inventoryCog.py
Normal file
61
cogs/inventory/inventoryCog.py
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
import os
|
||||
import discord
|
||||
import DiscordUtils
|
||||
import asyncio
|
||||
from google.cloud import firestore
|
||||
from discord.ext import commands
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
class InventoryCog(commands.Cog):
|
||||
|
||||
def __init__(self, client):
|
||||
self.client = client
|
||||
# Commands
|
||||
|
||||
# Get a single item from inventory
|
||||
@commands.command(aliases=['inv'])
|
||||
@commands.is_owner()
|
||||
async def inventory(self, ctx, arg1):
|
||||
"""Get a single item from the inventory database"""
|
||||
|
||||
# Make single input embed
|
||||
def single_embed(item, id):
|
||||
embed = discord.Embed(title=item["item_name"], description=id)
|
||||
if item["item_type"] != "": embed.add_field(name="Item Type", value=item["item_type"], inline=True)
|
||||
if item["color"] != "": embed.add_field(name="Color", value=item["color"], inline=True)
|
||||
if item["brand"] != "": embed.add_field(name="Brand", value=item["brand"], inline=True)
|
||||
if item["model"] != "": embed.add_field(name="Model", value=item["model"], inline=True)
|
||||
if item["size"] != "": embed.add_field(name="Size", value=item["size"], inline=True)
|
||||
if item["quantity"] != "": embed.add_field(name="Quantity", value=item["quantity"], inline=True)
|
||||
if item["box"] != "": embed.add_field(name="Box", value=item["box"], inline=True)
|
||||
return embed
|
||||
|
||||
# Connect to Firestore DB inventory collection and get the item arg1 as doc
|
||||
if "INVENTORY_PROJECT_ID" in os.environ and "GOOGLE_APPLICATION_CREDENTIALS" in os.environ:
|
||||
try:
|
||||
db = firestore.AsyncClient(project=os.environ.get("INVENTORY_PROJECT_ID"))
|
||||
inventory_ref = db.collection("inventory").document(arg1)
|
||||
doc = await inventory_ref.get()
|
||||
|
||||
if doc.exists:
|
||||
await ctx.send(embed=single_embed(doc.to_dict(), doc.id))
|
||||
else:
|
||||
await ctx.send("That ID doesn't exist!")
|
||||
except:
|
||||
await ctx.send("The DB connection is not working.")
|
||||
elif "INVENTORY_PROJECT_ID" not in os.environ and "GOOGLE_APPLICATION_CREDENTIALS" in os.environ:
|
||||
await ctx.send("Inventory Project ID not found!")
|
||||
elif "GOOGLE_APPLICATION_CREDENTIALS" not in os.environ:
|
||||
await ctx.send("GAPP Credentials not found!")
|
||||
|
||||
@inventory.error
|
||||
async def inventory_error(self, ctx, error):
|
||||
if isinstance(error, commands.MissingRequiredArgument):
|
||||
await ctx.send("Missing required argument! (e.g. d!inventory __10000__)")
|
||||
if isinstance(error, commands.NotOwner):
|
||||
await ctx.send("You do not have permissions to run this command.")
|
||||
|
||||
def setup(client):
|
||||
client.add_cog(InventoryCog(client))
|
||||
|
|
@ -9,17 +9,18 @@ class ModerationCog(commands.Cog):
|
|||
# Commands
|
||||
@commands.command()
|
||||
@commands.has_permissions(kick_members = True)
|
||||
async def kick(self, ctx, member : discord.Member, *, reason="No reason provided."):
|
||||
async def kick(self, ctx, member : commands.MemberConverter, *, reason="No reason provided."):
|
||||
"""Kick a user from the server"""
|
||||
try:
|
||||
await member.kick(reason=reason)
|
||||
await ctx.send(member.mention + " has been kicked.")
|
||||
except:
|
||||
await ctx.send(f"Unable to kick {member.mention}.\nIs {member.mention} at the same role level or higher than {self.client.user.name}?")
|
||||
|
||||
|
||||
@commands.command()
|
||||
@commands.has_permissions(ban_members = True)
|
||||
async def ban(self, ctx, member : discord.Member, *, reason="No reason provided."):
|
||||
async def ban(self, ctx, member : commands.MemberConverter, *, reason="No reason provided."):
|
||||
"""Ban a user from the server"""
|
||||
try:
|
||||
await member.ban(reason=reason)
|
||||
await ctx.send(member.mention + " has been banned.")
|
||||
|
|
@ -53,24 +53,42 @@ class MusicCog(commands.Cog):
|
|||
# Commands
|
||||
|
||||
@commands.command()
|
||||
async def play(self, ctx, *, url):
|
||||
"""Streams from a url (same as yt, but doesn't predownload)"""
|
||||
async def play(self, ctx, url):
|
||||
"""Streams from a url"""
|
||||
|
||||
if ctx.author.voice is None:
|
||||
return await ctx.send("You're not connected to a voice channel.")
|
||||
|
||||
try:
|
||||
voiceChannel = discord.utils.get(ctx.guild.voice_channels, guild=ctx.guild)
|
||||
await voiceChannel.connect()
|
||||
channel = ctx.author.voice.channel
|
||||
await channel.connect()
|
||||
except:
|
||||
pass
|
||||
async with ctx.typing():
|
||||
player = await YTDLSource.from_url(url, loop=self.client.loop, stream=True)
|
||||
ctx.voice_client.play(player, after=lambda e: print(f'Player error: {e}') if e else None)
|
||||
|
||||
await ctx.send(f'Now playing: {player.title}')
|
||||
|
||||
@commands.command()
|
||||
@play.error
|
||||
async def play_error(self, ctx, error):
|
||||
if isinstance(error, commands.MissingRequiredArgument):
|
||||
voice = ctx.voice_client
|
||||
if voice != None and voice.is_paused():
|
||||
voice.resume()
|
||||
else:
|
||||
await ctx.send("Missing URL!")
|
||||
|
||||
@commands.command(aliases=['disconnect, dc'])
|
||||
async def leave(self, ctx):
|
||||
"""Disconnects bot from the voice channel"""
|
||||
|
||||
if ctx.author.voice is None:
|
||||
return await ctx.send("You're not connected to a voice channel.")
|
||||
|
||||
voice = ctx.voice_client
|
||||
if voice.is_connected():
|
||||
await voice.disconnect()
|
||||
if voice is not None:
|
||||
if voice.is_connected():
|
||||
await voice.disconnect()
|
||||
else:
|
||||
await ctx.send("The bot is not connected to a voice channel.")
|
||||
|
||||
|
|
@ -78,6 +96,9 @@ class MusicCog(commands.Cog):
|
|||
async def volume(self, ctx, volume: int):
|
||||
"""Changes the player's volume"""
|
||||
|
||||
if ctx.author.voice is None:
|
||||
return await ctx.send("You're not connected to a voice channel.")
|
||||
|
||||
if ctx.voice_client is None:
|
||||
return await ctx.send("Not connected to a voice channel.")
|
||||
|
||||
|
|
@ -86,6 +107,11 @@ class MusicCog(commands.Cog):
|
|||
|
||||
@commands.command()
|
||||
async def pause(self, ctx):
|
||||
"""Pauses audio"""
|
||||
|
||||
if ctx.author.voice is None:
|
||||
return await ctx.send("You're not connected to a voice channel.")
|
||||
|
||||
voice = ctx.voice_client
|
||||
if voice.is_playing():
|
||||
voice.pause()
|
||||
|
|
@ -94,6 +120,11 @@ class MusicCog(commands.Cog):
|
|||
|
||||
@commands.command()
|
||||
async def resume(self, ctx):
|
||||
"""Resumes currently paused audio"""
|
||||
|
||||
if ctx.author.voice is None:
|
||||
return await ctx.send("You're not connected to a voice channel.")
|
||||
|
||||
voice = ctx.voice_client
|
||||
if voice.is_paused():
|
||||
voice.resume()
|
||||
|
|
@ -104,25 +135,28 @@ class MusicCog(commands.Cog):
|
|||
async def stop(self, ctx):
|
||||
"""Stops and disconnects the bot from voice"""
|
||||
|
||||
if ctx.author.voice is None:
|
||||
return await ctx.send("You're not connected to a voice channel.")
|
||||
|
||||
voice = ctx.voice_client
|
||||
voice.stop()
|
||||
if voice:
|
||||
voice.stop()
|
||||
|
||||
@commands.command(aliases=['join'])
|
||||
async def connect(self, ctx):
|
||||
"""Connects bot to currently connected voice channel"""
|
||||
|
||||
if ctx.author.voice is None:
|
||||
return await ctx.send("You're not connected to a voice channel.")
|
||||
|
||||
channel = ctx.author.voice.channel
|
||||
try:
|
||||
await channel.connect()
|
||||
except:
|
||||
voice = ctx.voice_client
|
||||
if voice.is_connected():
|
||||
if voice.is_connected() and voice.channel != channel:
|
||||
await voice.disconnect()
|
||||
await channel.connect()
|
||||
else:
|
||||
await channel.connect()
|
||||
|
||||
'''@commands.command(aliases=['dc','leave'])
|
||||
async def disconnect(self, ctx):
|
||||
await ctx.voice_client.disconnect()'''
|
||||
|
||||
def setup(client):
|
||||
client.add_cog(MusicCog(client))
|
||||
|
|
@ -1,16 +1,43 @@
|
|||
aiohttp==3.7.4.post0
|
||||
async-timeout==3.0.1
|
||||
attrs==21.2.0
|
||||
cffi==1.14.5
|
||||
chardet==4.0.0
|
||||
discord==1.0.1
|
||||
discord.py==1.7.2
|
||||
idna==3.1
|
||||
multidict==5.1.0
|
||||
pycparser==2.20
|
||||
PyNaCl==1.4.0
|
||||
python-dotenv==0.17.1
|
||||
six==1.16.0
|
||||
typing-extensions==3.10.0.0
|
||||
yarl==1.6.3
|
||||
youtube-dl==2021.5.16
|
||||
aiohttp==3.7.4.post0
|
||||
async-timeout==3.0.1
|
||||
attrs==21.2.0
|
||||
cachetools==4.2.2
|
||||
certifi==2021.5.30
|
||||
cffi==1.14.5
|
||||
chardet==4.0.0
|
||||
charset-normalizer==2.0.3
|
||||
discord==1.0.1
|
||||
discord.py==1.7.2
|
||||
DiscordUtils==1.3.4
|
||||
gcloud==0.18.3
|
||||
google-api-core==1.31.0
|
||||
google-auth==1.33.1
|
||||
google-cloud-core==1.7.1
|
||||
google-cloud-firestore==2.2.0
|
||||
googleapis-common-protos==1.53.0
|
||||
grpcio==1.39.0
|
||||
httplib2==0.19.1
|
||||
idna==3.1
|
||||
jws==0.1.3
|
||||
multidict==5.1.0
|
||||
oauth2client==4.1.3
|
||||
packaging==21.0
|
||||
proto-plus==1.19.0
|
||||
protobuf==3.17.3
|
||||
pyasn1==0.4.8
|
||||
pyasn1-modules==0.2.8
|
||||
pycparser==2.20
|
||||
pycryptodome==3.10.1
|
||||
PyNaCl==1.4.0
|
||||
pyparsing==2.4.7
|
||||
python-dotenv==0.17.1
|
||||
python-jwt==2.0.1
|
||||
pytz==2021.1
|
||||
requests==2.26.0
|
||||
requests-toolbelt==0.9.1
|
||||
rsa==4.7.2
|
||||
six==1.16.0
|
||||
typing-extensions==3.10.0.0
|
||||
urllib3==1.26.6
|
||||
yarl==1.6.3
|
||||
youtube-dl==2021.5.16
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue