bugfix and format and list

Signed-off-by: Bobloy <alboblexloy@gmail.com>
pull/6/head
Bobloy 7 years ago
parent 5a835072f8
commit e4f6cd65f1

@ -2,9 +2,7 @@ import asyncio
from datetime import timedelta, datetime from datetime import timedelta, datetime
import discord import discord
from redbot.core import Config, checks, commands from redbot.core import Config, checks, commands
from redbot.core.bot import Red from redbot.core.bot import Red
from redbot.core.utils.chat_formatting import pagify from redbot.core.utils.chat_formatting import pagify
@ -50,7 +48,7 @@ class Timerole:
if requiredroles: if requiredroles:
to_set['required'] = [r.id for r in requiredroles] to_set['required'] = [r.id for r in requiredroles]
await self.config.guild(guild).roles.set_raw(role.id, to_set) await self.config.guild(guild).roles.set_raw(role.id, value=to_set)
await ctx.send("Time Role for {0} set to {1} days".format(role.name, days)) await ctx.send("Time Role for {0} set to {1} days".format(role.name, days))
@timerole.command() @timerole.command()
@ -66,35 +64,51 @@ class Timerole:
"""Removes a role from being added after specified time""" """Removes a role from being added after specified time"""
guild = ctx.guild guild = ctx.guild
await self.config.guild(guild).roles.set_raw(role.id, None) await self.config.guild(guild).roles.set_raw(role.id, value=None)
await ctx.send("{0} will no longer be applied".format(role.name)) await ctx.send("{0} will no longer be applied".format(role.name))
@timerole.command()
async def list(self, ctx: commands.Context):
"""Lists all currently setup timeroles"""
guild = ctx.guild
role_dict = await self.config.guild(guild).roles()
out = ""
for r_id, r_data in role_dict.items():
if r_data is not None:
role = discord.utils.get(guild.roles, id=int(r_id))
r_roles = []
if role is None:
role = r_id
if 'required' in r_data:
r_roles = [str(discord.utils.get(guild.roles, id=int(new_id))) for new_id in r_data['required']]
out += "{} || {} days || requires: {}\n".format(str(role), r_data['days'], r_roles)
await ctx.maybe_send_embed(out)
async def timerole_update(self): async def timerole_update(self):
for guild in self.bot.guilds: for guild in self.bot.guilds:
print("In server {}".format(guild.name))
addlist = [] addlist = []
role_list = await self.config.guild(guild).roles() role_dict = await self.config.guild(guild).roles()
if not any(role for role in role_list): # No roles if not any(role_data for role_data in role_dict.values()): # No roles
print("No roles")
continue continue
for member in guild.members: for member in guild.members:
has_roles = [r.id for r in member.roles] has_roles = [r.id for r in member.roles]
get_roles = [rID for rID in role_list if rID is not None] get_roles = [int(rID) for rID, r_data in role_dict.items() if r_data is not None]
check_roles = set(get_roles) - set(has_roles) check_roles = set(get_roles) - set(has_roles)
for role_id in check_roles: for role_id in check_roles:
# Check for required role # Check for required role
if 'required' in role_list[role_id]: if 'required' in role_dict[str(role_id)]:
if not set(role_list[role_id]['required']) & set(has_roles): if not set(role_dict[str(role_id)]['required']) & set(has_roles):
# Doesn't have required role # Doesn't have required role
continue continue
if member.joined_at + timedelta( if member.joined_at + timedelta(
days=role_list[role_id]['days']) <= datetime.today(): days=role_dict[str(role_id)]['days']) <= datetime.today():
# Qualifies # Qualifies
addlist.append((member, role_id)) addlist.append((member, role_id))

Loading…
Cancel
Save