async def command_eventCreate(self, ctx, event_name: lower, event_description): """Create an event : Usage !eventCreate event_name event_description""" request = 'INSERT INTO events VALUES (\'{}\', \'{}\');'.format( preprocess_string(event_name), preprocess_string(event_description)) try: await self.bot.db.execute(request) await ctx.send('Event {} created'.format(event_name)) except asyncpg.exceptions.UniqueViolationError: await ctx.send('{} aleready exists'.format(event_name))
async def command_eventLeave(self, ctx, event_name: lower, member_name=None): """Leave an event : Usage !eventLeave event_name """ if not member_name: member_name = ctx.author.name request = 'DELETE FROM events_members WHERE name_event=\'{}\' AND name_member=\'{}\''.format( preprocess_string(event_name), preprocess_string(member_name)) response = await self.bot.db.execute(request) print(response) if response != 'DELETE 1': await ctx.send('{} is not in event {}'.format( member_name, event_name)) else: await ctx.send('{} leaved the event {}'.format( member_name, event_name))
async def command_ideaOpen(self, ctx, *args): """Propose an idea""" request = 'INSERT INTO ideas VALUES (DEFAULT, \'{}\');'.format( preprocess_string(' '.join(args))) response = await self.bot.db.execute(request) if response == 'INSERT 0 1': await ctx.send("Idea added") else: await ctx.send("Failure")
async def command_eventJoin(self, ctx, event_name: lower, member_name=None): """Join an event : Usage !eventJoin event_name """ if not member_name: member_name = ctx.author.name request = 'INSERT INTO events_members VALUES (\'{}\', \'{}\')'.format( preprocess_string(event_name), preprocess_string(member_name)) try: response = await self.bot.db.execute(request) await ctx.send('{} joined the event {}'.format( member_name, event_name)) except asyncpg.exceptions.ForeignKeyViolationError: await ctx.send('{} is not an event'.format(event_name)) except asyncpg.exceptions.UniqueViolationError: await ctx.send('{} is already in event {}'.format( member_name, event_name))
async def command_eventDelete(self, ctx, event_name: lower): """Delete an event : Usage !eventDelete event_name """ request = 'DELETE FROM events WHERE name=\'{}\';'.format( preprocess_string(event_name)) response = await self.bot.db.execute(request) if response != 'DELETE 1': await ctx.send('Event {} does not exists'.format(event_name)) else: await ctx.send('Event {} removed'.format(event_name))
async def command_event(self, ctx, event_name: lower): """Display infos about an event : Usage !event event_name """ request = 'SELECT * FROM events WHERE name=\'{}\';'.format( preprocess_string(event_name)) row = await self.bot.db.fetchrow(request) if not row: await ctx.send('The event {} does not exists :s'.format(event_name) ) else: await ctx.send(row['description'])
async def command_eventParticipants(self, ctx, event_name: lower): """List all the participants to an event : Usage !eventParticipants event_name """ request = 'SELECT * FROM events_members WHERE name_event=\'{}\';'.format( preprocess_string(event_name)) members = await self.bot.db.fetch(request) if not members: await ctx.send('The event {} does not exists :s'.format(event_name) ) return message = "Participants are : \n" for member in members: message += '\t{}'.format(member['name_member']) await ctx.send(message)