public async Task TransferLeadership(IGuildUser user) { if (user.Id == Context.User.Id) { throw new Exception("You are already the leader of this gang!"); } var gang = GangRepository.FetchGang(Context); if (!GangRepository.IsMemberOf(Context.User.Id, Context.Guild.Id, user.Id)) { throw new Exception("This user is not a member of your gang!"); } for (int i = 0; i < gang.Members.Length; i++) { if (gang.Members[i] == user.Id) { gang.Members[i] = Context.User.Id; GangRepository.Modify(DEABot.GangUpdateBuilder.Combine( DEABot.GangUpdateBuilder.Set(x => x.LeaderId, user.Id), DEABot.GangUpdateBuilder.Set(x => x.Members, gang.Members)), Context); break; } } await ReplyAsync($"{Context.User.Mention}, You have successfully transferred the leadership of {gang.Name} to {user.Mention}"); }
public async Task KickFromGang([Remainder] IGuildUser user) { if (!GangRepository.IsMemberOf(Context.User.Id, Context.Guild.Id, user.Id)) { throw new Exception("This user is not a member of your gang!"); } var gang = GangRepository.FetchGang(Context); GangRepository.RemoveMember(user.Id, Context.Guild.Id); await ReplyAsync($"{Context.User.Mention}, You have successfully kicked {user} from {gang.Name}"); var channel = await user.CreateDMChannelAsync(); await channel.SendMessageAsync($"You have been kicked from {gang.Name}."); }
public async Task KickFromGang(IGuildUser user) { using (var db = new SQLite.Models.DbContext()) { var gangRepo = new GangRepository(db); var guildRepo = new GuildRepository(db); if (!(await gangRepo.IsMemberOf(Context.User.Id, Context.Guild.Id, user.Id))) { throw new Exception("This user is not a member of your gang!"); } var gang = await gangRepo.FetchGangAsync(Context.User.Id, Context.Guild.Id); await gangRepo.RemoveMemberAsync(user.Id, Context.Guild.Id); await ReplyAsync($"{Context.User.Mention}, You have successfully kicked {user} from {gang.Name}"); var channel = await user.CreateDMChannelAsync(); await channel.SendMessageAsync($"You have been kicked from {gang.Name}."); } }
public async Task TransferLeadership(IGuildUser user) { if (user.Id == Context.User.Id) { throw new Exception("You are already the leader of this gang!"); } using (var db = new SQLite.Models.DbContext()) { var gangRepo = new GangRepository(db); var gang = await gangRepo.FetchGangAsync(Context.User.Id, Context.Guild.Id); if (!(await gangRepo.IsMemberOf(Context.User.Id, Context.Guild.Id, user.Id))) { throw new Exception("This user is not a member of your gang!"); } await gangRepo.RemoveMemberAsync(Context.User.Id, Context.Guild.Id); await gangRepo.ModifyAsync(x => { x.LeaderId = user.Id; return(Task.CompletedTask); }, user.Id, Context.Guild.Id); await gangRepo.AddMemberAsync(user.Id, Context.Guild.Id, Context.User.Id); await ReplyAsync($"{Context.User.Mention}, You have successfully transferred the leadership of {gang.Name} to {user.Mention}"); } }