Skip to content

Commit 2d2f6c8

Browse files
committed
Add oauth whitelist commands
1 parent 8a6ab07 commit 2d2f6c8

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

cogs/utility.py

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from pkg_resources import parse_version
1212
from textwrap import indent
1313

14-
from discord import Embed, Color, Activity, Role
14+
from discord import Embed, Color, Activity, Role, Member
1515
from discord.enums import ActivityType, Status
1616
from discord.ext import commands
1717

@@ -1165,6 +1165,63 @@ def get_level(perm_level):
11651165

11661166
p_session = PaginatorSession(ctx, *embeds)
11671167
return await p_session.run()
1168+
1169+
@commands.group(invoke_without_command=True)
1170+
@checks.has_permissions(PermissionLevel.OWNER)
1171+
async def oauth(self, ctx):
1172+
"""Commands relating to Logviewer oauth2 login authentication."""
1173+
cmd = self.bot.get_command('help')
1174+
await ctx.invoke(cmd, command='config')
1175+
1176+
@oauth.command()
1177+
@checks.has_permissions(PermissionLevel.OWNER)
1178+
async def whitelist(self, ctx, target: Union[Member, Role]):
1179+
"""Whitelist or un-whitelist a user or role from having access to logs."""
1180+
whitelisted = self.bot.config['oauth_whitelist']
1181+
1182+
if target.id in whitelisted:
1183+
whitelisted.remove(target.id)
1184+
removed = True
1185+
else:
1186+
whitelisted.append(target.id)
1187+
removed = False
1188+
1189+
await self.bot.config.update()
1190+
1191+
em = Embed(color=self.bot.main_color)
1192+
em.title = 'Success'
1193+
em.description = (
1194+
f"{'Un-w' if removed else 'W'}hitelisted "
1195+
f"{target.mention} to view logs."
1196+
)
1197+
1198+
await ctx.send(embed=em)
1199+
1200+
@oauth.command()
1201+
@checks.has_permissions(PermissionLevel.OWNER)
1202+
async def get(self, ctx):
1203+
"""Shows a list of users and roles that are whitelisted to view logs."""
1204+
whitelisted = self.bot.config['oauth_whitelist']
1205+
1206+
users = []
1207+
roles = []
1208+
1209+
for id in whitelisted:
1210+
user = bot.get_user(id)
1211+
if user:
1212+
users.append(users)
1213+
role = self.modmail_guild.get_role(id)
1214+
if role:
1215+
roles.append(role)
1216+
1217+
em = Embed(color=self.bot.main_color)
1218+
em.title = 'Oauth Whitelist'
1219+
em.add_field(name='Users', value=' '.join(u.mention for u in users) or 'None')
1220+
em.add_field(name='Roles', value=' '.join(r.mention for r in roles) or 'None')
1221+
1222+
await ctx.send(embed=em)
1223+
1224+
11681225

11691226
@commands.command(hidden=True, name='eval')
11701227
@checks.has_permissions(PermissionLevel.OWNER)

core/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ConfigManager(ConfigManagerABC):
3939

4040
internal_keys = {
4141
# bot presence
42-
'activity_message', 'activity_type', 'status',
42+
'activity_message', 'activity_type', 'status', 'oauth_whitelist',
4343

4444
# moderation
4545
'blocked', 'command_permissions', 'level_permissions',
@@ -107,6 +107,7 @@ def populate_cache(self):
107107
'plugins': [],
108108
'aliases': {},
109109
'blocked': {},
110+
'oauth_whitelist': [],
110111
'command_permissions': {},
111112
'level_permissions': {},
112113
'notification_squad': {},

0 commit comments

Comments
 (0)