|
11 | 11 | from pkg_resources import parse_version
|
12 | 12 | from textwrap import indent
|
13 | 13 |
|
14 |
| -from discord import Embed, Color, Activity, Role |
| 14 | +from discord import Embed, Color, Activity, Role, Member |
15 | 15 | from discord.enums import ActivityType, Status
|
16 | 16 | from discord.ext import commands
|
17 | 17 |
|
@@ -1165,6 +1165,63 @@ def get_level(perm_level):
|
1165 | 1165 |
|
1166 | 1166 | p_session = PaginatorSession(ctx, *embeds)
|
1167 | 1167 | 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 | + |
1168 | 1225 |
|
1169 | 1226 | @commands.command(hidden=True, name='eval')
|
1170 | 1227 | @checks.has_permissions(PermissionLevel.OWNER)
|
|
0 commit comments