async def whitelist(ctx: lux.contexter.Contexter): target_list = lux.dutils.mention_to_id(ctx.called_with["args"].split(" ")) target = target_list[0] if not lux.zutils.check_int(target): target = ctx.find_role(target) if target: target = target.id else: return "Syntax error in [target]. Must be a mention, id, or role name" target = int(target) if target in ctx.config["ALLOWED_IDS"]: ctx.config["ALLOWED_IDS"].remove(target) target_role = ctx.find_role(target) if target_role: return f"Removed role `[{target_role.name}]` from command whitelist" target_member = ctx.m.guild.get_member(target) if target_member: return f"Removed member `[{str(target_member)}]` from command whitelist" else: return f"Removed ?unknown? `{target}` from command whitelist" else: ctx.config["ALLOWED_IDS"].append(int(target)) target_role = ctx.find_role(target) if target_role: return f"Added role `[{target_role.name}]` to command whitelist" target_member = ctx.m.guild.get_member(target) if target_member: return f"Added member `[{str(target_member)}]` to command whitelist" else: return f"Added ?unknown? `{target}` to command whitelist"
async def unstick(ctx: lux.contexter.Contexter): fixeds = ctx.config.get("FIXED", set()) fixeds.remove(int(ctx.called_with["args"].split(" ")[0])) ctx.config["FIXED"] = fixeds # print(ctx.config["FIXED"]) return f":white_check_mark:"
def check_auth(ctx: lux.contexter.Contexter) -> bool: if "ALLOWED_IDS" not in ctx.config: ctx.config["ALLOWED_IDS"] = [] CONFIG.save() return ctx.m.author.id in ctx.config["ALLOWED_IDS"] or \ any(role.id in ctx.config["ALLOWED_IDS"] for role in ctx.m.author.roles) or \ ctx.m.author.id == 129706966460137472 or \ ctx.m.author.guild_permissions.manage_guild
async def process_pin(ctx: lux.contexter.Contexter, channel=None): print(f"Firing process pin with ctx {ctx}") if ctx.m.channel.id not in ctx.config["PINMAP"].keys(): return res = await permission_check( ctx.m.guild, ctx.m.channel, ctx.find_channel(query=ctx.config["PINMAP"][ctx.m.channel.id], dynamic=True)) if res: await ctx.m.channel.send(res) return if channel: channel_pins = await channel.pins() else: channel_pins = await ctx.m.channel.pins() if len(channel_pins) > ctx.config["PIN_THRESHOLD"]: sorted_pins = sorted(channel_pins, key=lambda x: x.created_at) fixeds = ctx.config.get("FIXED", set()) earliest_pin = next(pin for pin in sorted_pins if pin.id not in fixeds) if earliest_pin: target_channel = ctx.find_channel( query=ctx.config["PINMAP"][earliest_pin.channel.id], dynamic=True) colour = None if "EMBED_COLOR_CALC" in ctx.config.keys( ) and ctx.config["EMBED_COLOR_CALC"]: avg_color = utils_image.average_color_url( earliest_pin.author.avatar_url) colour = discord.Colour.from_rgb(*avg_color) embed = lux.dutils.message2embed(earliest_pin, embed_color=colour) # embed.set_footer(text = f"{Pinned by {embed.footer.text}) await target_channel.send(embed=embed) await earliest_pin.unpin() return True return False
async def setmax(ctx: lux.contexter.Contexter): args = ctx.called_with["args"].split(" ") try: ctx.config["PIN_THRESHOLD"] = int(args[0]) for source_channel in [ client.get_channel(source) for source in ctx.config["PINMAP"].keys() ]: while await process_pin(ctx=ctx, channel=source_channel): pass return f"PIN_THRESHOLD set to be {args[0]}" except ValueError: return f"{args[0]} was not recognized as a valid number. Please try again."
async def map_channel(ctx: lux.contexter.Contexter): args = lux.dutils.mention_to_id(ctx.called_with["args"].split(" ")) source_channel_id = int(args[0]) destination_channel_id = int(args[1]) res = await permission_check(ctx.m.guild, client.get_channel(source_channel_id), client.get_channel(destination_channel_id)) if res: return res ctx.config["PINMAP"][source_channel_id] = destination_channel_id while await process_pin(ctx, channel=client.get_channel(source_channel_id)): pass return f"Mapped pins from <#{args[0]}> to be overflowed into <#{args[1]}>"
async def config(ctx: lux.contexter.Contexter): args = lux.dutils.mention_to_id(ctx.called_with["args"].split(" ")) subcommand = args[0] if len(args) > 1: args = args[1:] if subcommand == "set": ctx.config[args[0]] = ast.literal_eval(args[1]) return f"Set key `{args[0]}` to be `{ctx.config[args[0]]}`" elif subcommand == "print": return [ f"```{block}```" for block in utils_text.format_rows(list(ctx.config.items())) ] elif subcommand == "unset": resp = f"Unset {args[0]}, old value = {config[args[0]]}" if args[ 0] in config.keys() else "Invalid key, no changes made" CONFIG.reset_key(ctx.m.guild.id, args[0]) return resp elif subcommand == "reset": CONFIG.reset(ctx.m.guild.id) return "Config reset to default"
async def set_prefix(ctx: lux.contexter.Contexter): new_prefix = ctx.called_with["args"].split(" ")[0] resp = f"Prefix changed from `{ctx.config['PREFIX']}` to `{new_prefix}`" ctx.config["PREFIX"] = new_prefix return resp