public async Task RemoveRolePoints(uint pointsAmount) { ServerList server = ServerListsManager.GetServer(Context.Guild); ServerRolePoints pointRole = server.GetServerRolePoints(pointsAmount); if (pointRole.PointsRequired == 0) //Make sure a point role with that amount of points needed actually exists. { await Context.Channel.SendMessageAsync($"There are no point roles with the points amount of `{pointsAmount}`."); return; } server.ServerRolePoints.Remove(pointRole); ServerListsManager.SaveServerList(); await Context.Channel.SendMessageAsync($"The point role with `{pointsAmount}` points was removed."); }
public async Task AddRolePoints(uint pointsAmount, [Remainder] string roleName) { //First, lets make sure that the role actually exists SocketRole role = RoleUtils.GetGuildRole(Context.Guild, roleName); if (role == null) { await Context.Channel.SendMessageAsync("That role doesn't exists!"); return; } ServerList server = ServerListsManager.GetServer(Context.Guild); //Make sure a point role with that many points doesn't exist if (server.GetServerRolePoints(pointsAmount).PointsRequired != 0) { await Context.Channel.SendMessageAsync( $"A role is already given when a user gets `{pointsAmount}` points."); return; } //Can't have a point role lower then the amount of points given each time if (pointsAmount >= server.PointGiveAmount) { await Context.Channel.SendMessageAsync( $"You have to set required points higher then `{server.PointGiveAmount}`!"); return; } ServerRolePoints serverRolePoints = new ServerRolePoints { RoleId = role.Id, PointsRequired = pointsAmount }; //Add our point role to our list server.ServerRolePoints.Add(serverRolePoints); ServerListsManager.SaveServerList(); await Context.Channel.SendMessageAsync( $"Ok, when a user gets {pointsAmount} points they shell receive the **{role.Name}** role.\nPlease note any user who already have {pointsAmount} points won't get the role."); }
/// <summary> /// Gives a user server points, and gives them a role if they past a certain amount of points /// </summary> /// <param name="user"></param> /// <param name="channel"></param> /// <param name="amount"></param> public static async void GiveUserServerPoints(SocketGuildUser user, SocketTextChannel channel, uint amount) { UserAccountServerData userAccount = UserAccountsManager.GetAccount(user).GetOrCreateServer(user.Guild.Id); userAccount.Points += amount; UserAccountsManager.SaveAccounts(); //Give the user a role if they have enough points for it. ServerList server = ServerListsManager.GetServer(user.Guild); ServerRolePoints serverRole = server.GetServerRolePoints(userAccount.Points); Logger.Debug("{@Username} now has {@Points} points on guild {@GuildId}", user.Username, userAccount.Points, user.Guild.Id); if (serverRole.PointsRequired == 0) { return; } await user.AddRoleAsync(RoleUtils.GetGuildRole(user.Guild, serverRole.RoleId)); await channel.SendMessageAsync( $"Congrats {user.Mention}, you got {userAccount.Points} points and got the **{RoleUtils.GetGuildRole(user.Guild, serverRole.RoleId).Name}** role!"); }