Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configurable embed colours #32

Merged
merged 1 commit into from
May 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ All commands require an admin role which you can set by using `rl!admin` (requir
- `rl!new` starts the creation process for a new reaction role message. Check [below](#example) for an example.
- `rl!abort` aborts the creation process for a new reaction role message started by the command user in that channel.
- `rl!edit` edits an existing reaction role message or provides instructions on how to do so if no arguments are passed.
- `rl!colour` changes the colour of the embeds of new and newly edited reaction role messages.
- `rl!rm-embed` suppresses the embed of an existing reaction-role message or provides instructions on how to do so if no arguments are passed.
- `rl!admin` adds the mentioned role or role id to the admin list, allowing members with a certain role to use the bot commands. Requires administrator permissions on the server.
- `rl!rm-admin` removes the mentioned role or role id from the admin list, preventing members with a certain role from using the bot commands. Requires administrator permissions on the server.
Expand Down
40 changes: 33 additions & 7 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
TOKEN = str(config.get("server", "token"))
prefix = str(config.get("server", "prefix"))
botname = str(config.get("server", "name"))
botcolour = discord.Colour(int(config.get("server", "colour"), 16))

Client = discord.Client()
bot = commands.Bot(command_prefix=prefix)
Expand All @@ -52,9 +53,6 @@
activities.append(activity)
activities = cycle(activities)

# Colour palette - changes 'embeds' sideline colour
botcolor = 0xFFFF00


def isadmin(ctx, msg=False):
# Checks if command author has one of config.ini admin role IDs
Expand Down Expand Up @@ -248,7 +246,7 @@ async def on_message(message):
selector_embed = discord.Embed(
title="Embed_title",
description="Embed_content",
colour=botcolor,
colour=botcolour,
)
selector_embed.set_footer(text=f"{botname}", icon_url=logo)
await message.channel.send(
Expand All @@ -267,7 +265,7 @@ async def on_message(message):
selector_msg_body = (
msg_values[0] if msg_values[0].lower() != "none" else None
)
selector_embed = discord.Embed(colour=botcolor)
selector_embed = discord.Embed(colour=botcolour)
selector_embed.set_footer(text=f"{botname}", icon_url=logo)
if len(msg_values) > 1:

Expand Down Expand Up @@ -549,12 +547,12 @@ async def edit_selector(ctx):
selector_embed = old_msg.embeds[0]
if len(msg_values) > 3 and msg_values[3].lower() != "none":
selector_embed.title = msg_values[3]
selector_embed.colour = botcolor
selector_embed.colour = botcolour
if old_msg.embeds and len(msg_values) == 4:
selector_embed.description = old_msg.embeds[0].description
if len(msg_values) > 4 and msg_values[4].lower() != "none":
selector_embed.description = msg_values[4]
selector_embed.colour = botcolor
selector_embed.colour = botcolour

# Prevent sending an empty embed instead of removing it
selector_embed = (
Expand Down Expand Up @@ -734,6 +732,33 @@ async def set_systemchannel(ctx):
await ctx.send("You do not have an admin role.")


@bot.command(name="colour")
async def set_colour(ctx):
if isadmin(ctx):
msg = ctx.message.content.split()
args = len(msg) - 1
if args:
global botcolour
colour = msg[1]
try:
botcolour = discord.Colour(int(msg[1], 16))

config["server"]["colour"] = colour
with open("config.ini", "w") as configfile:
config.write(configfile)

example = discord.Embed(
title="Example embed",
description="This embed has a new colour!",
colour=botcolour,
)
await ctx.send("Colour changed.", embed=example)
except ValueError:
await ctx.send(f"Please provide a valid hexadecimal value. Example: `{prefix}colour 0xffff00`")
else:
await ctx.send(f"Please provide a hexadecimal value. Example: `{prefix}colour 0xffff00`")


@bot.command(name="help")
async def hlp(ctx):
if isadmin(ctx):
Expand All @@ -742,6 +767,7 @@ async def hlp(ctx):
f"- `{prefix}new` starts the creation process for a new reaction role message.\n"
f"- `{prefix}abort` aborts the creation process for a new reaction role message started by the command user in that channel.\n"
f"- `{prefix}edit` edits an existing reaction-role message or provides instructions on how to do so if no arguments are passed.\n"
f"- `{prefix}colour` changes the colour of the embeds of new and newly edited reaction role messages.\n"
f"- `{prefix}rm-embed` suppresses the embed of an existing reaction-role message or provides instructions on how to do so if no arguments are passed.\n"
f"- `{prefix}admin` adds the mentioned role to the list of {botname} admins, allowing them to create and edit reaction-role messages. You need to be a server administrator to use this command.\n"
f"- `{prefix}rm-admin` removes the mentioned role from the list of {botname} admins, preventing them from creating and editing reaction-role messages. You need to be a server administrator to use this command.\n"
Expand Down
1 change: 1 addition & 0 deletions config.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ prefix = rl!
name = Reaction Light
system_channel =
logo =
colour = 0xffff00
12 changes: 11 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
else:
break


prefix = input("\nInsert the prefix of the bot (help not available for this) [rl!] ")
if prefix == "":
prefix = "rl!"
Expand Down Expand Up @@ -77,6 +76,16 @@
else:
break

while True:
colour = input(
"Insert the hexadecimal value of the embed colour you prefer [0xffff00] "
)
if logo.lower() == "help":
print("\nThe default is yellow. You can use a colour hex picker. You can change the colour later with a command\n")
continue
else:
break

copy("{}/config.ini.sample".format(folder), "{}/config.ini".format(folder))

config = configparser.ConfigParser()
Expand All @@ -86,6 +95,7 @@
config["server"]["name"] = name
config["server"]["logo"] = logo
config["server"]["system_channel"] = system_channel
config["server"]["colour"] = colour

with open("config.ini", "w") as f:
config.write(f)
Expand Down