ryo-cogs/lsar/lsar.py
2019-05-27 18:45:09 +12:00

52 lines
2.1 KiB
Python

from discord.ext import commands
from cogs.utils.dataIO import dataIO
from __main__ import send_cmd_help, settings
from .utils import checks
import datetime
import discord
import os
from collections import defaultdict
class lsar:
'''A pretty way to show self assignable roles.'''
def __init__(self, bot):
self.bot = bot
def _get_selfrole_names(self, server):
self._settings = dataIO.load_json('data/admin/settings.json')
self._settable_roles = self._settings.get("ROLES", {})
if server.id not in self._settable_roles:
return None
else:
return self._settable_roles[server.id]
@commands.command(no_pm=True, pass_context=True)
async def lsar(self, ctx):
"""Views all current roles you can assign to yourself.
Configurable using `adminset`"""
server = ctx.message.server
timestamp = datetime.datetime.today()
#The selfrole in admin has a bug. You can remove all roles but the server will remain on the selfrole list. The or check corrects this for us.
if self._get_selfrole_names(ctx.message.server) is None or not self._get_selfrole_names(ctx.message.server):
embedmsg = discord.Embed(title="<:res1error:330424101661442050> No roles are available for you to add to yourself.",
colour=discord.Colour(0xff000),
description="This server is currently offers no roles for you to add to yourself.",
timestamp = timestamp)
else:
selfroles = self._settable_roles[server.id]
embedmsg = discord.Embed(title="<:res1hellyeah:330424103259340800> Roles are available for you to add:",
colour=discord.Colour(0x54d824),
description="You can currently give yourself:\n{}".format("\n".join(selfroles)),
timestamp = timestamp)
await self.bot.say(embed=embedmsg)
def setup(bot: commands.Bot):
bot.add_cog(lsar(bot))