async def gameadd(self, ctx, key: str, *name: str): # check if game with key exist db_game = Game.getByKey(key) if not db_game: gameName = '{}'.format(' '.join(name)) db_game = Game() db_game.key = key db_game.name = gameName db_session.add(db_game) # commit update db_session.commit() gameRole = await ctx.guild.create_role( name=gameName, mentionable=True, ) # get role db_game.role = gameRole.id db_session.commit() # create output embed embed = discord.Embed(colour=discord.Colour.green(), title=f'Spiel angelegt') embed.add_field(name="Key", value=f'{key}', inline=False) embed.add_field(name="Name", value=f'{gameName}', inline=False) Session.close_all() # send embed await ctx.send(ctx.author.mention, embed=embed) else: # create output embed embed = discord.Embed(colour=discord.Colour.red(), title=f'Spiel gefunden') embed.add_field( name="Fehler", value= f'Es wurde das Spiel "{db_game.name}" mit dem Key "{db_game.key}" gefunden.', inline=False) # send embed await ctx.send(ctx.author.mention, embed=embed)
async def gameapplication(self, ctx, key: str, member: discord.Member): # check if game with key exist db_game = GameModel.getByKey(key) if db_game: foundGame = False for activity in member.activities: if activity.type == discord.ActivityType.playing: # set found game true foundGame = True db_application = Application.getByID( activity.application_id) if not db_application: db_application.id = activity.id db_application.name = activity.name db_session.add(db_application) db_session.commit() db_application_game = ApplicationGame.getByID( db_application.id, db_game.id ) if not db_application_game: db_application_game.applicationID = db_application.id db_application_game.gameID = db_game.id db_session.add(db_application_game) db_session.commit() # create output embed embed = discord.Embed( colour=discord.Colour.green(), title="Application hinzugefügt", ) else: # create output embed embed = discord.Embed( colour=discord.Colour.red(), title="Application wurde schon hinzugefügt", ) embed.add_field( name='Name', value=f'{activity.name}', inline=False ) embed.add_field( name='ApplicationID', value=f'{activity.application_id}', inline=False ) embed.add_field( name='Spiel', value=f'{db_game.name}', inline=False ) embed.add_field( name='SpielID', value=f'{db_game.id}', inline=False ) Session.close_all() # send message await ctx.send(ctx.author.mention, embed=embed) break if not foundGame: # create output embed embed = discord.Embed( colour=discord.Colour.red(), title=f'Kein Spiel gefunden' ) embed.add_field( name="Fehler", value=f'Es konnte kein Spiel bei {member.mention} entdeckt werden.', inline=False) # send embed await ctx.send(ctx.author.mention, embed=embed) else: # create output embed embed = discord.Embed( colour=discord.Colour.red(), title=f'Spiel nicht gefunden' ) embed.add_field( name="Fehler", value=f'Es wurde kein Spiel mit dem Key "{key}" gefunden.', inline=False) # send embed await ctx.send(ctx.author.mention, embed=embed)