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
24
bot.py
24
bot.py
|
|
@ -13,22 +13,26 @@ async def on_ready():
|
||||||
print(f'{client.user.name} is 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"))
|
await client.change_presence(activity=discord.Streaming(name="duck pictures.", url="https://www.youtube.com/watch?v=dQw4w9WgXcQ"))
|
||||||
|
|
||||||
|
@commands.is_owner()
|
||||||
@client.command()
|
@client.command()
|
||||||
async def load(ctx, extension):
|
async def load(ctx, extension):
|
||||||
|
"""Loads a cog"""
|
||||||
client.load_extension(f'cogs.{extension}')
|
client.load_extension(f'cogs.{extension}')
|
||||||
|
|
||||||
|
@commands.is_owner()
|
||||||
@client.command()
|
@client.command()
|
||||||
async def unload(ctx, extension):
|
async def unload(ctx, extension):
|
||||||
|
"""Unloads a cog"""
|
||||||
client.unload_extension(f'cogs.{extension}')
|
client.unload_extension(f'cogs.{extension}')
|
||||||
|
|
||||||
# Subfolders
|
# Subfolders
|
||||||
for filename in os.listdir('./cogs/fun'):
|
# for filename in os.listdir('./cogs/fun'):
|
||||||
if filename.endswith('.py'):
|
# if filename.endswith('.py'):
|
||||||
client.load_extension(f'cogs.fun.{filename[:-3]}')
|
# client.load_extension(f'cogs.fun.{filename[:-3]}')
|
||||||
|
|
||||||
for filename in os.listdir('./cogs/general'):
|
# for filename in os.listdir('./cogs/general'):
|
||||||
if filename.endswith('.py'):
|
# if filename.endswith('.py'):
|
||||||
client.load_extension(f'cogs.general.{filename[:-3]}')
|
# client.load_extension(f'cogs.general.{filename[:-3]}')
|
||||||
|
|
||||||
for filename in os.listdir('./cogs/info'):
|
for filename in os.listdir('./cogs/info'):
|
||||||
if filename.endswith('.py'):
|
if filename.endswith('.py'):
|
||||||
|
|
@ -42,8 +46,12 @@ for filename in os.listdir('./cogs/music'):
|
||||||
if filename.endswith('.py'):
|
if filename.endswith('.py'):
|
||||||
client.load_extension(f'cogs.music.{filename[:-3]}')
|
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'):
|
if filename.endswith('.py'):
|
||||||
client.load_extension(f'cogs.owner.{filename[:-3]}')
|
client.load_extension(f'cogs.inventory.{filename[:-3]}')
|
||||||
|
|
||||||
client.run(TOKEN)
|
client.run(TOKEN)
|
||||||
|
|
@ -9,6 +9,7 @@ class PingCog(commands.Cog):
|
||||||
# Commands
|
# Commands
|
||||||
@commands.command(aliases=['latency'])
|
@commands.command(aliases=['latency'])
|
||||||
async def ping(self, ctx):
|
async def ping(self, ctx):
|
||||||
|
"""Returns the bot client latency"""
|
||||||
await ctx.send(f'Pong! {round(self.client.latency * 1000)}ms')
|
await ctx.send(f'Pong! {round(self.client.latency * 1000)}ms')
|
||||||
|
|
||||||
def setup(client):
|
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
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@commands.has_permissions(kick_members = True)
|
@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:
|
try:
|
||||||
await member.kick(reason=reason)
|
await member.kick(reason=reason)
|
||||||
await ctx.send(member.mention + " has been kicked.")
|
await ctx.send(member.mention + " has been kicked.")
|
||||||
except:
|
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}?")
|
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.command()
|
||||||
@commands.has_permissions(ban_members = True)
|
@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:
|
try:
|
||||||
await member.ban(reason=reason)
|
await member.ban(reason=reason)
|
||||||
await ctx.send(member.mention + " has been banned.")
|
await ctx.send(member.mention + " has been banned.")
|
||||||
|
|
@ -53,22 +53,40 @@ class MusicCog(commands.Cog):
|
||||||
# Commands
|
# Commands
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def play(self, ctx, *, url):
|
async def play(self, ctx, url):
|
||||||
"""Streams from a url (same as yt, but doesn't predownload)"""
|
"""Streams from a url"""
|
||||||
|
|
||||||
|
if ctx.author.voice is None:
|
||||||
|
return await ctx.send("You're not connected to a voice channel.")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
voiceChannel = discord.utils.get(ctx.guild.voice_channels, guild=ctx.guild)
|
channel = ctx.author.voice.channel
|
||||||
await voiceChannel.connect()
|
await channel.connect()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
async with ctx.typing():
|
async with ctx.typing():
|
||||||
player = await YTDLSource.from_url(url, loop=self.client.loop, stream=True)
|
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)
|
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}')
|
await ctx.send(f'Now playing: {player.title}')
|
||||||
|
|
||||||
@commands.command()
|
@play.error
|
||||||
async def leave(self, ctx):
|
async def play_error(self, ctx, error):
|
||||||
|
if isinstance(error, commands.MissingRequiredArgument):
|
||||||
voice = ctx.voice_client
|
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 not None:
|
||||||
if voice.is_connected():
|
if voice.is_connected():
|
||||||
await voice.disconnect()
|
await voice.disconnect()
|
||||||
else:
|
else:
|
||||||
|
|
@ -78,6 +96,9 @@ class MusicCog(commands.Cog):
|
||||||
async def volume(self, ctx, volume: int):
|
async def volume(self, ctx, volume: int):
|
||||||
"""Changes the player's volume"""
|
"""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:
|
if ctx.voice_client is None:
|
||||||
return await ctx.send("Not connected to a voice channel.")
|
return await ctx.send("Not connected to a voice channel.")
|
||||||
|
|
||||||
|
|
@ -86,6 +107,11 @@ class MusicCog(commands.Cog):
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def pause(self, ctx):
|
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
|
voice = ctx.voice_client
|
||||||
if voice.is_playing():
|
if voice.is_playing():
|
||||||
voice.pause()
|
voice.pause()
|
||||||
|
|
@ -94,6 +120,11 @@ class MusicCog(commands.Cog):
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def resume(self, ctx):
|
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
|
voice = ctx.voice_client
|
||||||
if voice.is_paused():
|
if voice.is_paused():
|
||||||
voice.resume()
|
voice.resume()
|
||||||
|
|
@ -104,25 +135,28 @@ class MusicCog(commands.Cog):
|
||||||
async def stop(self, ctx):
|
async def stop(self, ctx):
|
||||||
"""Stops and disconnects the bot from voice"""
|
"""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 = ctx.voice_client
|
||||||
|
if voice:
|
||||||
voice.stop()
|
voice.stop()
|
||||||
|
|
||||||
@commands.command(aliases=['join'])
|
@commands.command(aliases=['join'])
|
||||||
async def connect(self, ctx):
|
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
|
channel = ctx.author.voice.channel
|
||||||
try:
|
try:
|
||||||
await channel.connect()
|
await channel.connect()
|
||||||
except:
|
except:
|
||||||
voice = ctx.voice_client
|
voice = ctx.voice_client
|
||||||
if voice.is_connected():
|
if voice.is_connected() and voice.channel != channel:
|
||||||
await voice.disconnect()
|
await voice.disconnect()
|
||||||
await channel.connect()
|
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):
|
def setup(client):
|
||||||
client.add_cog(MusicCog(client))
|
client.add_cog(MusicCog(client))
|
||||||
|
|
@ -1,16 +1,43 @@
|
||||||
aiohttp==3.7.4.post0
|
aiohttp==3.7.4.post0
|
||||||
async-timeout==3.0.1
|
async-timeout==3.0.1
|
||||||
attrs==21.2.0
|
attrs==21.2.0
|
||||||
|
cachetools==4.2.2
|
||||||
|
certifi==2021.5.30
|
||||||
cffi==1.14.5
|
cffi==1.14.5
|
||||||
chardet==4.0.0
|
chardet==4.0.0
|
||||||
|
charset-normalizer==2.0.3
|
||||||
discord==1.0.1
|
discord==1.0.1
|
||||||
discord.py==1.7.2
|
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
|
idna==3.1
|
||||||
|
jws==0.1.3
|
||||||
multidict==5.1.0
|
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
|
pycparser==2.20
|
||||||
|
pycryptodome==3.10.1
|
||||||
PyNaCl==1.4.0
|
PyNaCl==1.4.0
|
||||||
|
pyparsing==2.4.7
|
||||||
python-dotenv==0.17.1
|
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
|
six==1.16.0
|
||||||
typing-extensions==3.10.0.0
|
typing-extensions==3.10.0.0
|
||||||
|
urllib3==1.26.6
|
||||||
yarl==1.6.3
|
yarl==1.6.3
|
||||||
youtube-dl==2021.5.16
|
youtube-dl==2021.5.16
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue