public static async Task <User> FetchUserAsync(ulong userId, ulong guildId) { var guild = await GuildRepository.FetchGuildAsync(guildId); var existingUser = guild.Users.FirstOrDefault(x => x.UserId == userId); if (existingUser == null) { var createdUser = new User() { UserId = userId, GuildId = guild.Id }; guild.Users.Add(createdUser); await BaseRepository <Guild> .UpdateAsync(guild); return(createdUser); } return(existingUser); }
public static async Task <User> FetchUserAsync(SocketCommandContext context) { var guild = await GuildRepository.FetchGuildAsync(context.Guild.Id); var existingUser = guild.Users.FirstOrDefault(x => x.UserId == context.User.Id); if (existingUser == null) { var createdUser = new User() { UserId = context.User.Id, GuildId = guild.Id }; guild.Users.Add(createdUser); await BaseRepository <Guild> .UpdateAsync(guild); return(createdUser); } return(existingUser); }
public static async Task <Gang> CreateGangAsync(ulong leaderId, ulong guildId, string name) { var guild = await GuildRepository.FetchGuildAsync(guildId); if (guild.Gangs.Any(x => x.Name.ToLower() == name.ToLower() && x.GuildId == guildId)) { throw new Exception($"There is already a gang by the name {name}."); } if (name.Length > Config.GANG_NAME_CHAR_LIMIT) { throw new Exception($"The length of a gang name may not be longer than {Config.GANG_NAME_CHAR_LIMIT} characters."); } var createdGang = new Gang() { LeaderId = leaderId, Name = name, GuildId = guild.Id }; guild.Gangs.Add(createdGang); await BaseRepository <Guild> .UpdateAsync(guild); return(createdGang); }
public static async Task <List <Gang> > AllAsync(ulong guildId) { return((await GuildRepository.FetchGuildAsync(guildId)).Gangs); }