Skip to content

Commit b3606f3

Browse files
authored
Fixes #21
fixed #21, implemented circular music queue and some new music commands
2 parents 5d8b034 + bea8d00 commit b3606f3

5 files changed

Lines changed: 561 additions & 231 deletions

File tree

src/bot.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ def __init__(self, *args, **kwargs):
3535
self.load_extension(f'src.cogs.{file[:-3]}')
3636

3737
def connect_to_db(self) -> None:
38-
3938
self.DB_CONNECTION = psycopg2.connect(
4039
host=os.getenv('DEX_DB_HOST'),
4140
database=os.getenv('DEX_DB_NAME'),
@@ -52,7 +51,7 @@ async def get_prefix(self, message):
5251
return prefix
5352

5453
def run(self) -> None:
55-
super().run(os.getenv('BOT_TOKEN'))
54+
super().run(os.getenv('DEX_BOT_TOKEN'))
5655

5756
async def on_ready(self):
5857
print('Logged in as {0.user}'.format(self))
@@ -88,11 +87,13 @@ async def on_message(self, message) -> None:
8887
str(message.guild.id) + '\';')
8988
tag_switch = cur.fetchone()
9089
cur.close()
91-
if tag_switch[0] == 'off':
92-
return
9390
target = message.author
9491
if target == self.user:
9592
return
93+
print("\n\n-----------------------\n-----------------------\n\n" +
94+
str(message.content) + "\n-----------------------\n")
95+
if tag_switch[0] == 'off':
96+
return
9697
embed = discord.Embed(
9798
title='Message Tagged',
9899
colour=target.colour,

src/cogs/fun.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ async def send_iquote(self, ctx):
3232

3333
async def get_nasa(self):
3434
API_URL = "https://api.nasa.gov/planetary/apod?api_key=" + \
35-
str(os.getenv('NASA_API_KEY'))
35+
str(os.getenv('DEX_NASA_API_KEY'))
3636
async with aiohttp.ClientSession() as session:
3737
async with session.get(API_URL) as resp:
3838
data_json = await resp.json()

src/cogs/modset.py

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
import discord
2-
import psycopg2
32
from typing import Optional
4-
from datetime import datetime
5-
from discord import Embed, Member
3+
import datetime
64
from discord.ext.commands import Cog
75
from discord.ext.commands import command
86
import os
9-
import json
107

118

129
class ModSet(Cog):
1310
def __init__(self, bot):
1411
self.bot = bot
1512

1613
@command(name="modset", aliases=["mset", "modsettings"])
17-
async def modset(self, ctx, target: Optional[Member]):
14+
async def modset(self, ctx, target: Optional[discord.Member]):
1815
pass
1916

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

3735
else:
38-
embed = Embed(title="Status", colour=0xff0000,
39-
timestamp=datetime.utcnow())
40-
embed.add_field(
41-
name="Error", value="Invalid value provided", inline=True)
36+
async with ctx.typing():
37+
embed = discord.Embed(
38+
title="Status",
39+
colour=0xff0000,
40+
timestamp=datetime.datetime.utcnow()
41+
)
42+
embed.add_field(
43+
name="Error",
44+
value="Invalid value provided",
45+
inline=True
46+
)
4247
await ctx.send(embed=embed)
4348
return
4449

@@ -47,28 +52,34 @@ async def message_tags(self, ctx, switch: Optional[str]):
4752
'\' WHERE guild_id = \'' + str(ctx.guild.id) + '\';')
4853
self.bot.DB_CONNECTION.commit()
4954
cur.close()
50-
embed = Embed(title="Status",
51-
colour=0x00ff00,
52-
timestamp=datetime.utcnow())
53-
embed.add_field(name="Done", value="Message Tags are now " +
54-
tag_switch, inline=True)
55+
async with ctx.typing():
56+
embed = discord.Embed(
57+
title="Status",
58+
colour=0x00ff00,
59+
timestamp=datetime.datetime.utcnow()
60+
)
61+
embed.add_field(
62+
name="Done",
63+
value="Message Tags are now " + tag_switch,
64+
inline=True
65+
)
5566
await ctx.send(embed=embed)
5667

5768
@command(name="changepref", aliases=["changeprefix"], help="changes the prefix to the appended string")
5869
async def change_prefix(self, ctx, *args):
5970
prefix = "".join(args)
60-
if ctx.guild.id == int(os.environ['PUBLIC_BOT_SERVER']):
61-
embed = Embed(title="Status",
62-
colour=0xff0000,
63-
timestamp=datetime.utcnow())
71+
if ctx.guild.id == int(os.environ['DEX_PUBLIC_BOT_SERVER']):
72+
embed = discord.Embed(title="Status",
73+
colour=0xff0000,
74+
timestamp=datetime.datetime.utcnow())
6475
embed.add_field(
6576
name="Error", value="Prefix changes are not allowed on this server!", inline=True)
6677
await ctx.send(embed=embed)
6778
else:
6879
if ctx.author != ctx.guild.owner:
69-
embed = Embed(title="Status",
70-
colour=0xff0000,
71-
timestamp=datetime.utcnow())
80+
embed = discord.Embed(title="Status",
81+
colour=0xff0000,
82+
timestamp=datetime.datetime.utcnow())
7283
embed.add_field(
7384
name="Error", value="Only server owner can change the prefix!", inline=True)
7485
await ctx.send(embed=embed)
@@ -80,26 +91,26 @@ async def change_prefix(self, ctx, *args):
8091
"\' WHERE guild_id = \'"+str(ctx.guild.id)+"\';")
8192
self.bot.DB_CONNECTION.commit()
8293
cur.close()
83-
embed = Embed(title="Status",
84-
colour=0x00ff00,
85-
timestamp=datetime.utcnow())
94+
embed = discord.Embed(title="Status",
95+
colour=0x00ff00,
96+
timestamp=datetime.datetime.utcnow())
8697
embed.add_field(
8798
name="Done", value="New Prefix is " + prefix, inline=True)
8899
await ctx.send(embed=embed)
89100
else:
90-
embed = Embed(title="Status",
91-
colour=0xff0000,
92-
timestamp=datetime.utcnow())
101+
embed = discord.Embed(title="Status",
102+
colour=0xff0000,
103+
timestamp=datetime.datetime.utcnow())
93104
embed.add_field(
94105
name="Error", value="prefix length must be between (1 - 27)", inline=True)
95106
await ctx.send(embed=embed)
96107

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

0 commit comments

Comments
 (0)