Skip to content

Commit 1c139ee

Browse files
committed
Ability to change the main Modmail color
1 parent 5ec244e commit 1c139ee

File tree

5 files changed

+56
-37
lines changed

5 files changed

+56
-37
lines changed

bot.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,19 @@ def recipient_color(self):
240240
else:
241241
return color
242242

243+
@property
244+
def main_color(self):
245+
color = self.config.get('main_color')
246+
if not color:
247+
return discord.Color.blurple()
248+
try:
249+
color = int(color.lstrip('#'), base=16)
250+
except ValueError:
251+
print('Invalid main_color provided')
252+
return discord.Color.blurple()
253+
else:
254+
return color
255+
243256
async def on_connect(self):
244257
print(LINE)
245258
print(Fore.CYAN, end='')

cogs/modmail.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async def setup(self, ctx):
4848
'<channel-id>` command to set up a custom log channel'
4949
', then you can delete the default '
5050
f'{log_channel.mention} channel.',
51-
color=discord.Color.blurple()
51+
color=self.bot.main_color
5252
)
5353

5454
embed.set_footer(text=f'Type "{self.bot.prefix}help" '
@@ -71,7 +71,7 @@ async def snippets(self, ctx):
7171
embeds = []
7272

7373
if self.bot.snippets:
74-
embed = discord.Embed(color=discord.Color.blurple(),
74+
embed = discord.Embed(color=self.bot.main_color,
7575
description='Here is a list of snippets '
7676
'that are currently configured.')
7777
else:
@@ -88,7 +88,7 @@ async def snippets(self, ctx):
8888

8989
for name, value in self.bot.snippets.items():
9090
if len(embed.fields) == 5:
91-
embed = discord.Embed(color=discord.Color.blurple(),
91+
embed = discord.Embed(color=self.bot.main_color,
9292
description=embed.description)
9393
embed.set_author(name='Snippets', icon_url=ctx.guild.icon_url)
9494
embeds.append(embed)
@@ -108,7 +108,7 @@ async def add_(self, ctx, name: str.lower, *, value):
108108

109109
embed = discord.Embed(
110110
title='Added snippet',
111-
color=discord.Color.blurple(),
111+
color=self.bot.main_color,
112112
description=f'`{name}` points to: {value}'
113113
)
114114

@@ -121,7 +121,7 @@ async def del_(self, ctx, *, name: str.lower):
121121
if self.bot.config.snippets.get(name):
122122
embed = discord.Embed(
123123
title='Removed snippet',
124-
color=discord.Color.blurple(),
124+
color=self.bot.main_color,
125125
description=f'`{name}` no longer exists.'
126126
)
127127
del self.bot.config['snippets'][name]
@@ -261,7 +261,7 @@ async def notify(self, ctx, *, role=None):
261261
else:
262262
mentions.append(mention)
263263
await self.bot.config.update()
264-
embed = discord.Embed(color=discord.Color.blurple(),
264+
embed = discord.Embed(color=self.bot.main_color,
265265
description=f'{mention} will be mentioned '
266266
'on the next message received.')
267267
return await ctx.send(embed=embed)
@@ -299,7 +299,7 @@ async def subscribe(self, ctx, *, role=None):
299299
mentions.append(mention)
300300
await self.bot.config.update()
301301
embed = discord.Embed(
302-
color=discord.Color.blurple(),
302+
color=self.bot.main_color,
303303
description=f'{mention} will now be '
304304
'notified of all messages received.'
305305
)
@@ -332,7 +332,7 @@ async def unsubscribe(self, ctx, *, role=None):
332332
else:
333333
mentions.remove(mention)
334334
await self.bot.config.update()
335-
embed = discord.Embed(color=discord.Color.blurple(),
335+
embed = discord.Embed(color=self.bot.main_color,
336336
description=f'{mention} is now unsubscribed '
337337
'to this thread.')
338338
return await ctx.send(embed=embed)
@@ -351,7 +351,7 @@ async def loglink(self, ctx):
351351
log_link = await self.bot.api.get_log_link(ctx.channel.id)
352352
await ctx.send(
353353
embed=discord.Embed(
354-
color=discord.Color.blurple(),
354+
color=self.bot.main_color,
355355
description=log_link
356356
)
357357
)
@@ -376,7 +376,7 @@ def format_log_embeds(self, logs, avatar_url):
376376
username = entry['recipient']['name'] + '#'
377377
username += entry['recipient']['discriminator']
378378

379-
embed = discord.Embed(color=discord.Color.blurple(),
379+
embed = discord.Embed(color=self.bot.main_color,
380380
timestamp=created_at)
381381
embed.set_author(name=f'{title} - {username}',
382382
icon_url=avatar_url,
@@ -616,7 +616,7 @@ async def contact(self, ctx,
616616
title='Created thread',
617617
description=f'Thread started in {thread.channel.mention} '
618618
f'for {user.mention}',
619-
color=discord.Color.blurple()
619+
color=self.bot.main_color
620620
)
621621

622622
return await ctx.send(embed=embed)
@@ -627,7 +627,7 @@ async def contact(self, ctx,
627627
async def blocked(self, ctx):
628628
"""Returns a list of blocked users"""
629629
embed = discord.Embed(title='Blocked Users',
630-
color=discord.Color.blurple(),
630+
color=self.bot.main_color,
631631
description='Here is a list of blocked users.')
632632

633633
users = []
@@ -675,7 +675,7 @@ async def block(self, ctx, user: User = None, *, reason=None):
675675
extend = f'for `{reason}`' if reason else ''
676676
embed = discord.Embed(
677677
title='Success',
678-
color=discord.Color.blurple(),
678+
color=self.bot.main_color,
679679
description=f'{mention} is now blocked ' + extend
680680
)
681681
else:
@@ -707,7 +707,7 @@ async def unblock(self, ctx, *, user: User = None):
707707
await self.bot.config.update()
708708
embed = discord.Embed(
709709
title='Success',
710-
color=discord.Color.blurple(),
710+
color=self.bot.main_color,
711711
description=f'{mention} is no longer blocked'
712712
)
713713
else:

cogs/utility.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def format_cog_help(self, ctx, cog):
4646
for fmt in fmts:
4747
embed = Embed(
4848
description='*' + inspect.getdoc(cog) + '*',
49-
color=Color.blurple()
49+
color=self.bot.main_color
5050
)
5151

5252
embed.add_field(name='Commands', value=fmt)
@@ -62,7 +62,7 @@ def format_command_help(self, cmd):
6262
"""Formats command help."""
6363
prefix = self.bot.prefix
6464
embed = Embed(
65-
color=Color.blurple(),
65+
color=self.bot.main_color,
6666
description=cmd.help
6767
)
6868

@@ -143,7 +143,7 @@ async def changelog(self, ctx):
143143
@trigger_typing
144144
async def about(self, ctx):
145145
"""Shows information about the bot."""
146-
embed = Embed(color=Color.blurple(),
146+
embed = Embed(color=self.bot.main_color,
147147
timestamp=datetime.utcnow())
148148
embed.set_author(name='Modmail - About',
149149
icon_url=self.bot.user.avatar_url)
@@ -204,7 +204,7 @@ async def github(self, ctx):
204204
embed = Embed(
205205
title='GitHub',
206206
description='Current User',
207-
color=Color.blurple()
207+
color=self.bot.main_color
208208
)
209209
user = data['user']
210210
embed.set_author(name=user['username'],
@@ -227,7 +227,7 @@ async def update(self, ctx):
227227
embed = Embed(
228228
title='Already up to date',
229229
description=desc,
230-
color=Color.blurple()
230+
color=self.bot.main_color
231231
)
232232

233233
if metadata['latest_version'] == self.bot.version:
@@ -294,7 +294,7 @@ async def activity(self, ctx, activity_type: str, *, message: str = ''):
294294
await self.bot.config.update()
295295
embed = Embed(
296296
title='Activity Removed',
297-
color=Color.blurple()
297+
color=self.bot.main_color
298298
)
299299
return await ctx.send(embed=embed)
300300

@@ -334,7 +334,7 @@ async def activity(self, ctx, activity_type: str, *, message: str = ''):
334334
embed = Embed(
335335
title='Activity Changed',
336336
description=desc,
337-
color=Color.blurple()
337+
color=self.bot.main_color
338338
)
339339
return await ctx.send(embed=embed)
340340

@@ -346,7 +346,7 @@ async def ping(self, ctx):
346346
embed = Embed(
347347
title='Pong! Websocket Latency:',
348348
description=f'{self.bot.ws.latency * 1000:.4f} ms',
349-
color=Color.blurple()
349+
color=self.bot.main_color
350350
)
351351
return await ctx.send(embed=embed)
352352

@@ -359,15 +359,15 @@ async def mention(self, ctx, *, mention=None):
359359
if mention is None:
360360
embed = Embed(
361361
title='Current text',
362-
color=Color.blurple(),
362+
color=self.bot.main_color,
363363
description=f'{current}'
364364
)
365365

366366
else:
367367
embed = Embed(
368368
title='Changed mention!',
369369
description=f'On thread creation the bot now says {mention}',
370-
color=Color.blurple()
370+
color=self.bot.main_color
371371
)
372372
self.bot.config['mention'] = mention
373373
await self.bot.config.update()
@@ -382,7 +382,7 @@ async def prefix(self, ctx, *, prefix=None):
382382
current = self.bot.prefix
383383
embed = Embed(
384384
title='Current prefix',
385-
color=Color.blurple(),
385+
color=self.bot.main_color,
386386
description=f'{current}'
387387
)
388388

@@ -411,7 +411,7 @@ async def options(self, ctx):
411411
valid = ', '.join(f'`{k}`' for k in allowed)
412412
embed = Embed(title='Valid Keys',
413413
description=valid,
414-
color=Color.blurple())
414+
color=self.bot.main_color)
415415
return await ctx.send(embed=embed)
416416

417417
@config.command()
@@ -430,7 +430,7 @@ async def set(self, ctx, key: str.lower, *, value):
430430
else:
431431
embed = Embed(
432432
title='Success',
433-
color=Color.blurple(),
433+
color=self.bot.main_color,
434434
description=f'Set `{key}` to `{value_text}`'
435435
)
436436
await self.bot.config.update({key: value})
@@ -452,7 +452,7 @@ async def del_config(self, ctx, key: str.lower):
452452
if key in keys:
453453
embed = Embed(
454454
title='Success',
455-
color=Color.blurple(),
455+
color=self.bot.main_color,
456456
description=f'`{key}` had been deleted from the config.'
457457
)
458458
try:
@@ -481,7 +481,7 @@ async def get(self, ctx, key=None):
481481
if key in keys:
482482
desc = f'`{key}` is set to `{self.bot.config.get(key)}`'
483483
embed = Embed(
484-
color=Color.blurple(),
484+
color=self.bot.main_color,
485485
description=desc
486486
)
487487
embed.set_author(name='Config variable',
@@ -498,7 +498,7 @@ async def get(self, ctx, key=None):
498498

499499
else:
500500
embed = Embed(
501-
color=Color.blurple(),
501+
color=self.bot.main_color,
502502
description='Here is a list of currently '
503503
'set configuration variables.'
504504
)
@@ -527,12 +527,12 @@ async def alias(self, ctx):
527527

528528
if self.bot.aliases:
529529
embed = Embed(
530-
color=Color.blurple(),
530+
color=self.bot.main_color,
531531
description=desc
532532
)
533533
else:
534534
embed = Embed(
535-
color=Color.blurple(),
535+
color=self.bot.main_color,
536536
description='You dont have any aliases at the moment.'
537537
)
538538
embed.set_author(name='Command aliases', icon_url=ctx.guild.icon_url)
@@ -542,7 +542,7 @@ async def alias(self, ctx):
542542

543543
for name, value in self.bot.aliases.items():
544544
if len(embed.fields) == 5:
545-
embed = Embed(color=Color.blurple(), description=desc)
545+
embed = Embed(color=self.bot.main_color, description=desc)
546546
embed.set_author(name='Command aliases',
547547
icon_url=ctx.guild.icon_url)
548548
embed.set_footer(text=f'Do {self.bot.prefix}help '
@@ -583,7 +583,7 @@ async def add_(self, ctx, name: str.lower, *, value):
583583

584584
embed = Embed(
585585
title='Added alias',
586-
color=Color.blurple(),
586+
color=self.bot.main_color,
587587
description=f'`{name}` points to: {value}'
588588
)
589589

@@ -602,7 +602,7 @@ async def del_alias(self, ctx, *, name: str.lower):
602602

603603
embed = Embed(
604604
title='Removed alias',
605-
color=Color.blurple(),
605+
color=self.bot.main_color,
606606
description=f'`{name}` no longer exists.'
607607
)
608608

core/config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ class ConfigManager(ConfigManagerABC):
1313
'twitch_url',
1414
# bot settings
1515
'main_category_id', 'disable_autoupdates', 'prefix', 'mention',
16+
'main_color',
1617
# logging
1718
'log_channel_id',
1819
# threads
1920
'sent_emoji', 'blocked_emoji', 'thread_creation_response',
2021
# moderation
21-
'recipient_color', 'mod_tag', 'mod_color',
22+
'recipient_color', 'mod_tag', 'mod_color'
2223
# anonymous message
2324
'anon_username', 'anon_avatar_url', 'anon_tag'
2425
}
@@ -48,7 +49,7 @@ class ConfigManager(ConfigManagerABC):
4849
}
4950

5051
colors = {
51-
'mod_color', 'recipient_color'
52+
'mod_color', 'recipient_color', 'main_color'
5253
}
5354

5455
valid_keys = allowed_to_change_in_command | internal_keys | protected_keys

core/models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ def mod_color(self) -> typing.Union[Color, int]:
129129
def recipient_color(self) -> typing.Union[Color, int]:
130130
raise NotImplementedError
131131

132+
@property
133+
@abc.abstractmethod
134+
def main_color(self) -> typing.Union[Color, int]:
135+
raise NotImplementedError
136+
132137
@abc.abstractmethod
133138
async def process_modmail(self, message: Message) -> None:
134139
raise NotImplementedError

0 commit comments

Comments
 (0)