async def update(ctx: Context, index: int = None, description: str = None): mentions = ctx.message.mentions hacks = db.get_hacks() if index == None or index >= len(hacks): await send_hacks_list(ctx.channel) elif not description: embed = discord.Embed( title="Error: Can't update the hack", description= f'Project description and possibly updated user(s) have to be specified!' ) await ctx.send(embed=embed) else: previous = hacks[index] if not (ctx.author.id in previous['people'] or await is_mod(ctx)): await ctx.send( f'Error: You do not have permission to modify "{format_hack(previous)}"' ) return people = [user.id for user in mentions ] if len(mentions) > 0 else previous['people'] hack = {**previous, 'people': people, 'description': description} hacks[index] = hack db.set_hacks(hacks) await ctx.send(f'Updated hack "{format_hack(hack)}"') await send_hacks_list(ctx.channel) await edit_sent(ctx)
async def link(ctx: Context, index: int = None, url: str = None): hacks = db.get_hacks() if index == None or index >= len(hacks): await send_hacks_list(ctx.channel) elif not url: embed = discord.Embed(title="Error: Can't update the hack", description=f'Project url has to be specified!') await ctx.send(embed=embed) else: previous = hacks[index] if not (ctx.author.id in previous['people'] or await is_mod(ctx)): await ctx.send( f'Error: You do not have permission to modify "{format_hack(previous)}"' ) return hack = {**previous, 'url': url} hacks[index] = hack db.set_hacks(hacks) await ctx.send(f'Updated hack "{format_hack(hack)}"') await send_hacks_list(ctx.channel) await edit_sent(ctx)
async def remove(ctx: Context, index: int = None): hacks = db.get_hacks() if index == None or index >= len(hacks): await send_hacks_list(ctx.channel) else: hack = hacks[index] if not (ctx.author.id in hack['people'] or await is_mod(ctx)): await ctx.send( f'Error: You do not have permission to remove "{format_hack(hack)}"' ) return hacks.pop(index) db.set_hacks(hacks) await ctx.send(f'Removed hack "{format_hack(hack)}"') await send_hacks_list(ctx.channel) await edit_sent(ctx)
async def add(ctx: Context, description: str = None): mentions = ctx.message.mentions if not description or len(mentions) == 0: embed = discord.Embed( title="Error: Can't add the hack", description=f'Project description and user(s) have to be specified!' ) await ctx.send(embed=embed) else: hack = { 'people': [user.id for user in mentions], 'description': description } hacks = db.get_hacks() hacks.append(hack) db.set_hacks(hacks) await ctx.send(f'Added hack "{format_hack(hack)}"') await send_hacks_list(ctx.channel) await edit_sent(ctx)
async def link(ctx: Context, index: int = None): hacks = db.get_hacks() if index == None or index >= len(hacks): await send_hacks_list(ctx.channel) else: previous = hacks[index] if not (ctx.author.id in previous['people'] or await is_mod(ctx)): await ctx.send( f'Error: You do not have permission to modify "{format_hack(previous)}"' ) return hack = {**previous} hack.pop('url', None) hacks[index] = hack db.set_hacks(hacks) await ctx.send(f'Updated hack "{format_hack(hack)}"') await send_hacks_list(ctx.channel) await edit_sent(ctx)