Skip to content

Commit

Permalink
Remove Voting + Minor Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bugsbirb committed Jan 24, 2024
1 parent dd8c323 commit fe61b27
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
10 changes: 8 additions & 2 deletions Cogs/Configuration/Views/CustomCommandsView.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ def __init__(self):
Titles = discord.ui.TextInput(
label='title',
placeholder='What is the title?',
required=False
)


Expand All @@ -236,7 +237,10 @@ def __init__(self):
async def on_submit(self, interaction: discord.Interaction):
embed = interaction.message.embeds[0]
embed.title = self.Titles.value
await interaction.response.edit_message(embed=embed)
try:
await interaction.response.edit_message(embed=embed)
except discord.HTTPException():
return await interaction.response.send_message(f"{no} {interaction.user.display_name}, had an error adding the title please try again.", ephemeral=True)


class Description(discord.ui.Modal, title='Description'):
Expand All @@ -250,6 +254,7 @@ def __init__(self):
placeholder='What is the description?',
style=discord.TextStyle.long,
max_length=4000,
required=False
)


Expand Down Expand Up @@ -344,6 +349,7 @@ def __init__(self):
Thumbnaile = discord.ui.TextInput(
label='Image',
placeholder='Whats the image URL?',
required=False
)


Expand Down Expand Up @@ -416,7 +422,7 @@ async def add_embed(self, interaction: discord.Interaction, button: discord.ui.B
embed = discord.Embed(description=f"**{interaction.user.global_name},** this is not your view!",
color=discord.Colour.dark_embed())
return await interaction.response.send_message(embed=embed, ephemeral=True)
embed = discord.Embed(title="Untitled Embed")
embed = discord.Embed(title="Untitled Embed", color=discord.Colour.dark_embed())
view = Embeds(interaction.user, self.name)
await interaction.response.edit_message(embed=embed, view=view)

Expand Down
23 changes: 18 additions & 5 deletions Cogs/Modules/customcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async def run(self, ctx, command, channel: discord.TextChannel = None):
if embed_description in ["None", None]:
embed_description = ""
color_value = command_data.get('color', None)
colors = discord.Colour(int(color_value, 16)) if color_value else discord.Colour.default()
colors = discord.Colour(int(color_value, 16)) if color_value else discord.Colour.dark_embed()

embed = discord.Embed(
title=embed_title,
Expand Down Expand Up @@ -211,7 +211,17 @@ async def upvote(self, interaction: discord.Interaction, button: discord.ui.Butt


if interaction.user.id in voting.get('Voters', []):
await interaction.response.send_message(f"{no} **{interaction.user.display_name},** You have already voted.", ephemeral=True)
CustomVoting.update_one(
{"message_id": message_id},
{
"$inc": {"votes": -1},
"$pull": {"Voters": interaction.user.id},
},
)
new_label = str(voting.get('votes', 0) - 1)
button.label = new_label
await interaction.message.edit(view=self)
await interaction.response.send_message(f"{tick} **{interaction.user.display_name},** You have successfully unvoted.", ephemeral=True)
return

CustomVoting.update_one(
Expand All @@ -228,12 +238,15 @@ async def upvote(self, interaction: discord.Interaction, button: discord.ui.Butt

await interaction.message.edit(view=self)

@discord.ui.button(label="View List", style=discord.ButtonStyle.blurple, emoji=f"{folder}", custom_id="viewlist")
@discord.ui.button(label="Voters", style=discord.ButtonStyle.blurple, emoji=f"{folder}", custom_id="viewlist")
async def list(self, interaction: discord.Interaction, button: discord.ui.Button):
voting = await CustomVoting.find_one({"message_id": interaction.message.id})
voters = voting.get('Voters', [])
voters_str = "\n".join([f"<@{voter}> ({voter})" for voter in voters])

if not voters:
voters_str = f"**{interaction.user.display_name},** there are no voters!"
else:
voters_str = "\n".join([f"<@{voter}> ({voter})" for voter in voters])


embed_description = str(voters_str)[:4096]
embed = discord.Embed(title="Voters", description=embed_description, color=discord.Color.dark_embed())
Expand Down

0 comments on commit fe61b27

Please sign in to comment.