Skip to content

Commit

Permalink
Fixes #21
Browse files Browse the repository at this point in the history
fixed #21, implemented circular music queue and some new music commands
  • Loading branch information
code-chaser authored Jun 25, 2022
2 parents 5d8b034 + bea8d00 commit b3606f3
Show file tree
Hide file tree
Showing 5 changed files with 561 additions and 231 deletions.
9 changes: 5 additions & 4 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def __init__(self, *args, **kwargs):
self.load_extension(f'src.cogs.{file[:-3]}')

def connect_to_db(self) -> None:

self.DB_CONNECTION = psycopg2.connect(
host=os.getenv('DEX_DB_HOST'),
database=os.getenv('DEX_DB_NAME'),
Expand All @@ -52,7 +51,7 @@ async def get_prefix(self, message):
return prefix

def run(self) -> None:
super().run(os.getenv('BOT_TOKEN'))
super().run(os.getenv('DEX_BOT_TOKEN'))

async def on_ready(self):
print('Logged in as {0.user}'.format(self))
Expand Down Expand Up @@ -88,11 +87,13 @@ async def on_message(self, message) -> None:
str(message.guild.id) + '\';')
tag_switch = cur.fetchone()
cur.close()
if tag_switch[0] == 'off':
return
target = message.author
if target == self.user:
return
print("\n\n-----------------------\n-----------------------\n\n" +
str(message.content) + "\n-----------------------\n")
if tag_switch[0] == 'off':
return
embed = discord.Embed(
title='Message Tagged',
colour=target.colour,
Expand Down
2 changes: 1 addition & 1 deletion src/cogs/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async def send_iquote(self, ctx):

async def get_nasa(self):
API_URL = "https://api.nasa.gov/planetary/apod?api_key=" + \
str(os.getenv('NASA_API_KEY'))
str(os.getenv('DEX_NASA_API_KEY'))
async with aiohttp.ClientSession() as session:
async with session.get(API_URL) as resp:
data_json = await resp.json()
Expand Down
75 changes: 43 additions & 32 deletions src/cogs/modset.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import discord
import psycopg2
from typing import Optional
from datetime import datetime
from discord import Embed, Member
import datetime
from discord.ext.commands import Cog
from discord.ext.commands import command
import os
import json


class ModSet(Cog):
def __init__(self, bot):
self.bot = bot

@command(name="modset", aliases=["mset", "modsettings"])
async def modset(self, ctx, target: Optional[Member]):
async def modset(self, ctx, target: Optional[discord.Member]):
pass

@command(name="tags", aliases=["tagging", "msgtag"], help="toggles message tags")
Expand All @@ -23,6 +20,7 @@ async def message_tags(self, ctx, switch: Optional[str]):
cur.execute(
'SELECT tag_messages FROM guilds WHERE guild_id = \'' + str(ctx.guild.id) + '\';')
tag_messages = cur.fetchone()
cur.close()
tag_switch = tag_messages[0]
if switch is None:
if tag_switch == "off":
Expand All @@ -35,10 +33,17 @@ async def message_tags(self, ctx, switch: Optional[str]):
tag_switch = "on"

else:
embed = Embed(title="Status", colour=0xff0000,
timestamp=datetime.utcnow())
embed.add_field(
name="Error", value="Invalid value provided", inline=True)
async with ctx.typing():
embed = discord.Embed(
title="Status",
colour=0xff0000,
timestamp=datetime.datetime.utcnow()
)
embed.add_field(
name="Error",
value="Invalid value provided",
inline=True
)
await ctx.send(embed=embed)
return

Expand All @@ -47,28 +52,34 @@ async def message_tags(self, ctx, switch: Optional[str]):
'\' WHERE guild_id = \'' + str(ctx.guild.id) + '\';')
self.bot.DB_CONNECTION.commit()
cur.close()
embed = Embed(title="Status",
colour=0x00ff00,
timestamp=datetime.utcnow())
embed.add_field(name="Done", value="Message Tags are now " +
tag_switch, inline=True)
async with ctx.typing():
embed = discord.Embed(
title="Status",
colour=0x00ff00,
timestamp=datetime.datetime.utcnow()
)
embed.add_field(
name="Done",
value="Message Tags are now " + tag_switch,
inline=True
)
await ctx.send(embed=embed)

@command(name="changepref", aliases=["changeprefix"], help="changes the prefix to the appended string")
async def change_prefix(self, ctx, *args):
prefix = "".join(args)
if ctx.guild.id == int(os.environ['PUBLIC_BOT_SERVER']):
embed = Embed(title="Status",
colour=0xff0000,
timestamp=datetime.utcnow())
if ctx.guild.id == int(os.environ['DEX_PUBLIC_BOT_SERVER']):
embed = discord.Embed(title="Status",
colour=0xff0000,
timestamp=datetime.datetime.utcnow())
embed.add_field(
name="Error", value="Prefix changes are not allowed on this server!", inline=True)
await ctx.send(embed=embed)
else:
if ctx.author != ctx.guild.owner:
embed = Embed(title="Status",
colour=0xff0000,
timestamp=datetime.utcnow())
embed = discord.Embed(title="Status",
colour=0xff0000,
timestamp=datetime.datetime.utcnow())
embed.add_field(
name="Error", value="Only server owner can change the prefix!", inline=True)
await ctx.send(embed=embed)
Expand All @@ -80,26 +91,26 @@ async def change_prefix(self, ctx, *args):
"\' WHERE guild_id = \'"+str(ctx.guild.id)+"\';")
self.bot.DB_CONNECTION.commit()
cur.close()
embed = Embed(title="Status",
colour=0x00ff00,
timestamp=datetime.utcnow())
embed = discord.Embed(title="Status",
colour=0x00ff00,
timestamp=datetime.datetime.utcnow())
embed.add_field(
name="Done", value="New Prefix is " + prefix, inline=True)
await ctx.send(embed=embed)
else:
embed = Embed(title="Status",
colour=0xff0000,
timestamp=datetime.utcnow())
embed = discord.Embed(title="Status",
colour=0xff0000,
timestamp=datetime.datetime.utcnow())
embed.add_field(
name="Error", value="prefix length must be between (1 - 27)", inline=True)
await ctx.send(embed=embed)

@command(name="goodbye!", aliases=["leaveThisServer"], help="makes the bot to leave the server (only for server owner)")
async def leave_this_server(self, ctx):
if ctx.author != ctx.guild.owner:
embed = Embed(title="Status",
colour=0xff0000,
timestamp=datetime.utcnow())
embed = discord.Embed(title="Status",
colour=0xff0000,
timestamp=datetime.datetime.utcnow())
embed.add_field(
name="Error", value="Only server owner can use this command!", inline=True)
await ctx.send(embed=embed)
Expand All @@ -109,7 +120,7 @@ async def leave_this_server(self, ctx):
Had a great time in {ctx.guild.name}!
Now it's time, I guess!
Report any issues: [Here](https://github.com/code-chaser/dex/issues/new)
""", color=0x8e38ce, timestamp=datetime.utcnow())
""", color=0x8e38ce, timestamp=datetime.datetime.utcnow())
embed.set_image(
url="https://user-images.githubusercontent.com/63065397/156924332-3638cd0d-9cf9-4e08-b4de-6f20cedd921a.png")
embed.set_author(
Expand All @@ -134,7 +145,7 @@ async def madeby(self, ctx):
**codechaser#0647**
**[GitHub](https://github.com/code-chaser)**
""",
color=0x8e38ce, timestamp=datetime.utcnow())
color=0x8e38ce, timestamp=datetime.datetime.utcnow())
embed.set_author(name="dex",
url="https://github.com/code-chaser/dex/", icon_url=self.bot.user.avatar_url)

Expand Down
Loading

0 comments on commit b3606f3

Please sign in to comment.